Create button with border and gradient text

Asked

Viewed 1,702 times

0

I need to make a button with the border and the text color gradient, but the button also has border-Radius. I have tried several forms here, but I did not succeed. What is the best way to make this button?

The button is this:

inserir a descrição da imagem aqui

What I have so far:

https://jsfiddle.net/jsalves/ca0ezhdx/

  • Hello friend, Welcome to the OS, can you put what you have done so far? https://answall.com/help/mcve

  • Oops! I forgot that detail. https://jsfiddle.net/jsalves/ca0ezhdx/

3 answers

0


This comes very close to what you need:

.botao {
  display: inline-block;
  padding: 12px 18px;
  border-radius: 10px;
  text-decoration: none;
  font-family: Sans-serif;
  font-weight: bold;
  overflow: hidden;
  position: relative;
  margin: 10px;
  z-index: 0;
}
.botao span {
  text-transform: uppercase;
  font-size: 16px;
  position: relative;
  z-index: 0;
  background: linear-gradient(to right, #4382c9, #5bafe4); 
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  color: transparent;
}
.botao:before {
  content: '';
  background: linear-gradient(to right, #4382c9, #5bafe4); 
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: -2;
}
.botao:after {
  content: '';
  background: #fff;
  top: 2px;
  bottom: 2px;
  left: 2px;
  right: 2px;
  position: absolute;
  border-radius: 8px;
  z-index: -1;
}
<a href="" class="botao"><span>Conheça</span></a>

  • Performing the tests here, it worked right, but when applying the code, it doesn’t work. I’ll see what’s going on here. Thanks for the help! D

  • Apparently the problem I have here is with the z-index of pseudo-Elements

  • In this case, to apply a z-index to the button you will need to encapsulate the text in another tag, in the example I put in a span]

  • Now it was! The button is encapsulated in a div with background, when I took the background of that div the button was right. Now encapsulating the button text worked as well. Thanks for the help! :D

  • I used your solution as a base, but as I predicted when I had to do the gradients, I had problems with the text gradient in IE 10

0

Well first of all, put gradient on edges is a bit difficult,

EDITED:

made this small example of a button the result is almost identical:

a {
  text-decoration: none;
  font-family:sans-serif;
  
}
input{
  background:none;
  border: none;
}
.outer {
    padding: 2px;
    text-align: center;
    border-radius: 8px;
    background: linear-gradient(to right, #04a6f3, #0072ff);
    width: 150px;
}

.inner {
     display: block;
    border-radius: 6px;
    font-size: 18px;
    font-weight: 700;
    width: 100%;
    background-color: #fff;
    color: #0095ff;
    height: 100%;
    padding-top: 10px;
    padding-bottom: 10px;
}
<div class="outer">
     <a href="#" class="inner">CONHEÇA</a>
</div>

  • It was very good, but I need it to be a <a> and not an input :/

  • @John edited the answer to <a> I think it looks good :)!

  • The color of the text is not gradient right?! The rest was very good!

  • No, but in the text is already easier, if you want to edit the answer

  • 1

    Got it right here! Thanks for the help :D

-2

.MeuBotao {
  padding: 10px;
  border-radius: 4px;
  font-weight: 600;
  background-image: linear-gradient(to bottom, white, purple);
}
.MeuBotao h3 {
  font-size: 40px;
  background: -webkit-linear-gradient(#eee, #333);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
<button class="MeuBotao" type="button"><h3>Conheça</h3></button>

Sources of study:

Ready buddy! There you are! Now it’s just for your style! I hope I’ve helped

  • You used the gradients but the final result was totally different from the proposed

  • @Diegomarques I only used one example!

Browser other questions tagged

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