The Comprehensive CSS Selectors Cheat Sheet

in #stem5 years ago (edited)

There is no shortage of various CSS cheat-sheets and quick reference guides online. However, most of them target web designers and only a handful are aimed at the developer crowd. Especially when it comes to backend developers who suddenly find themselves writing frontend automation with CSS selectors.

<p dir="auto">Sure, you can go ahead and have some fun learning CSS through online minigames. If you are so inclined and have the free time to dedicate to gamified expansion of your skillset – <a href="https://itnext.io/train-your-css-skills-with-online-games-11067129338a" target="_blank" rel="nofollow noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">go for it. But if you’re looking for a focused and short CSS selectors cheat sheet made for developers – we’ve created one just for you. <p dir="auto"><img src="https://images.hive.blog/768x0/https://blog.codota.com/wp-content/uploads/2020/02/download-1.jpeg" srcset="https://images.hive.blog/768x0/https://blog.codota.com/wp-content/uploads/2020/02/download-1.jpeg 1x, https://images.hive.blog/1536x0/https://blog.codota.com/wp-content/uploads/2020/02/download-1.jpeg 2x" /> <h2>What are CSS Selectors (and why you need them)? <p dir="auto">Generally speaking, <a href="https://en.wikipedia.org/wiki/Cascading_Style_Sheets" target="_blank" rel="nofollow noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">CSS (Cascading Style Sheets) are awesome. CSS are like libraries for a website, and they have been one of the best things to happen to the way the web looks and works in the past 20 years. <p dir="auto">CSS selectors are components in the CSS rulebase and are at the heart of advanced CSS. They essentially save you a lot of manual coding by letting you easily manipulate multiple elements according to their properties. <p dir="auto">The latest iteration of CSS, <a href="https://tutorial.techaltum.com/css3-selectors.html" target="_blank" rel="nofollow noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">CSS 3.0, added selector options for styling automation. With the selector options added you can write your code to select pretty much any element in the website or webapp frontend. <h2>CSS Selectors Cheat Sheet for Developers <div class="table-responsive"><table> <thead> <tr><th>Selector Name<th>Syntax<th>Description<th>Example <tbody> <tr><td>Universal Selector<td><code>*<td>Selects all the elements<td><code>* {color: pink;font-size: 20px;} <tr><td>Type Selector<td><code>element{properties}<td>Selects elements based on element type<td><code>p {color: pink;font-size: 20px;} <tr><td>Id Selector<td><code>#id{properties}<td>Selects an element with a specified id<td><code>#adbox {width: 80px;margin: 5px;} <tr><td>Class Selector<td><code>.class{properties}<td>Selects elements of the specified CSS class<td><code>.dark {color: black;} <tr><td>Attribute Selectors<td><td><td> <tr><td><td><code>element[attribute]{properties}<td>Selects elements with the specified attribute<td><code>input[disabled] {background-color: #fff;} <tr><td><td><code>element[attribute="value"]<td>Selects elements with the specified attribute equaling a value<td><code>input[type=”text”] {color: black;} <tr><td><td><code>element[attribute~="value"]<td>Selects elements with the specified attribute the value of which contains a specific word.<td>`h1[title~="Codota"] {color: pink;font-size: 20px;}' <tr><td><td><code>element[attribute"ן="value"]<td>Selects elements with the specified attribute and attribute value with the attribute beginning with specified value (or specified value immediately followed by “-“)<td>' a[hreflangן="en"] { color: blue;}' <tr><td><td><code>element[attribute^="value"]<td>Selects elements with the specified attribute with the attribute value starting with specified value<td><code>h2[title^="Codota"] {color: black;font-size: 20px;} <tr><td><td><code>element[attribute$="value"]<td>Selects elements with the specified attribute with the attribute value ending with specified value<td><code>h3[title$="Right Now!"] {color: red;font-size: 30px;} <tr><td><td><code>element[attribute*="value"]<td>Selects elements with the specified attribute where the attribute value contains a specified value<td><code>h4[title*="new"] {color: red;font-size: 20px;} <tr><td>Descendant Combinator<td><code>element1 element2{properties}<td>Selects all specified child descendant elements (element2) under the parent element (element1).<td><code>div p{color:pink;} <tr><td>Child Combinator<td><code>element1 > element2{properties}<td>Selects all specified immediate child elements (element2) under the parent element (element1).<td><code>div > p{color:pink;} <tr><td>Pseudo Classes<td><td> <tr><td><td><code>element:link{properties}<td>Selects unvisited link elements<td><code>a:link{color:blue;} <tr><td><td><code>element:visited{properties}<td>Selects visited link elements<td><code>a:visited{color:red;} <tr><td><td><code>element:active{properties}<td>Selects active link elements<td><code>a:active{color:green;} <tr><td><td><code>element:hover{properties}<td>Selects mouseover hover elements<td><code>a:hover{color:purple;} <tr><td><td><code>element:focus{properties}<td>Selects in-focus elements<td><code>a:focus{color:pink;} <p dir="auto">Got more? Let me know in the comments! <p dir="auto"><em>This post, written by yours truly, was <a href="https://blog.codota.com/css-selectors-cheat-sheet-for-developers/" target="_blank" rel="nofollow noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">published originally on the Codota blog for awesome developers. <p dir="auto">P.S. Sorry for the markdown butchering my code examples. Hope you forgive me just his once. <3
Sort:  

Hi @techslut!


Your UA account score is currently 5.968 which ranks you at #344 across all Steem accounts.
Your rank has not changed in the last three days.Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!

In our last Algorithmic Curation Round, consisting of 93 contributions, your post is ranked at #12.

Evaluation of your UA score:
  • You've built up a nice network.
  • The readers appreciate your great work!
  • Try to work on user engagement: the more people that interact with you via the comments, the higher your UA score!

Feel free to join our @steem-ua Discord server

Congratulations @techslut! You received a personal award!

Look's like you do not like Justin. Did you really downvote him?

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Do not miss the last post from @steemitboard:

Use your witness votes and get the Community Badge
Vote for @Steemitboard as a witness to get one more award and increased upvotes!

Congratulations @techslut! You received a personal award!

Did you downvote Steemit's posts because its owner converted it into a sockpuppets factory? OK, you deserve that badge!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Do not miss the last post from @steemitboard:

Use your witness votes and get the Community Badge
Vote for @Steemitboard as a witness to get one more award and increased upvotes!
 5 years ago  Reveal Comment