[英]How to create a overlapping border with different colors and widths / heights on a input element?
带有渐变的边框图像是您所需要的:
input { border:2px solid; padding:10px; background:pink; }.one { border-image:linear-gradient(to right, red 80%,blue 0) 2; }.two { border-image:linear-gradient(to bottom,red 70%,blue 0) 2; }
<input type="text" class="one"> <input type="text" class="two">
您可以使用:after 和:before 来覆盖剩余 20% 的边框。
<div><input value="Text"/></div>
CSS:
input {
padding:20px;
border: 5px solid lightblue;
border-bottom: 5px solid gray;
position:relative;
display:block;
}
div:before {
content:' ';
width:5px;
height: 14px;
background:gray;
position:absolute;
display:block;
bottom:0;
left:0;
z-index:999;
}
div:after {
content:' ';
width:5px;
height: 14px;
background:gray;
position:absolute;
display:block;
bottom:0;
right:0;
z-index:999;
}
div {position: relative;width:fit-content;}
我可能会设置包装元素的样式并在其上添加伪元素。
https://codepen.io/slackday/pen/wvwQOvq
<html>
<head>
<title>How to create a overlapping border with different colors and widths / heights on a input element?</title>
</head>
<style>
body {
margin: 0;
padding: 0;
}
.site {
height: 100vh;
width: 100vw;
display: flex;
justify-content: center;
align-items: center;
}
.input-wrapper {
position: relative;
}
.input-wrapper::before,
.input-wrapper::after {
height: 20%; /* adjust height of how much it should overlap */
width: 1px; /* same width as your input border */
position: absolute;
bottom: 0;
z-index: 1;
content: '';
background-color: #ccc; /** same color as bottom border */
}
.input-wrapper::before {
left: 0;
}
.input-wrapper::after {
right: 0;
}
input {
border: solid 1px aqua;
border-bottom: solid 1px #ccc;
position: relative; /* to position psuedo elements ::before, ::after */
padding: 1rem;
font-size: 16px;
line-height: 1;
}
input:focus {
outline: none;
}
</style>
<body>
<main class="site">
<div class="input-wrapper">
<input type="text" value="text" placeholder="Aorta" />
</div>
</main>
</body>
</html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.