Very easy question. I have been using CSS for a while but rarely use + sigh for my code. Could any one explain what the best time is to use it? I couldn't find anything from Google...Thanks a millions...
Short answer no, in css you can't create content or display it multiple times. Usually this repeated content is taken care of via server side technologies (PHP, JSP, ASPX) etc. If your site is static content (no server side processing) then your best bet is just copy and past.
You cannot have multiple IDs for a single div tag. There is never any need for multiple ids on the same tag since ids are unique either one would serve to uniquely identify that specific tag provided you first get rid of the other id which is stopping things working.
An id must be unique in a page. Use a class if you want to describe a group of elements. why we should not use id selector two times in a page while its working fine.
I've found that adjacent sibling selectors are useful when you want to apply special styling to the first element of a series of elements. For example, if you want to style the first paragraph of an article differently from the rest, you could use:
p {
/* styles for the first paragraph */
}
p + p {
/* styles for all other paragraphs */
}
This can replace using class="first"
in many situations.
EDIT: Using the first-child
pseudo-class would work better for this specific case, since it's supported by a wider range of browsers. (Thanks alex)
You might also want to adjust how certain elements are positioned when next to each other. If you have an unordered list that looks fine on its own, but needs less padding at the top when it's next to a paragraph, you could use:
ul {
padding-top: 1em;
/* Default ul styling */
}
p + ul {
padding-top: 0;
/* special styling for lists that come after paragraphs */
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With