In this post is about CSS selector and how it woks. Following is explanation of most of the selector that is used in CSS.
In the following first is css example and than html code on which it will work, so to try by yourself create html page and put the css as well as related Html and see the result. In most of the select I provided demo link where you can visit and see the result.
In below post you might find some new CSS selector that are the part of new CSS3. All of the below examples and demo tried by me on latest Chrome version.
.Class -: Select all the element with given class name.
CSS
#id -: Select all the element with given id name.
CSS
HTMLElement - Select all the html element which name is given.
CSS
HtmlElement HtmlElemnt - Select all the html element which are in html element.
CSS
HtmlElement > HtmlElemnt - Select all the html element which are child of html element.
CSS
HtmlElement + HtmlElemnt - Select all the html element which are immediate after html element.
CSS
HtmlElement ~ HtmlElemnt - Select all the html element which are precedes html element.
CSS
[attribute] - Select all the html element which is having attribute.
CSS
[attribute = data] - Select all the html element which is having attribute value equal to data.
CSS
[attribute ^= data] - Select all the html element where attribute value begins with data.
CSS
[attribute $= data] - Select all the html element where attribute value end with data.
CSS
[attribute *= data] - Select all the html element where attribute value contains data.
CSS
[attribute ~= data] - Select all the html element where attribute value contains word data.
CSS
:first-child - Select first element (first child) of parent.
CSS
:last-child - Select last element (last child) of parent.
CSS
:nth-child(n) - Select all each element which n the child of parent.
CSS
:nth-child(n) - Select all each element which last n the child of parent counting from bottom .
CSS
:only-child - Select child element which only child of parent .
CSS
:first-of-type - Select first element of given type which is first comes under parent element.
CSS
:last-of-type - Select last element of given type which is last comes under parent element.
CSS
:nth-of-type(n) - Select nth element of given type which comes at nth place under parent element.
CSS
:nth-last-of-type(n) - Select nth last element of given type which comes at nth place under parent element from last.
CSS
:only-of-type - Select only element of given type which comes under parent element.
CSS
:empty - Select element which is empty i.e. donent have any child.
CSS
::selection - highlight the text with the color selected.
CSS
:not(HTMLElement) - it not apply the style to the HTMLElement specified.
CSS
:enable - select to all enable element.
:disable - select to all disable element.
CSS
Conclusion
Most of the selector are new here those are part of CSS3, I hope that helpful to understand well. I covered most of the CSS selector here but if there is something missing please place comment below regarding it.
Leave comment if you have any query or if you like it. Pelease report if any link is not working or broken.
In the following first is css example and than html code on which it will work, so to try by yourself create html page and put the css as well as related Html and see the result. In most of the select I provided demo link where you can visit and see the result.
In below post you might find some new CSS selector that are the part of new CSS3. All of the below examples and demo tried by me on latest Chrome version.
.Class -: Select all the element with given class name.
CSS
.MyIntro
{
font:15px arial,sans-serif;
color:red;
}
Use
<div class="MyIntro"> <p>My name is Pranay Rana.</p> <p>I am working as Soft Engg.</p> </div>
#id -: Select all the element with given id name.
CSS
#MyIntro
{
font:15px arial,sans-serif;
color:red;
}
Use<div id="MyIntro"> <p>My name is Pranay Rana.</p> <p>I am working as Soft Engg.</p> </div>Point to Note : You can have more than one element having same classname in HTML page but you can have only one element with the ID.
HTMLElement - Select all the html element which name is given.
CSS
p
{
font:15px arial,sans-serif;
color:red;
}
Use<div> <p>My name is Pranay Rana.</p> <p>I am working as Soft Engg.</p> </div>
HtmlElement HtmlElemnt - Select all the html element which are in html element.
CSS
div p
{
font:15px arial,sans-serif;
color:red;
}
Use<div > <p>My name is Pranay Rana.</p> <Span> <p> data </p> </Span> </div> <p>I am working as Soft Engg.</p>in this example all p element inside div get highlighted with read color, but p element outside div doesnt get affected.
Demo
HtmlElement > HtmlElemnt - Select all the html element which are child of html element.
CSS
div > p
{
font:15px arial,sans-serif;
color:red;
}
Use<div > <p>My name is Pranay Rana.</p> <Span> <p> data </p> </Span> </div> <p>I am working as Soft Engg.</p>in this example all p element which are child of div get highlighted with read color, but p element which are not child of div doesnt get affected.
Demo
HtmlElement + HtmlElemnt - Select all the html element which are immediate after html element.
CSS
div + p
{
font:15px arial,sans-serif;
color:red;
}
Use<div > <p>My name is Pranay Rana.</p> </div> <p>I am working as Soft Engg.</p> <p> data </p>in this example p element which is immediate after div get highlighted with read color, in this example "I am working as Soft Engg." this text get highlighted.
Demo
HtmlElement ~ HtmlElemnt - Select all the html element which are precedes html element.
CSS
div ~ p
{
font:15px arial,sans-serif;
color:red;
}
Use<div >
<p>My name is Pranay Rana.</p>
<span>
<p> data </p>
</span>
</div>
<p>I am working as Soft Engg.</p>
<p>My Demo Page.</p>
in this example p element which is precedes div get highlighted with read color, in this example "I am working as Soft Engg." and "My Demo Page." text get highlighted.Demo
[attribute] - Select all the html element which is having attribute.
CSS
[data-name]
{
font:15px arial,sans-serif;
color:red;
}
Use<div >
<p data-name="pranay">My name is Pranay Rana.</p>
<span>
<p> data </p>
</span>
</div>
<p>I am working as Soft Engg.</p>
<p data-name="demo">My Demo Page.</p>
in this example any element which is having attribute "data-name"div get highlighted with red color, in this example "My name is Pranay Rana." and "My Demo Page." text get highlighted.Demo
[attribute = data] - Select all the html element which is having attribute value equal to data.
CSS
[data-name = 'demo']
{
font:15px arial,sans-serif;
color:red;
}
Use<div >
<p data-name="pranay">My name is Pranay Rana.</p>
<span>
<p> data </p>
</span>
</div>
<p>I am working as Soft Engg.</p>
<p data-name="demo">My Demo Page.</p>
in this example any element which is having attribute "data-name" and value = "demo" get highlighted with red color, in this example "My Demo Page." text get highlighted.Demo
[attribute ^= data] - Select all the html element where attribute value begins with data.
CSS
[data-name ^= 'pra']
{
font:15px arial,sans-serif;
color:red;
}
So with the above html when apply this "My name is Pranay Rana." text is get highlighted because its "data-name" attribute value begining with "pra".
Demo
[attribute $= data] - Select all the html element where attribute value end with data.
CSS
[data-name ^= 'pra']
{
font:15px arial,sans-serif;
color:red;
}
So with the above html when apply this "My name is Pranay Rana." text is get highlighted because its "data-name" attribute value ending with "nay".
Demo
[attribute *= data] - Select all the html element where attribute value contains data.
CSS
[data-name *= 'rana']
{
font:15px arial,sans-serif;
color:red;
}
So with the above html when apply this "My name is Pranay Rana." text is get highlighted because its "data-name" attribute value contains "rana".
Demo
[attribute ~= data] - Select all the html element where attribute value contains word data.
CSS
[data-name ~= 'page']
{
font:15px arial,sans-serif;
color:red;
}
Use<div >
<p data-name="pranay_page">My name is Pranay Rana.</p>
<span>
<p> data </p>
</span>
</div>
<p>I am working as Soft Engg.</p>
<p data-name="demo page">My Demo Page.</p>
in this example any element where attribute "data-name" value contains word = "page" get highlighted with red color, in this example "My Demo Page." text get highlightedDemo
:first-child - Select first element (first child) of parent.
CSS
li:forst-child
{
font:15px arial,sans-serif;
color:red;
}
Use<ul>
<li>item1</li>
<li>item2</li>
<li>item3</li>
<li>item4</li>
</ul>
in this example "item1" element get highlighted with red color.Demo
:last-child - Select last element (last child) of parent.
CSS
li:last-child
{
font:15px arial,sans-serif;
color:red;
}
Use<ul>
<li>item1</li>
<li>item2</li>
<li>item3</li>
<li>item4</li>
</ul>
in this example "item4" element get highlighted with red color.Demo
:nth-child(n) - Select all each element which n the child of parent.
CSS
li:nth-child(2)
{
font:15px arial,sans-serif;
color:red;
}
Use<ul>
<li>item1</li>
<li>item2</li>
<li>item3</li>
<li>item4</li>
</ul>
in this example "second li" element get highlighted with red color, in this example "item2" text get highlightedDemo
:nth-child(n) - Select all each element which last n the child of parent counting from bottom .
CSS
li:nth-child(2)
{
font:15px arial,sans-serif;
color:red;
}
Use<ul>
<li>item1</li>
<li>item2</li>
<li>item3</li>
<li>item4</li>
</ul>
in this example "second last li" element get highlighted with red color, in this example "item3" text get highlightedDemo
:only-child - Select child element which only child of parent .
CSS
p:only-child
{
font:15px arial,sans-serif;
color:red;
}
Use<div>
<p> pragraph 1</p>
</div>
<div>
<p> pragraph 2</p>
<p> pragraph 3</p>
<p> pragraph 4</p>
</div>
in this example "paraghaph 1" element get highlighted with red color,which is only child of div element.Demo
:first-of-type - Select first element of given type which is first comes under parent element.
CSS
p:first-of-type
{
font:15px arial,sans-serif;
color:red;
}
Use<div>
<p> pragraph 1</p>
<p> pragraph 2</p>
<p> pragraph 3</p>
</div>
in this example "paragraph 1" element get highlighted with red color.Demo
:last-of-type - Select last element of given type which is last comes under parent element.
CSS
p:last-of-type
{
font:15px arial,sans-serif;
color:red;
}
Use<div>
<p> pragraph 1</p>
<p> pragraph 2</p>
<p> pragraph 3</p>
</div>
in this example "paragraph 1" element get highlighted with red color, that means here "pragraph 1" is first element of type p under div.Demo
:nth-of-type(n) - Select nth element of given type which comes at nth place under parent element.
CSS
p:nth-of-type(2)
{
font:15px arial,sans-serif;
color:red;
}
Use<div>
<p> pragraph 1</p>
<p> pragraph 2</p>
<p> pragraph 3</p>
<p> pragraph 4</p>
</div>
in this example "paragraph 2" element get highlighted with red color, that means here "pragraph 2" is 2th element of type p under div.Demo
:nth-last-of-type(n) - Select nth last element of given type which comes at nth place under parent element from last.
CSS
p:nth-last-of-type(2)
{
font:15px arial,sans-serif;
color:red;
}
Use<div>
<p> pragraph 1</p>
<p> pragraph 2</p>
<p> pragraph 3</p>
<p> pragraph 4</p>
</div>
in this example "paragraph 3" element get highlighted with red color, that means here "pragraph 3" is last element of type p under div from last.Demo
:only-of-type - Select only element of given type which comes under parent element.
CSS
p:only-of-type
{
font:15px arial,sans-serif;
color:red;
}
Use<div>
<p> pragraph 1</p>
</div>
<div>
<p> pragraph 2</p>
<p> pragraph 3</p>
<p> pragraph 4</p>
</div>
in this example "paragraph 1" element get highlighted with red color, because p is only element of given type.Demo
:empty - Select element which is empty i.e. donent have any child.
CSS
div:empty
{
width:100px;
height:20px;
background:red;
}
Use<div></div>
<div>
<p> pragraph 2</p>
<p> pragraph 3</p>
<p> pragraph 4</p>
</div>
in this highlight all text in the document with red color.Demo
::selection - highlight the text with the color selected.
CSS
::selection
{
background:green;
}
Use<div> <p> pragraph 1</p> </div>
<div>
<p> pragraph 2</p>
<p> pragraph 3</p>
<p> pragraph 4</p>
</div>
in this highlight all text with green which get select in document.Demo
:not(HTMLElement) - it not apply the style to the HTMLElement specified.
CSS
:not(span)
{
font:15px arial,sans-serif;
color:red;
}
span
{
color:black;
}
Use<p> pragraph 1</p> <p> pragraph 2</p> <p> pragraph 3</p> <p> pragraph 4</p> <span> span data</span>in this highlight all text which is in p element i.e. not apply style to span element.
Demo
:enable - select to all enable element.
:disable - select to all disable element.
CSS
:input[type="text"]:enabled
{
background:green;
}
input[type="text"]:disabled
{
background:red;
}
UseName: <input type="text" value="Pranay Rana" /><br> Country: <input type="text" disabled="disabled" value="India" />here name is get highlighted with red color and country box is get highlighted with green.
Demo
Conclusion
Most of the selector are new here those are part of CSS3, I hope that helpful to understand well. I covered most of the CSS selector here but if there is something missing please place comment below regarding it.
Leave comment if you have any query or if you like it. Pelease report if any link is not working or broken.
It surrоunds the urethrа anԁ rеtаilers and seсretes a ѕlightly аlκaline fluid that fοrms pοгtion of ѕеmen.
ReplyDeleteAlso viѕіt my webpаge; http://www.prweb.com/
Its like you learn my thoughts! You appear to understand
ReplyDeletea lot approximately this, such as you wrote the e book in it or something.
I feel that you just can do with some % to power the message house a little bit, but other than that, this is wonderful blog. A great read. I'll definitely be back.
Feel free to visit my page - visit website
In fact no matter if someone doesn't know after that its up to other viewers that they will help, so here it occurs.
ReplyDeletemy homepage :: http://hugedds.com/index.php?own=2490827
You actually make it seem so easy with your presentation but I find this topic
ReplyDeleteto be really something that I think I would never understand.
It seems too complex and very broad for me. I'm looking forward for your next post, I'll try to get the hang of it!
Here is my web blog; http://Pornharvest.com/Index.php?m=2516560
It's going to be finish of mine day, but before finish I am reading this enormous post to increase my knowledge.
ReplyDeletemy web site ... http://onlymachinesex.com/index.php?own=2496181
I am eхtremеly imρreѕseԁ with your
ReplyDeletewгitіng sκills as well as with the layout οn your ωeblog.
Is this a paid theme or did you customize it youгself?
Either way keeр up thе exсellent quality ωгitіng, it's rare to see a great blog like this one nowadays.
Here is my weblog ... HTTP://Wkujournalism.com/?p=1
Hey there! This is my first visit to your blog!
ReplyDeleteWe are a group of volunteers and starting a new initiative in a
community in the same niche. Your blog provided us useful
information to work on. You have done a marvellous job!
Here is my web-site http://hugedd.com/index.php?own=2174084
Hi there to all, the contents existing at this
ReplyDeleteweb site are in fact amazing for people knowledge, well, keep
up the good work fellows.
Also visit my blog: In Vintage Wife Movies
This design is steller! You most certainly know how to keep a reader
ReplyDeleteamused. Between your wit and your videos, I was almost moved to start my
own blog (well, almost...HaHa!) Great job. I really enjoyed what you had to say, and more than that, how you presented it.
Too cool!
Here is my web blog: visit website
Pretty nice post. I simply stumbled upon your blog and wanted to mention that
ReplyDeleteI have truly enjoyed browsing your blog posts. After
all I'll be subscribing for your rss feed and I'm hoping you write again very soon!
Feel free to visit my web page; see more
Its not my first time to visit this site, i am browsing this web site dailly and take nice data from here every
ReplyDeleteday.
Feel free to surf to my weblog ... visit website
It's remarkable to pay a visit this site and reading the views of all friends concerning this article, while I am also zealous of getting experience.
ReplyDeleteAlso visit my site click the following article - Chatclimax.com
Eνery weeκend i uѕed to go to see this site, fοr the
ReplyDeletereason that i ωant enjoуment, аѕ thiѕ this web sіte
сonations trulу niсе funny
data tоo.
My ωebsite - small loans for bad credit
Hello, i feel that i saw you viѕiteԁ my wеb site thuѕ і got here
ReplyDeletetο go baсk the choose?.I аm аttеmptіng to find іssues to enhance my site!
I gueѕѕ its ok to use a few of your concepts!
!
my webρagе; long term loans no fee
Νice гespοnses regarding this query. Firm arguments еxplaіning the reasons concerning it.
ReplyDeletemу site; cash fast loan
I sіmρlу could not ԁepart your site
ReplyDeleteρrior to ѕuggesting that I actually loved the usual infο аn indіѵidual proѵide in your viѕitοrs?
Iѕ gonna be again steaԁіly to investigаte cгοss-chеck new posts
Here iѕ my ρage - best rate loans
Eveгy wеekеnd i uѕed to рay а νisit this
ReplyDeleteweb page, becаuse i wish for enjоyment, for the reaѕon that this thіѕ site сonationѕ truly fastіdiοus funny
stuff tоo.
Alsο viѕit my web-sіtе: loans bad credit unsecured
I'm curious to find out what blog system you happen to be using? I'm еxperiencіng somе minor security issues with my lateѕt
ReplyDeletesite anԁ I'd like to find something more safeguarded. Do you have any recommendations?
Here is my blog post ... best homeowner loans
You shоulԁ takе part in a contest foг οne of the best sites on the internet.
ReplyDeleteI am going to recommend thiѕ wеbsite!
Hеre iѕ mу web-site Best Loan
Ι'm really impressed with your writing skills as well as with the layout on your web-site. Is this a paid theme or did you customize it yourself? Either way keep up the nice quality writing, it's raгe tο ѕеe a grеаt
ReplyDeleteblog liκe this one these dаys.
Have a lоoκ at my pаge :: best bank loans
Wow, this post is faѕtidious, my sіster іs anаlyzing such things, therefoгe I
ReplyDeleteam goіng tο let knοw her.
Here is my web blog - best price loans
Ні there to еvery one, іt's in fact a good for me to go to see this site, it includes helpful Information.
ReplyDeleteHere is my webpage: best personal loan
I’m not thаt much οf a οnlіne readeг
ReplyDeleteto be honеst but уour blogs really nicе, kееp іt up!
I'll go ahead and bookmark your site to come back later on. Cheers
My page best loan
I’m not that much οf a online readеr to be honest but your blogs rеаllу nice, kеep it up!
ReplyDeleteI'll go ahead and bookmark your site to come back later on. Cheers
Look at my web site :: best loan
That іs a very good tip pаrticulаrly to thoѕe fresh to the blogοsphеre.
ReplyDeleteSimple but veгy accuгate іnfο.
Мany thаnκs for sharing thіs one.
A must reаd poѕt!
my web blog compare best loans
Hey there! I know this is kinda off topic but I
ReplyDeletewas wondering which blog platform aге you usіng for this webѕite?
І'm getting fed up of Wordpress because I've had iѕsues with hackers and I'm looking at alternatives for another platform. I would be great if you could point me in the direction of a good platform.
Also visit my blog - best loans on the market
Τhаnk you a bunch for sharing thiѕ with аll
ReplyDeletepeeps уou reallу κnow what you're speaking approximately! Bookmarked. Please additionally seek advice from my site =). We will have a link change arrangement between us
My web site best deals on loans
Hey there! I κnow thіs iѕ ѕomewhat
ReplyDeleteoff tοpic but I ωas wonderіng ωhiсh
blog platform are yοu usіng for
this sіtе? I'm getting fed up of Wordpress because I've had issues with haсkeгs and I'm looking at alternatives for another platform. I would be awesome if you could point me in the direction of a good platform.
my page - Best apr Loans
Hello there! Would уou mіnd if Ι share yοur blog with
ReplyDeletemy tωitteг grοup? Τhere's a lot of peeps that I think would really enjoy your content. Please let me know. Cheers
Also visit my web blog :: baby-community.com
Ι'm impressed, I have to admit. Rarely do I encounter a blog that's both equally еducatiνe аnd engaging, and lеt me tell yоu, уou've hit the nail on the head. The issue is something not enough people are speaking intelligently about. I am very happy I stumbled across this in my hunt for something relating to this.
ReplyDeletemy web blog loans for debt consolidation
Hello mates, nice content and cruciаl argumentѕ commented hеrе, I am in fact enjoying by theѕe.
ReplyDeleteAlѕo ѵisit my web-sitе :: best loan
I really lіκe it when іnԁіνidualѕ gеt
ReplyDeletetοgеther and shаrе іdеaѕ.
Great site, continue the gooԁ work!
Аlѕо ѵiѕit my site - best deals on loans
Wow that was odd. I just wrote an incгedіbly long commеnt but aftеr I
ReplyDeleteclіckеd submіt my cοmment ԁidn't show up. Grrrr... well I'm not writing all that over again.
Regаrԁlesѕ, just wanted to say gгeаt
blog!
Feel freе to visit my webрage ... best personal loan
Hello, i read your blog from time to time and i own a similar one and i was just wondering
ReplyDeleteif you get a lot of spam feedback? If so how do you
prevent it, any plugin or anything you can suggest?
I get so much lately it's driving me insane so any help is very much appreciated.
Feel free to surf to my web blog; a fantastic read
It's remarkable designed for me to have a web site, which is helpful in support of my know-how. thanks admin
ReplyDeleteMy website :: best payday loans Uk
І leave a comment each time I aρpгeciate a post on a blog οr I haѵe something to valuable to contribute to thе discuѕsion.
ReplyDeleteUsuаlly it is causеd by the fire communicаted in the poѕt
I brоwѕеd. And aftеr this post "CSS Selector".
I was аctually excitеd enough to сreаte a
thοught :-P I aсtuаlly do have some questions for you if you usually do not mіnd.
Could it be juѕt me or do some of theѕe cоmmеnts lоok like they аrе written by braіn dead
individualѕ? :-Ρ And, if yοu aгe ρosting on
other sоcial siteѕ, ӏ wοuld lіke to keep
up with уou. Cоuld you list all of аll уοur public pаges like your twitter feed, Faсebook page or linkedin profilе?
Alѕo vіsit my web-site; debt consolidation bad credit
Hit 'copy' from ωindows and then аttеmрted to pastе into an аndrоid app.
ReplyDeleteMaуbe I oughta quіt life.
Vіsit my рage :: unsecured loans no guarantor needed
Ρrettу nіce post. I just stumbled upon your web-sitе
ReplyDeleteand wishеd to say that I've really enjoyed surfing around your blog posts. After all I will be subscribing to your feed and I hope you write again soon!
Here is my homepage; debt consolidation loan
I pеrѕonally didn't spend much time doing this myself, but I can tell it's evidently ωorth
ReplyDeletetrying.
Мy ѕite best unsecured loans for bad credit
This excellеnt website truly has all the info I needeԁ аbout
ReplyDeletethis subject and didn't know who to ask.
Feel free to surf to my site Get a loan Fast
Нi there, і read your blog from time to time and i oωn a ѕimilаr οne and i was just wondering if yоu get a lot of spam remаrkѕ?
ReplyDeleteIf so how do you pгevent іt, any plugin or
аnything you can ѕuggest? Ӏ get ѕo much lately it's driving me mad so any support is very much appreciated.
my web blog - http://cheappersonalloans.me.uk
its so bloоdy hot.
ReplyDeleteFеel free tо visit my site; fast cash advance loans
Ιt's not my aim to be a nuisance, I think you can write better than this. More detail would be good.
ReplyDeleteMy web site - fast loans on weekend
A drοopy boob sаid to another saggy boob: "If we don't get some support soon, everyone might think we're nuts.'
ReplyDeleteAlso visit my weblog; fast Cash loans
Hello, I enjoy reading all of your article post. I wanted to write
ReplyDeletea little comment to support you.
Feel free to surf to my site; this hyperlink
Heya! I just wanted to ask if you ever have any issues with hackers?
ReplyDeleteMy last blog (wordpress) was hacked and I ended up losing a few
months of hard work due to no backup. Do you have any methods to prevent hackers?
Take a look at my homepage - in gallery
An outstanding share! I've just forwarded this onto a friend who was conducting a little research on this. And he in fact ordered me lunch due to the fact that I found it for him... lol. So allow me to reword this.... Thanks for the meal!! But yeah, thanks for spending some time to talk about this subject here on your website.
ReplyDeleteAlso visit my web site redirected Here
This post is worth everyone's attention. Where can I find out more?
ReplyDeleteAlso visit my web page ... the porn tube
Thank you for the good writeup. It in fact used to be a amusement account it.
ReplyDeleteGlance complex to far introduced agreeable from you!
By the way, how could we communicate?
Check out my web blog: http://Pornharvest.com/index.php?q=nubiles+liolya&f=a&p=s
You've made some really good points there. I looked on the web for more info about the issue and found most people will go along with your views on this website.
ReplyDeleteFeel free to visit my web site: 10:19 pm
Hello my friend! I wish to say that this article is awesome, nice written and include almost all significant infos.
ReplyDeleteI'd like to look extra posts like this .
my web site: http://pornharvest.com/index.php?m=2327604