CSS Gradient Border Not Showing Correctly
I want to set half blue and orange for border-color of text input. I tried using a gradient but it doesn't work. what is my code problem?
Solution 1:
You need to specify the slice value inside border-image
like this :
.search {
width: 550px;
height: 50px;
border-radius: 20px;
outline: none;
margin-top: 70px;
border: solid;
border-image: linear-gradient(to right, rgb(254, 113, 53) 50%, rgb(55, 154, 214) 50%) 2;
font-size: 20px;
text-align: center;
}
<form method="post">
<input type="Search" class="search" placeholder="Search">
</form>
You can read more about border-image
By the way, you cannot use border-radius
with border-image
but you can achive the same using multiple background and by adjusting background-clip
. This will also allow you to have the hover behavior:
.search {
width: 550px;
height: 50px;
border-radius: 20px;
outline: none;
margin-top: 70px;
border: 2px solid transparent;
background:
linear-gradient(#fff,#fff) content-box,
linear-gradient(to right, rgb(254, 113, 53) 50%, rgb(55, 154, 214) 50%) border-box;
font-size: 20px;
text-align: center;
transition: all 0.2s linear;
}
.search:hover,
.search:focus {
border-color:#4cbea5;
}
<form method="post">
<input type="Search" class="search" placeholder="Search">
</form>
Related: Border Gradient with Border Radius
Solution 2:
You had a typo on this gradient line, it should be like this:
border-image: linear-gradient(to right, rgb(254, 113, 53), rgb(55, 154, 214)) 1 20%;
See running demo:
.search {
width: 550px;
height: 50px;
margin-left: 50px; /* adjust as needed */
border-radius: 20px;
outline: none;
margin-top: 70px;
border: solid 5px; /* made thicker for illustration purposes only */
border-image: linear-gradient(to right, rgb(254, 113, 53), rgb(55, 154, 214)) 1 20%;
font-size: 20px;
text-align: center;
}
.search:hover,
.search:focus {
border: #4cbea5 solid;
}
<div>
<form method="post">
<input type="Search" class="search" placeholder="Search">
</form>
</div>
Post a Comment for "CSS Gradient Border Not Showing Correctly"