.
In CSS, there are the basic stylings for all the essential elements of a page. Body, heading tags, paragraph tags, and so forth. As it gets more advanced, you can create specific blocks for different elements on the website using CSS to style elements within each block accordingly. In going even further, you can use a number of advanced selectors to style your website with the most control you could ever need. In this post, we will look at a few of these advanced selectors.
viagra for women
The first-letter selector is something rarely seen, but it has many applicable uses. For example, what if you wanted to give the first letter of a heading tag more prominence, or wanted to give the first letter of a paragraph tag an underline? Now you can! For example:
h1 {font-size:25px;}
h1:first-letter {font-size:40px;}
Now the first letter of the Heading 1 tag will have a font size of 40 pixels, while the rest of the heading will have a font size of 25 pixels.
viagra for women
The first-line selector works in the same way as the first-letter selector. This will style the first line in a block of text with whatever property you give it. For example:
p:first-line {background:#CCCCCC;}
The first line in a paragraph will now have a background colour of #CCCCCC.
viagra for women
The first child and last child selectors are used to specify the first and last elements. This is particularly useful if you have many columns or rows in a container. For example:
.column {
width:100px;
float:left;
margin-right:20px;
}.column:last-child {
float:right;
margin-right:0;
}
If your container is 340 pixels wide, your columns will appear to have equal spacing.
viagra for women
The selection selector provides a style for highlighting elements on the website. In this example, we will apply a background colour to the body for when the content is highlighted.
body::selection {background:#CCCCCC;}
Now when the user highlights the content, there will be a background colour of #CCCCCC.
viagra for women
The nth-child selector can be a tricky one to use as it sometimes requires math. There are 3 primary ways to use nth-child.
viagra for women
In this example, we will turn a list into a zebra list:
li:nth-child(odd) {background:#FFFFFF;}
li:nth-child(even) {background:#000000;}
viagra for women
In this example, we will specify a specific column. Assume there are 5 columns declared.
.col {background:#000000;}
.col:nth-child(4) {background:#FFFFFF;}
This will give the 4th column a white background. This solution is generally useful only when there are around 1-5 elements. The next method is handy for 5+ elements.
viagra for women
This method requires a bit of math. You can use it to specify a starting point and the iterations after that point. In this example, we will specify starting at the third point and reiterate every 3 times after that:
p:nth-child(3n+3) {background:#CCCCCC;}
This will give the third item and every third item after that a background colour of #CCCCC. To explain, 3n specifies the start point and the +3 specifies the reiterated point.
If you wanted to start from the 5th point and reiterate every second 2nd time after that, you could use p:nth-child(2n+5). This would start at the 2nd point and reiterate on every 5th element.
To specify the first 5 elements and none after that, the following method could be used: p:nth-child(-n+5). This would provide 0 as the starting point and iterate only 5 times.
To specify all points after a specified point, the following method could be used: p:nth-child(+n5)
If this sounds confusing, there is a handy tool for previewing nth-child provided by CSS Tricks:Â
viagra for women
There’s many more interesting CSS selectors out there, but some caution may need to be applied when using them in the wild, as there is some cross-browser concerns. To see which selectors work on older (IE) browsers, view this handy list:Â