colorSets the color of text.
p {
color: blue;
}
background-colorSets the background color of an element.
div {
background-color: #f0f0f0;
}
font-familySpecifies the font for text.
body {
font-family: Arial, sans-serif;
}
font-sizeSets the size of the font.
h1 {
font-size: 24px;
}
font-weightDefines the thickness of characters.
strong {
font-weight: bold;
}
text-alignAligns the text within an element.
.center-text {
text-align: center;
}
width and heightSets the width and height of an element.
.box {
width: 200px;
height: 100px;
}
paddingCreates space inside an element, between its content and its border.
.padded {
padding: 10px;
}
marginCreates space outside an element.
.spaced {
margin: 20px;
}
borderAdds a border around an element.
.bordered {
border: 1px solid black;
}
displaySpecifies how an element should be displayed.
span {
display: inline-block;
}
visibilityDetermines whether an element is visible or hidden.
.hidden {
visibility: hidden;
}
positionSpecifies the positioning method for an element.
.relative {
position: relative;
top: 10px;
left: 20px;
}
z-indexControls the stacking order of elements.
.top-layer {
z-index: 1;
}
display: flexCreates a flex container.
.container {
display: flex;
}
flex-directionDefines the direction of flex items.
.column {
flex-direction: column;
}
justify-contentAligns flex items along the main axis.
.spread {
justify-content: space-between;
}
display: gridCreates a grid container.
.grid-container {
display: grid;
}
grid-template-columnsDefines the columns of the grid.
.three-column {
grid-template-columns: 1fr 1fr 1fr;
}
transitionAdds smooth transitions to property changes.
button {
transition: background-color 0.3s ease;
}
transformApplies 2D or 3D transformations to an element.
.rotated {
transform: rotate(45deg);
}
@mediaApplies different styles for different screen sizes.
@media screen and (max-width: 600px) {
body {
font-size: 14px;
}
}
Select elements based on their attributes or attribute values.
/* Selects inputs with a "type" attribute of "text" */
input[type="text"] {
border: 1px solid #ccc;
}
/* Selects anchors with an "href" starting with "https" */
a[href^="https"] {
color: green;
}
Target specific states or parts of elements.
/* Style the first line of a paragraph */
p::first-line {
font-weight: bold;
}
/* Style odd rows in a table */
tr:nth-child(odd) {
background-color: #f2f2f2;
}
Define reusable values that can be used throughout your stylesheet.
:root {
--primary-color: #3498db;
--secondary-color: #2ecc71;
}
.button {
background-color: var(--primary-color);
color: white;
}
box-sizingChanges how the total width and height of elements are calculated.
* {
box-sizing: border-box;
}
clip-pathCreates a clipping region that sets what part of an element should be shown.
.clip-circle {
clip-path: circle(50% at center);
}
flex-grow, flex-shrink, and flex-basisFine-tune how flex items grow and shrink.
.flex-item {
flex: 1 0 200px; /* grow shrink basis */
}
align-selfAligns individual flex items.
.special-item {
align-self: flex-end;
}
grid-template-areasDefines named grid areas.
.container {
display: grid;
grid-template-areas:
"header header"
"sidebar content"
"footer footer";
}
.header { grid-area: header; }
.sidebar { grid-area: sidebar; }
.content { grid-area: content; }
.footer { grid-area: footer; }
minmax()Sets a size range for grid tracks.
.grid {
grid-template-columns: repeat(3, minmax(100px, 1fr));
}
Create complex, multi-step animations.
@keyframes slide-in {
0% { transform: translateX(-100%); }
100% { transform: translateX(0); }
}
.animated {
animation: slide-in 0.5s ease-out;
}
Fine-tune your animations.
.bounce {
animation-name: bounce;
animation-duration: 1s;
animation-timing-function: ease-in-out;
animation-iteration-count: infinite;
animation-direction: alternate;
}
Create non-rectangular shapes for text wrapping.
.circle-text {
shape-outside: circle(50%);
width: 200px;
height: 200px;
float: left;
}
Apply graphical effects like blur or color shifting to elements.
.blurred {
filter: blur(5px);
}
.vintage {
filter: sepia(0.5) contrast(1.2) brightness(1.1);
}
Allows grid items to inherit the grid of their parent.
.grid-container {
display: grid;
grid-template-columns: repeat(3, 1fr);
}
.grid-item {
display: grid;
grid-template-columns: subgrid;
}
Write direction-agnostic styles for better internationalization.
.box {
margin-inline-start: 1em;
padding-block-end: 2em;
}
Improve performance by isolating parts of the page.
.widget {
contain: content;
}
next -> Css Display