Categories
CSS

How to select the first element with class with CSS?

Sometimes, we want to select the first element with class with CSS.

In this article, we’ll look at how to select the first element with class with CSS.

How to select the first element with class with CSS?

To select the first element with class with CSS, we the first-of-type.

For instance, we write

.red:first-of-type {
  color: red;
}

to select the first element with class red with .red:first-of-type.

Conclusion

To select the first element with class with CSS, we the first-of-type.

Categories
CSS

How to hide the HTML5 number input’s spin box with CSS?

Sometimes, we want to hide the HTML5 number input’s spin box with CSS.

In this article, we’ll look at how to hide the HTML5 number input’s spin box with CSS.

How to hide the HTML5 number input’s spin box with CSS?

To hide the HTML5 number input’s spin box with CSSm we set a few styles.

For instance, we write

<input type="number" step="0.01" />

to add a number input.

Then we hide the spin box with

input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type="number"] {
  -moz-appearance: textfield;
}

to use -webkit-appearance: none; to hide the spin box.

We use -moz-appearance: textfield; to hide the spin box in Firefox.

Conclusion

To hide the HTML5 number input’s spin box with CSSm we set a few styles.

Categories
CSS

How to apply CSS to iframe?

Sometimes, we want to apply CSS to iframe.

In this article, we’ll look at how to apply CSS to iframe.

How to apply CSS to iframe?

To apply CSS to iframe, we set the style attribute.

For instance, we write

<iframe
  name="iframe1"
  id="iframe1"
  src="empty.htm"
  frameborder="0"
  border="0"
  cellspacing="0"
  style="border-style: none; width: 100%; height: 120px"
></iframe>

to add the style attribute with the styles for the iframe.

Conclusion

To apply CSS to iframe, we set the style attribute.

Categories
CSS

How to center text (horizontally and vertically) inside a div block with CSS?

Sometimes, we want to center text (horizontally and vertically) inside a div block with CSS.

In this article, we’ll look at how to center text (horizontally and vertically) inside a div block with CSS.

How to center text (horizontally and vertically) inside a div block with CSS?

To center text (horizontally and vertically) inside a div block with CSS, we use flexbox.

For instance, we write

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

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

Then we center items horizontally with justify-content: center;.

We center items vertically with align-items: center;.

Conclusion

To center text (horizontally and vertically) inside a div block with CSS, we use flexbox.

Categories
HTML

How to make Bootstrap columns all the same height with HTML?

Sometimes, we want to make Bootstrap columns all the same height with HTML.

In this article, we’ll look at how to make Bootstrap columns all the same height with HTML.

How to make Bootstrap columns all the same height with HTML?

To make Bootstrap columns all the same height with HTML, we use the flexbox classes.

For instance, we write

<div class="container">
  <div class="row">
    <div class="col-md-4" style="background-color: red">some content</div>
    <div class="col-md-4" style="background-color: yellow">
      catz
      <img width="100" height="100" src="https://placekitten.com/100/100/" />
    </div>
    <div class="col-md-4" style="background-color: green">
      some more content
    </div>
  </div>
</div>

to add the container class to make the outer div a flex container.

Then we add the row and column classes to make the inner divs rows and columns with the same height.

Conclusion

To make Bootstrap columns all the same height with HTML, we use the flexbox classes.