@media query
is used for special devices.
In the example below @media query
is for devices with width less than or equal to 600px
#main {
width: 70%;
float: left;
padding: 0 30px;
box-sizing: border-box;
}
#sidebar {
width: 30%;
float: right;
padding: 0 30px;
box-sizing: border-box;
}
@media(max-width:600px) {
#main {
width: 100%;
float: none;
}
#sidebar {
width: 100%;
float: none;
}
}
div.mydiv {
min-height: 100px;
}
The div will start at 100px, if the content pushes the div beyond 100px it will continue growing.
However if you have content that takes less than 100px it will still take 100px in space.<span>
).
Any height and width properties will have no effectfirst-child
to select only the first child element:.my-list li:first-child {
background-color: red;
}
last-child
is used to select the last member from the list:my-list li:last-child {
background-color: blue;
}
nth-child(5)
is used to select nth
element. In the example we select 5th element.my-list li:nth-child(5) {
background-color: yellow;
}
We can also use nth-child(even)
to select even members from the list.my-list li:nth-child(even) {
background-color: grey;
}
div.sticky {
background-color: yellow;
position: sticky;
top: 0;
}
A sticky element toggles between relative and fixed, depending on the scroll position. It is positioned relative until a given offset position is met in the viewport - then it "sticks" in place like position:fixed
static
).parent {
position: relative;
}
.parent h1 {
position: absolute;
top: 10px;
}
https://youtu.be/aFtByxWjfLY?t=200.my-form input[type="text"]{
padding: 8px;
width: 100%;
}
In this example, only inputs will be selected with types text
label
element to block level element using the code below.
So they will take the full width of the container.my-form label {
display: block;
}