body { background-color: lightblue; } /* element (and group) selector */ h1, h2, p { text-align: center; color: red; } /* id selector */ #foss { text-align: center; color: green; } /* clsss selector */ .major { text-align: center; } p.major { color: red; } /* universal selector */ * { text-align: center; color: blue; } /* element only when inside other element (first is parent second is child) */ ul li { color: cyan } /* element state */ /* when hovered with mouse */ h2:hover { background-color: red; } /* when clicked */ h2:active { background-color: green; } /* also
Click to show panel
*/ /* make nth row in a table a different color */ tr:nth-child(even){background-color: #f2f2f2;} /* make table responsive (horizontally scrollable */ div.tablecontainer { overflow-x: auto; } /* clearfix hack */ .clearfix::after { content: ""; clear: both; display: table; } /* Combinators */ /* descendant combinator: space */ /* all p elements inside div elements */ div p { background-color: yellow; } /* child combinator: > */ /* only direct children, immediately descendant */ div > p { background-color: yellow; } /* next sibling combinator: + */ /* elements that are right next to each other on the same level within the same parent */ div + p { background-color: yellow; } /* subsequent-sibling combinator: ~ */ /* style all ul elements that come after any p element, no need to be immediately after and within the same parent */ p ~ ul { background-color: gold; border: 1px solid gray; } /* Pseudo-classes, the ":" operator */ /* unvisited link */ a:link { color: #FF0000; } /* visited link */ a:visited { color: #00FF00; } /* mouse over link */ a:hover { color: #FF00FF; } /* selected link */ a:active { color: #0000FF; } /* when input box is focused */ input:focus { background-color: yellow; } /* with descendant combinator */ /* change visibility of all p elements inside div when hovered */ div:hover p { display: block; }