Select second 2nd child div from within the parents div
You need to remove inline style from the second div tag
<div style="border-top: 1px solid #e5e5e5; width: 100%; line-height: 22px;">
It is overriding your css style.
For whatever reason if you want to keep the style, use !important although I highly DO NOT recommend this approach because it is very very bad practice but that's an option (however bad).
.manufacturer_box div:nth-child(2) {
border-top: 5px solid #e0e0e0 !important;
}
Select only the second child of an element with CSS
You can easily do with with nth-child:
#someID .text:nth-child(2) {
background:red;
}
Demo: http://jsfiddle.net/P6FKf/
CSS nth-child: what exactly does nth-child(1n) select
Xn
essentially means every Xth child, where Xn+Y
is every Xth child with an offset of Y.
1n
is quite nonsensical, as it will just select every child (every 1th child, which essentially is just every child).
div:nth-child(1n)
{
color: red;
}
<div>Hi</div>
<div>Hi</div>
<div>Hi</div>
<div>Hi</div>
<div>Hi</div>
Select the second child after some element
Looking at the two you say don't work, consider this structure:
h1+p+p::first-letter {
color: red;
}
h1+p:nth-child(2)::first-letter {
color: blue;
}
<body>
<h1>H1</h1>
<p>P1</p>
<p>P2</p>
</body>
Get second child using jQuery
grab the second child:
$(t).children().eq(1);
or, grab the second child <td>
:
$(t).children('td').eq(1);
See documentation for children
and eq
.
SCSS - nth-child(2) affects all descendants
If you look at how your SCSS actually gets compiled, you'll see it gets compiled to:
.my-class :nth-child(2) {
padding-right: 15px;
padding-left: 0;
}
Because CSS cascades (hence cascading style sheet), your :nth-child(2)
will affect every second child.
I changed the padding to the left side, so it can be seen.
.my-class :nth-child(2) {
padding-right: 0;
padding-left: 15px;
}
<div class="my-class">
<div>
first
<div>
first child
</div>
<div>
second child
<div>
first - second child
</div>
<div>
second - second child
</div>
</div>
</div>
<div>
second
</div>
</div>
Related Topics
Use CSS Variables with Rgba for Gradient Transparency
Css: Disable Font Ligatures in All Browsers
How to Draw a Diagonal Line Using CSS3
CSS Animation on "Content:" Doesn't Work on Safari and Firefox
Bootstrap - Do We Have to Use Rows and Columns
How to Remove the Blue Highlight of Button on Mobile
How to Use Bootstrap Modals Without Loading the Entire Library
Less/Sass Debugging in Chrome Dev Tools/Firebug
Tools to Optimize (Remove Redundancy and Merge) CSS
How to Adjust the Caret (Blinking Cursor) Size Inside Searchbar with CSS
Using a Percentage Margin in CSS But Want a Minimum Margin in Pixels
How to Center Content in a Div Using CSS
Pugjs(Jade) Template Engine Loading CSS File
Less CSS - Change Variable Value for Theme Colors Depending on Body Class