Categories
CSS

How to position a div at the bottom of its container with CSS?

Sometimes, we want to position a div at the bottom of its container with CSS.

In this article, we’ll look at how to position a div at the bottom of its container with CSS.

How to position a div at the bottom of its container with CSS?

To position a div at the bottom of its container with CSS, we use flexbox.

For instance, we write

.parent {
  display: flex;
}

.child {
  align-self: flex-end;
}

to make the element with class parent a flex container with display: flex;.

Then we make the element with class child in the flex container stay at the bottom with align-self: flex-end;.

Conclusion

To position a div at the bottom of its container with CSS, we use flexbox.

Categories
CSS

How to center horizontally and vertically with flexbox and CSS?

Sometimes, we want to center horizontally and vertically with flexbox and CSS.

In this article, we’ll look at how to center horizontally and vertically with flexbox and CSS.

How to center horizontally and vertically with flexbox and CSS?

To center horizontally and vertically with flexbox and CSS, we use align-items and justify-content.

For instance, we write

#parent {
  display: flex;
  align-items: center;
  justify-content: center;
}

to make the element with ID parent a flex container with display: flex;.

Then we vertically align the items inside with align-items: center;.

We horizontally align the items inside with justify-content: center;.

Conclusion

To center horizontally and vertically with flexbox and CSS, we use align-items and justify-content.

Categories
CSS

How to wrap text in a pre tag with CSS?

Sometimes, we want to wrap text in a pre tag with CSS.

In this article, we’ll look at how to wrap text in a pre tag with CSS.

How to wrap text in a pre tag with CSS?

To wrap text in a pre tag with CSS, we set the white-space property.

For instance, we write

pre {
  white-space: pre-wrap;
}

to set white-space to pre-wrap to make the text in the pre element wrap.

Conclusion

To wrap text in a pre tag with CSS, we set the white-space property.

Categories
CSS

How to set 100% height with padding/margin with CSS?

Sometimes, we want to set 100% height with padding/margin with CSS.

In this articl, we’ll look at how to set 100% height with padding/margin with CSS.

How to set 100% height with padding/margin with CSS?

To set 100% height with padding/margin with CSS, we set the box-sizing property.

For instance, we write

div {
  box-sizing: border-box;
}

to make the div stay the same size after adding padding.

Conclusion

To set 100% height with padding/margin with CSS, we set the box-sizing property.

Categories
CSS

How to inherit CSS classes?

Sometimes, we want to inherit CSS classes.

In this article, we’ll look at how to inherit CSS classes.

How to inherit CSS classes?

To inherit CSS classes, we add multiple classes to an element.

For instance, we write

<div class="classOne classTwo">
  <p>I'm bold and verdana.</p>
</div>

to add classOne and classTwo to the div.

Then we write

.classOne {
  font-weight: bold;
}
.classTwo {
  font-famiy: verdana;
}

to add the styles for classOne and classTwo.

The styles for both classes will be applied to the div.

Conclusion

To inherit CSS classes, we add multiple classes to an element.