trhthong
31-03-2008, 08:27
Đọc thử về Selector của CSS2, nhưng không hiểu rõ lắm. Các Pro chỉ giúp hen:
Đầu tiên là cái Child-of Selector, được nói là:
Child-of selector
E > F: selects any element F that is a child of E
For instance, these slides are in XHTML, and each slide is just a <div>.
I used to have for each slide
<div class="slide">
but now I can save typing, and have an unadorned <div>. Where I used to have the CSS rule:
div.slide {...}
I now have:
body>div {...}
which only selects divs which are a (direct) child of <body>
đoạn này, tớ không hiểu lắm ở câu: but now I can save typing, and have an unadorned <div>. Where I used to have the CSS rule:...
Đoạn thứ hai:
Alternative for child-of
Note that the rule
body div
also selects divs that are a child of <body>, but at any level, not just direct children. So if my slides themselves contain <div>s (which they do) then those divs would be selected too.
Another option I could have used was:
body div {... rules intended for slides... }
body div div {... rules to undo the above rules ... }
but it is nicer not to have to 'undo' presentation caused by other rules if you can avoid it.
Đọc xong đoạn này, tớ hiểu đại khái là: Child-of Selector chỉ chọn những phần tử con trực tiếp của phần tử cha (which only selects divs which are a (direct) child of <body>). Còn cách dùng bộ chọn kiểu body div{...} thì chọn tất tần tật những phần tử con của phần tử body.
Nhưng xuống đoạn dưới này:
First-child selector
E:first-child: selects any E that is the first child of its parent
So for instance, the following only selects paragraphs that are the first child of their parent:
p:first-child
Note that this slide does not have such a paragraph. The first child is a heading, so the above rule wouldn't apply to any paragraph here.
Usually though you want to be more specific. For instance, to select the first slide of this set:
body > :first-child
which selects any element that is a direct child of <body> that is also a first-child of its parent. Since there is only one of those, the first child of the body, it selects that.
vẫn là which selects any element that is a direct child of <body>
Vậy không lẽ cái Child-of Selector và cái First Child Selector giống nhau à?
Vui lòng giải thích dùm mình ý nghĩa của những bộ chọn trên nghen! Thanks very much!
Đầu tiên là cái Child-of Selector, được nói là:
Child-of selector
E > F: selects any element F that is a child of E
For instance, these slides are in XHTML, and each slide is just a <div>.
I used to have for each slide
<div class="slide">
but now I can save typing, and have an unadorned <div>. Where I used to have the CSS rule:
div.slide {...}
I now have:
body>div {...}
which only selects divs which are a (direct) child of <body>
đoạn này, tớ không hiểu lắm ở câu: but now I can save typing, and have an unadorned <div>. Where I used to have the CSS rule:...
Đoạn thứ hai:
Alternative for child-of
Note that the rule
body div
also selects divs that are a child of <body>, but at any level, not just direct children. So if my slides themselves contain <div>s (which they do) then those divs would be selected too.
Another option I could have used was:
body div {... rules intended for slides... }
body div div {... rules to undo the above rules ... }
but it is nicer not to have to 'undo' presentation caused by other rules if you can avoid it.
Đọc xong đoạn này, tớ hiểu đại khái là: Child-of Selector chỉ chọn những phần tử con trực tiếp của phần tử cha (which only selects divs which are a (direct) child of <body>). Còn cách dùng bộ chọn kiểu body div{...} thì chọn tất tần tật những phần tử con của phần tử body.
Nhưng xuống đoạn dưới này:
First-child selector
E:first-child: selects any E that is the first child of its parent
So for instance, the following only selects paragraphs that are the first child of their parent:
p:first-child
Note that this slide does not have such a paragraph. The first child is a heading, so the above rule wouldn't apply to any paragraph here.
Usually though you want to be more specific. For instance, to select the first slide of this set:
body > :first-child
which selects any element that is a direct child of <body> that is also a first-child of its parent. Since there is only one of those, the first child of the body, it selects that.
vẫn là which selects any element that is a direct child of <body>
Vậy không lẽ cái Child-of Selector và cái First Child Selector giống nhau à?
Vui lòng giải thích dùm mình ý nghĩa của những bộ chọn trên nghen! Thanks very much!