Categories
CSS

How to change the color of an svg element with CSS?

Sometimes, we want to change the color of an svg element with CSS.

In this article, we’ll look at how to change the color of an svg element with CSS.

How to change the color of an svg element with CSS?

To change the color of an svg element with CSS, we set the filter property.

For instance, we write

<img src="dotted-arrow.svg" class="filter-green" />

to add an img element with the svg.

Thenw ewrite

.filter-green {
  filter: invert(48%) sepia(79%) saturate(2476%) hue-rotate(86deg)
    brightness(118%) contrast(119%);
}

to tweak the colors for the filter-green class by apply filters to the image.

Conclusion

To change the color of an svg element with CSS, we set the filter property.

Categories
CSS

How to disable a link using only CSS?

Sometimes, we want to disable a link using only CSS.

in this article, we’ll look at how to disable a link using only CSS.

How to disable a link using only CSS?

To disable a link using only CSS, we set the pointer-events property.

For instance, we write

<a href="#" class="disabled">link</a>

to add a link.

Then we write

.disabled {
  pointer-events: none;
  cursor: default;
  opacity: 0.6;
}

to add pointer-events: none; to disable clicks on the link.

We set cursor: default; to set the cursor to the default arrow.

Conclusion

To disable a link using only CSS, we set the pointer-events property.

Categories
CSS

How to right-align flex item with CSS?

Sometimes, we want to right-align flex item with CSS.

In this article, we’ll look at how to right-align flex item with CSS.

How to right-align flex item with CSS?

To right-align flex item with CSS, we set the justify-content property.

For instance, we write

.main {
  display: flex;
}
.c {
  justify-content: flex-end;
}

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

Then we right align the elements inside it with justify-content: flex-end;.

Conclusion

To right-align flex item with CSS, we set the justify-content property.

Categories
CSS

How to center a “position: absolute” element with CSS?

Sometimes, we want to center a "position: absolute" element with CSS.

In this article, we’ll look at how to center a "position: absolute" element with CSS.

How to center a "position: absolute" element with CSS?

To center a "position: absolute" element with CSS, we use flexbox.

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 a "position: absolute" element with CSS, we use flexbox.

Categories
CSS

How to change the color of an hr element with CSS?

Sometimes, we want to change the color of an hr element with CSS.

In this article, we’ll look at how to change the color of an hr element with CSS.

How to change the color of an hr element with CSS?

To change the color of an hr element with CSS, we set the border property.

For instance, we write

hr {
  display: block;
  height: 1px;
  border: 0;
  border-top: 1px solid #ccc;
  margin: 1em 0;
  padding: 0;
}

to set border-top to the border styles.

We set border to 0 to disable the default border.

Conclusion

To change the color of an hr element with CSS, we set the border property.