How to create "Banner" with css?

Asked

Viewed 3,819 times

2

inserir a descrição da imagem aqui

I’d like to produce a Banner similar to the photo using css.

I tried using characters UTF-8 and the result was almost perfect, but I would like to do with css to avoid some problems of reponsibility.

HTML

<div style='background-color:black;'>
      <p><span style='float:left; color: white;'>&#9654;</span>
           <span style='color: white'>Texto no interior do banner</span>
          <span style='float:rigth; color:white;'>&#9664;</span>
       </p>
</div>

Upshot

▶ Text inside the banner

How could I do with Css ?

  • Will this text be dynamic, or exchanged frequently? If not, you can simplify using a . png one even a . gif

  • @Micaelferreira the text will be dynamic...

2 answers

2

I made a version using two linear-gradiente as background-image, so you don’t need to pseudos-elementos and saves some lines of code. If you want to do it with pseudo-elements I suggest you use transforme:skwe()

Concept of the idea:

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

Code referring to the above images:

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  background-image: linear-gradient(yellow, red);
}


.box {
  height: 50px;
  line-height: 50px;
  text-align: center;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 2rem;
  color: #fff;

  background-image: 
                    linear-gradient(-45deg, transparent 20%, black 20%, black 80%, transparent 80%), 
                    linear-gradient(45deg, transparent 20%, black 20%, black 80%, transparent 80%);

  background-origin: border-box;
  box-sizing: border-box;
  border-left: 2rem transparent solid;
  border-right: 2rem transparent solid;
  padding: 0px 6rem;
}
<div class="box">Meu Texto</div>

2


with css it is possible to define different orders to create triangular shapes.

<div class="banner">Texto</div>

.banner {
  position: relative;
  margin-left: 25px;
  padding: 0 25px;
  background-color: blue;
  height: 50px;
  display: inline-block;
  line-height: 50px;
  font-size: 32px;
  color: #fff;
}

.banner:before {
  content: '';
  position: absolute;
  top: 0; left: -25px;
  border-left: 26px solid transparent;
  border-top: 25px solid blue;
  border-bottom: 26px solid blue;
  width: 0;
}

.banner:after {
  content: '';
  position: absolute;
  top: 0; right: -25px;
  border-right: 25px solid transparent;
  border-top: 25px solid blue;
  border-bottom: 26px solid blue;
  width: 0;
}
  • 1

    That there brother ... Beauty !

Browser other questions tagged

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