我想为border-color
输入的text
设置半蓝色和橙色。
我尝试使用渐变但它不起作用。
我的代码问题是什么?
.search {
width: 550px;
height: 50px;
margin-left: 350px;
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%);
font-size: 20px;
text-align: center;
transition: all 0.2s linear;
}
.search:hover,
.search:focus {
border: #4cbea5 solid;
}

<div>
<form method="post">
<input type="Search" class="search" placeholder="Search">
</form>
</div>
&#13;
答案 0 :(得分:5)
您需要在border-image
内指定切片值,如下所示:
.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>
您可以阅读有关border-image
的更多信息顺便说一句,您不能将border-radius
与border-image
一起使用,但您可以使用多个背景并调整background-clip
来实现相同的目标。这也将允许您具有悬停行为:
.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>
答案 1 :(得分:1)
要在您正在寻找的边框上获得半橙色,半蓝色渐变,请使用border-image-slice
属性并在搜索类上应用蓝色和橙色边框图像。您可以在悬停时查看干净的边框渐变和平滑过渡。
希望,它有所帮助。
.search{
width: 550px;
height: 50px;
margin-left: 350px;
border-radius: 20px;
outline: none;
margin-top: 70px;
border: solid;
border-image: linear-gradient(to right, #4cbea5 0%, orange 100%);
border-image-slice: 1;
font-size: 20px;
text-align: center;
transition: all 0.2s linear;
}
.search:hover , .search:focus{
border: #4cbea5 solid;
}
&#13;
<div>
<form method="post">
<input type="Search" class="search" placeholder="Search">
</form>
</div>
&#13;
答案 2 :(得分:0)
这个渐变线上有一个拼写错误,它应该是这样的:
border-image: linear-gradient(to right, rgb(254, 113, 53), rgb(55, 154, 214)) 1 20%;
请参阅运行演示
.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>