How to make a gradient at the ends of a line, with CSS?

Asked

Viewed 768 times

5

Probably this may be a repeated question, but since I don’t know the name of the effect I can’t find anything on it, the effect I want to do on the edge is exactly the same as the image below:

inserir a descrição da imagem aqui

  • How can I do that effect?
  • What’s his name?
  • You mean that line with the fine tips, a little degrade?

  • Yes, at the little thin ends fading slowly, and in the middle at the normal thickness

2 answers

4


I would make a div with fixed size, leaving the backgound linear gradient:

HTML

<div class="linha"></div>

CSS

.linha { 
    margin: 10px 0;
    height: 2px;
    background: black;
    background: -webkit-gradient(linear, 0 0, 100% 0, from(white), to(white), color-stop(50%, black));
}

Example:

.linha {
  margin: 10px 0;
  height: 2px;
  background: black;
  background: -webkit-gradient(linear, 0 0, 100% 0, from(white), to(white), color-stop(50%, black));
}
<div class="linha"></div>

  • 1

    It is not on the edges as I imagined, but it served me very well , thank you.

4

Complementing, I would do so mine hr:

hr{
    border: 0;
    height: 1px;
    background-image: linear-gradient(to right, transparent, black, transparent);
}
<hr>

I believe it is simpler this solution, now just choose the desired color and put where this the black

  • 1

    +1 both solutions are on the right track, but this seems to me more standard.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.