Hướng dẫn last-child css not working
I have a grid of news articles and I wanting it so the last two articles in the grid do not have a bottom border, however my css Here is a fiddle of my code and problem. http://jsfiddle.net/Udders/HJE5h/ asked Dec 21, 2011 at 11:22
5 As mentioned by @BoltClock above, swap the JSFiddle: http://jsfiddle.net/HJE5h/2/ EditOk, as @BoltClock mentions in the comment below, the problem is not entirely with the
JSFiddle: http://jsfiddle.net/HJE5h/5/ answered Dec 21, 2011 at 11:37
My Head HurtsMy Head Hurts 37.1k16 gold badges73 silver badges114 bronze badges 1 You can achieve that by using nth-last-child(n) pseudo class. It begins at the end of the collection and this way you can specify the last two elements without knowing the size of the collection. Please try this selector in your css code:
This is a good reference for useful css selectors http://net.tutsplus.com/tutorials/html-css-techniques/the-30-css-selectors-you-must-memorize/ answered Dec 21, 2011 at 11:53
You can’t…with CSS Pseudo-selectors like Either something is the Remember that CSS reads ‘right to left’ So, in your case, it’s testing for it to meet all the conditions. It looks to see if something is the last child then if it has the attribute and class. If it doesn’t have all three…in that order…it fails.
My guess it that this is just by chance….the element just happens to be the first element in the parent. You can test this for yourself by adding an extra element in front, temporarily, to your code. JQuery can do this selector for you though.
Định nghĩa và sử dụng
Cấu trúc:last-child { property: value; } Ví dụHTML viết:
Hiển thị trình duyệt khi chưa có CSS:Thành phần thứ nhất Thành phần thứ 2 Thành phần thứ 3 Thành phần thứ 4 Thành phần thứ 5 Thành phần thứ 6 Thành phần thứ nhấtThành phần thứ 2 Thành phần thứ 3 Thành phần thứ 4 Thành phần thứ 5 Thành phần thứ 6 Thành phần thứ nhất
Thành phần thứ 3 Thành phần thứ 4 Thành phần thứ 5 Thành phần thứ 6 Thành phần độc lập thứ nhất Thành phần độc lập thứ 2 Thành phần độc lập thứ 3 Thành phần độc lập thứ 4 Thành phần độc lập thứ 5 Thành phần độc lập thứ 6 CSS viết:p:last-child{ color: blue; } Hiển thị trình duyệt khi đã có css:Thành phần thứ nhất Thành phần thứ 2 Thành phần thứ 3 Thành phần thứ 4 Thành phần thứ 5 Thành phần thứ 6 Thành phần thứ nhấtThành phần thứ 2 Thành phần thứ 3 Thành phần thứ 4 Thành phần thứ 5 Thành phần thứ 6 Thành phần thứ nhất
Thành phần thứ 3 Thành phần thứ 4 Thành phần thứ 5 Thành phần thứ 6 Thành phần độc lập thứ nhất Thành phần độc lập thứ 2 Thành phần độc lập thứ 3 Thành phần độc lập thứ 4 Thành phần độc lập thứ 5 Thành phần độc lập thứ 6 Ta thấy những thành phần ở vị trí cuối cùng có thành phần cha đều đã được chọn. Trình duyệt hỗ trợ":last-child" được hỗ trợ trong đa số các trình duyệt, ngoài trừ trình duyệt Internet Explorer 8 trở xuống. |