Categories
CSS

How to remove focus border (outline) around text/input boxes with CSS?

Sometimes, we want to remove focus border (outline) around text/input boxes with CSS.

In this article, we’ll look at how to remove focus border (outline) around text/input boxes with CSS.

How to remove focus border (outline) around text/input boxes with CSS?

To remove focus border (outline) around text/input boxes with CSS, we set the outline property.

For instance, we write

textarea:focus,
input:focus {
  outline: none;
}

to remove the outline when we focus on the input or textarea with outline: none;.

Conclusion

To remove focus border (outline) around text/input boxes with CSS, we set the outline property.

Categories
CSS

How to vertically center a div element for all browsers using CSS?

Sometimes, we want to vertically center a div element for all browsers using CSS.

In this article, we’ll look at how to vertically center a div element for all browsers using CSS.

How to vertically align an image inside a div with CSS?

To vertically center a div element for all browsers using CSS, we use flexbox.

For instance, we write

<div class="parent">
  <img class="child" src="https://picsum.photos/300/300" />
</div>

to add a div with an img element inside.

Then we write

.parent {
  align-items: center;
  background: red;
  display: flex;
  height: 250px;
  width: 250px;
}

to make the div a flex container with display: flex;.

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

Conclusion

To vertically center a div element for all browsers using CSS, we use flexbox.

Categories
CSS

How to set font scaling based on the width of container with CSS?

Sometimes, we want to set font scaling based on the width of container with CSS.

In this article, we’ll look at how to set font scaling based on the width of container with CSS.

How to set font scaling based on the width of container with CSS?

To set font scaling based on the width of container with CSS, we set the vw unit.

For instance, we write

p {
  font-size: 4vw;
}

to set the p elements’ font size to 4vw, which 4% of the screen’s width.

Conclusion

To set font scaling based on the width of container with CSS, we set the vw unit.

Categories
CSS

How to style a select dropdown with only CSS?

Sometimes, we want to style a select dropdown with only CSS.

In this article, we’ll look at how to style a select dropdown with only CSS.

How to style a select dropdown with only CSS?

To style a select dropdown with only CSS, we set the appearance property.

For instance, we write

select {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url(...);
}

to set appearance to none to remove the default select arrow.

Then we set the background-image property to add our own arrow.

Conclusion

To style a select dropdown with only CSS, we set the appearance property.

Categories
CSS

How to vertically align text in a div with CSS?

Sometimes, we want to vertically align text in a div with CSS.

In this article, we’ll look at how to vertically align text in a div with CSS.

How to vertically align text in a div with CSS?

To vertically align text in a div with CSS, we use flexbox.

For instance, we write

<ul>
  <li>
    <p>Some Text</p>
  </li>
  <li>
    <p>A bit more text that goes on two lines</p>
  </li>
  <li>
    <p>Even more text that demonstrates how lines can span multiple lines</p>
  </li>
</ul>

to add some elements.

Then we write

li {
  display: flex;
  justify-content: center;
  align-content: center;
  flex-direction: column;
}

to make the li elements flex containers with display: flex;.

And then we set the flex direction to vertical with flex-direction: column;.

We vertically center content with justify-content: center;.

And we horizontally center content with align-content: center;

Conclusion

To vertically align text in a div with CSS, we use flexbox.