I am trying to use nth-child to target 1,6, 7,10, 13 ect. and some style. I was targeting them individually but this wont work as the content will be automatically generated.
I have 1 large div followed by 2 small divs one above the other then the next row is the opposite 2 small and one large and this is to continue as content is added.
What would be my best option for achieving this ?
Below is the css i am using at the min:
div:nth-child(1),div:nth-child(6),div:nth-child(7),
div:nth-child(10),div:nth-child(13){
background:#000;
}
I have 1 large div followed by 2 small divs one above the other then the next row is the opposite 2 small and one large and this is to continue as content is added.
So the same situation repeats every 6 items. Using :nth-child(an+b), you now know that a=6.
2 elements are selected for each group of 6: 1 and 6 (and then 7 and 12 (not 10), 13 and 18, etc). To select the first one, b=1 is OK. To select the 6th one, b=0 or b=6 are OK
That leads to:
li:nth-child(6n+1),
li:nth-child(6n) {
/* sth different */
}
Codepen: http://codepen.io/anon/pen/cypAn
You should use nth-child if you just want to use CSS. See this article here. There is a nice table at the bottom that can help if you are a visual learner.
Related
I'm currently having a problem trying to set to the left every sublist of the navigation bar so that it aligns correctly bellow every sublist if there is more than 6 columns, the problem happens from the 7th list. I'm using bootstrap and every sublist have a size of 2 (so from the 7th as it passes the 12 column size it moves down, as expected)
What I'm getting a result is
And the expected result is
Piece of code used per list:
<div class="sub-navigation-section col-md-2">Ul and li inside</div>
The CSS that is attempting to do the expected result is a Float:left;
Bootstrap uses a 12 column grid system so you won't be able to divide that up equally into 7 columns. You could do this by creating your own class that has a width of approx 14.285% (100/7) and the same properties as the bootstrap col-* classes (float left etc)... but remember you'll need to cater for different viewports etc
If you wont use javascript, you can alternatively use CSS3´s column-gap and column-width like in this example:
https://www.bootply.com/118335
It floats the boxes like waterfall layout. Hope this helps you.
I've been working with Susy for a while now and came across a use case that I can't seem to figure out. The best way to explain it is to use Twitter as an example.
If you look on their site you'll see they use a three column standard layout with a break point at 1250. After that point is reached, the entire right most column 3 goes underneath column 1.
How is this done with pure CSS in Susy 2? When I look at twitter it seems like they are physically moving the content from column 3 into column 1. I'm assuming this is all done with JS but id rather do it a bit more clean. Ideas?
Looks like it was as simple as using breakpoint as another mixin for my columns. I simply added
#import "breakpoint";
#include breakpoint (new screen size here) {
.right span (5 of 13);
.left span (8 of 13 last);
.middle span (5 of 13);
}
I have an Rails app I am building with Foundation. I am having trouble figuring out how to display an arbitrary number of columns per row and keep it responsive in the small/medium/large layouts.
For example, lets say I have a model Department which has many Employees. I am trying to build the department page and display a list of the employees in the department. One department may have 10 employees. Another may have 6. It's arbitrary.
I want to do 4 columns in large, 2 columns in medium and 1 column in small. (See my wireframe below). However, the columns need to be wrapped in a div.row. This requirement means I have either of the following two situations:
Case #1 (jsfiddle) I have 2 elements per row and the large layout only gets 2 elements because it is getting cleared by the .row.
Case #2 (jsfiddle) I have 4 elements per row and the columns don't clear properly when in the 2-column, medium layout because there are 4 in a row.
This seems like it should be a pretty standard situation but I cant seem to figure it out. How do I do this? Is Foundation the wrong tool?
Media Queries and CSS might do the trick:
// medium
#media only screen and (min-width: 40.063em) and (max-width: 64em) {
.row > div:nth-child(2) {clear: left;}
}
With 4 elements per row
http://quirksmode.org/css/selectors/nthchild.html
http://foundation.zurb.com/docs/media-queries.html
Inspired by this tutorial, I've set up a Fiddle that has 5 columns. That works fine with 5 images. With 6, however, it sorts it into 2 rows of 3 instead of one row of 5 and a row of 1. Other configurations have a similar effect.
Is there a reason for this and a way to prevent that from happening?
You should use as an additional style, like this:
float:left;
In ColorBox, is it possible to control the order that photos appear within a grouped (rel="group") gallery?
Unfortunately, due to the layout of my page, photos appear in vertical columns, which need to be grouped horizontally. So the links are output in vertical order in the html, ie:
1 4 7
2 5 8
3 6 9
...but need to be displayed as...
1 2 3
4 5 6
7 8 9
What I need to be able to do, is to override the natural order, sort of like a tabindex, ie:
rel="group[1]"
rel="group[4]"
rel="group[7]"
rel="group[2]"
rel="group[5]"
rel="group[8]"
rel="group[3]"
rel="group[6]"
rel="group[9]"
Is this possible?
Sorry, I can't think of any easy way to do this. Colorbox's ordering is controlled by DOM placement and there isn't a way to alter that outside of editing the plugin. The easiest thing to do would be somewhat ugly: create a duplicate set of DOM elements in the correct order and assign colorbox to them instead (this could be done with JS and they could have their display set to none so they are hidden from the visitor). Then use the original links to trigger colorbox on the duplicate link that shares the same href value.