CSS SHORT
CSS SHORT
Separate content from presentation, ensuring that websites are accessible and
maintainable.
Adapt the presentation to different types of devices, such as large screens, small
screens, or printers.
Example:
Without CSS, an HTML document may appear as plain text with links. With CSS, the
same document can have colors, varied fonts, layouts, and more.
selector {
property: value;
}
Example:
p {
color: red;
}
This CSS will make all paragraphs ( <p> ) have red text.
3. Backgrounds:
You can set the background properties of an element:
Short CSS 1
background-image : Sets a background image.
Example:
div {
background-color: yellow;
background-image: url('image.jpg');
background-repeat: no-repeat;
background-position: center center;
background-size: cover;
}
HEX: #FF0000
RGB: rgb(255,0,0)
Example:
p {
color: #FF0000; /* Text color */
background-color: rgba(0, 255, 0, 0.3); /* Semi-transparent green background */
}
5. Manipulating Texts:
Various properties control text appearance:
Short CSS 2
color : Sets the text color.
Example:
p {
text-align: center;
text-decoration: underline;
line-height: 1.5;
text-transform: uppercase;
}
6. Fonts:
Control the typography of an element:
Example:
body {
font-family: 'Arial', sans-serif;
font-size: 16px;
font-weight: bold;
font-style: italic;
}
border : Shorthand for setting the width, style, and color of the borders.
Short CSS 3
border-radius : Rounds the corners of an element.
Example:
div {
border: 2px solid black;
border-radius: 5px;
box-shadow: 3px 3px 5px #888888;
}
padding : Sets the space between the content and the border.
Example:
div {
margin: 20px;
padding: 10px;
}
9. Lists:
Style list elements:
list-style-type : Specifies the type of list item marker ( disc , circle , square ,
decimal , none , etc.).
Example:
ul {
list-style-type: square;
}
li.special {
list-style-image: url('marker.jpg');
}
Short CSS 4
10. CSS2 and CSS3:
CSS2 was a revision of the original CSS specification. CSS3, on the other hand, is
divided into "modules", allowing specifications to be written and revised individually.
Differences:
11. Animations:
CSS3 introduced the ability to create animations using keyframes.
Example:
@keyframes slide {
from { transform: translateX(0%); }
to { transform: translateX(100%); }
}
div {
animation: slide 5s infinite;
}
12. Tool-Tips:
Tooltips are a common UI element that offers hints or extra information when hovered
over or focused on.
Example:
[data-tooltip]:hover:after {
content: attr(data-tooltip);
position: absolute;
background-color: #333;
color: #fff;
padding: 5px;
border-radius: 5px;
}
Short CSS 5
Use with HTML:
Example:
img {
border-radius: 50%;
box-shadow: 3px 3px 5px #888888;
filter: brightness(80%);
}
14. Variables:
CSS variables (or custom properties) allow you to store specific values for reuse
throughout your stylesheet.
Example:
:root {
--primary-color: #4CAF50;
}
body {
background-color: var(--primary-color);
}
Example:
Short CSS 6
.container {
display: flex;
justify-content: space-between;
}
Example:
* {
box-sizing: border-box;
}
a[href^="https://"] {
background-color: yellow;
}
input[name$="name"] {
border: 2px solid red;
}
Short CSS 7
18. Working with Gradients:
Gradients can be linear or radial:
Example:
div {
background: linear-gradient(red, yellow);
}
a:hover {
color: red;
}
p:first-child {
font-weight: bold;
}
p::first-line {
color: blue;
}
p::before {
content: "Read this: ";
}
Short CSS 8
22. Responsive Web Design and Media Query:
Responsive design ensures a website looks good on all devices. Media queries, flexible
grid layouts, flexible images, and an understanding of the viewport and its size help in
achieving this.
Example:
Short CSS 9