h1 {
color: red;
font-size: 5em;
}
h1 {
color: red;
font-size: 20px;
}
p {
color: black;
}
Examples:
HTML
A text where I need to
<span class="ref">
something<span>
Css
.ref::before {
font-weight: bold;
color: navy;
content: "Reference ";
}
HTML
<a href="developer.mozilla.org" class="glossary">
</a>
Css
a.glossary::after {
content:" ",
url("glossary-icon.gif");
}
| CSS Frameworks | ||||
| 1. Bootstrap | 2. Tailwind CSS | 3. Foundation | 4. Bulma | 5. Skeleton |
p { color: green; }
<p>
This paragraph has
<em>emphasized text</em>
in it.
</p>
Color is an inherited property while the background is not. So this can make confusion further.
You can control inheritance for all properties at once using the all shorthand property,
which applies its value to all properties. For example:
p {
all: revert;
font-size: 200%;
font-weight: bold;
}
<style>
p {
font-family: georgia, serif;
font-size: x-small;
}
hr {
color: #ff9900;
height: 1px;
}
a:hover {
color: #ff0000;
text-decoration: none;
}
</style>
/* Selects all elements */
* {
color: green;
}
Examples:
* [lang^=en] {
color: green;
}
*.warning {
color: red;
}
*#maincontent {
border: 1px solid blue;
}
.floating {
float: left
}
/*
automatically clear
the next sibling after a
floating element
*/
.floating + * {
clear: left;
}
/* All elements. */
a {
color: red;
}
Examples:
span {
background-color: red;
}
HTML
<span>
Here's a span with some text.
</span>
<p>
Here's a p with some text.
</p>
<span>
Here's a span with more text.
</span>
Here's a p with some text.
Here's a span with more text.
/* All elements with class="spacious" */
.spacious {
margin: 2em;
}
/* All <li>
elements with class="spacious" */
li.spacious {
margin: 2em;
}
/* All <li>
elements with a class list that includes both
"spacious" and "elegant" */
/* For example, class="elegant retro spacious" */
li.spacious.elegant {
margin: 2em;
}
.class_name { style properties }
Examples:
.red {
color: #f33;
}
.yellow-bg {
background: #ffa;
}
.fancy {
font-weight: bold;
text-shadow: 4px 4px 3px #77f;
}
HTML
<p class="red">This paragraph has red text.</p>
<p class="red yellow-bg">This paragraph has red text and a yellow background.</p>
<p class="red fancy">This paragraph has red text and "fancy" styling.</p>
<p>This is just a regular paragraph.</p>
This paragraph has red text.
This paragraph has red text and a yellow background.
This paragraph has red text and "fancy" styling.
This is just a regular paragraph.
/* The element with id="demo" */
#demo {
border: red 2px solid;
}
Syntax:
#id_value { style properties }
Examples:
#identified {
background-color: blue; color: white;
}
HTML
<div id="identified">This div has a special ID on it!</div>
<div>This is just a regular div.'</div>| Chrome | Edge | Safari Mini | Firefox | Opera | IE |
| Support | Support | Support | Support | Support | Support |
<div class="light">You can barely see this.</div>
<div class="medium">This is easier to see.</div>
<div class="heavy">This is very easy to see.</div>div {
background-color: yellow;
font-weight: bold;
font-size: 130%;
}
.light {
opacity: 0.2;
/* Barely see the text over the background */
}
.medium {
opacity: 0.5;
/* See the text more clearly over the background */
}
.heavy {
opacity: 0.9;
/* See the text very clearly over the background */
}<div class="wrapper">
<img src="//interactive-examples
.mdn.mozilla.net/media/dino.svg"
alt="MDN Dino" width="128" height="146"
class="opacity">
</div>
img.opacity {
opacity: 1;
}
img.opacity:hover {
opacity: 0.5;
}
.wrapper {
width: 200px;
height: 160px;
background-color: #f03cc3;
background-image:
linear-gradient(90deg,
transparent 50%,
rgba(255,255,255,.5) 50%);
background-size: 20px 20px;
}
| Chrome | Edge | Safari Mini | Firefox | Opera | IE |
| Support | Support | Not Support | Support | Support | Support |
html {
font-size: 1em;
}
h1 {
font-size: 2rem;
}
@media (min-width: 1200px) {
h1 {
font-size: 4rem;
}
}
| Logical tags | Physical tags |
| 1: Logical tags describe the behaviour, nature of content for the text enclosed inside the tag. They represent the function of text on the page. | 2: Physical tags are used to decide the appearance of the text and do not provide any information about the text. |
| 1: It carries certain obligations. | 2: It is extremely straightforward. |
| 1: It is used to mention visually impaired texts. | 2: It is used to indicate the specific characters which need formation. |
| 1: Here, the pages are more accessible. | 2: Page accessibility is comparatively low. |
| 1: It supports the latest technology. | 2: This concept is dependent upon weak tools. |
| 1: Logical tags are used to provide information by giving the special importance to the text. For instance, <em> tag is used to emphasize the text by representing it in italic format. | 2: Physical tags are used to style the content only. For instance, <i> is used to display the text in italic format. |
div {
width: 300px;
border: 15px solid green;
padding: 50px;
margin: 20px;
}
| Specified value | Computed value |
| 1: inline | 2: Block |
| 1: inline-block | 2: Block |
| 1: inline-table | 2: Block |
| 1: table-row | 2: Block |
| 1: table-row-group | 2: Block |
| 1: table-column | 2: Block |
| 1: table-column-group | 2: Block |
| 1: table-cell | 2: Block |
| 1: table-caption | 2: Block |
| 1: table-header-group | 2: Block |
| 1: table-footer-group | 2: Block |
| 1: inline-flex | 2: flex |
| 1: inline-grid | 2: grid |
| 1: other | 2: unchanged |
* {all: revert}
div {all: revert}
/* Keyword value */
z-index: auto;
/* <integer> values */
z-index: 0;
z-index: 3;
z-index: 289;
z-index: -1; /*
Negative values to lower
the priority
*/
/* Global values */
z-index: inherit;
z-index: initial;
z-index: revert;
z-index: revert-layer;
z-index: unset;
Example:
<div class="wrapper">
<div class="dashed-box">
Dashed box
</div>
<div> class="gold-box"<
Gold bo
x</div>
<div class="green-box">
Green box
</div>
</div>
CSS
.wrapper {
position: relative;
}
.dashed-box {
position: relative;
z-index: 1;
border: dashed;
height: 8em;
margin-bottom: 1em;
margin-top: 2em;
}
.gold-box {
position: absolute;
background: gold;
width: 80%;
left: 60px;
top: 3em;
}
.green-box {
position: absolute;
z-index: 2; /*
put .green-box above .dashed-box
*/
background: lightgreen;
width: 20%;
left: 65%;
top: -25px;
height: 7em;
opacity: 0.9;
}