有一個帶邊框的按鈕:3px solid #E82929; 什么技術可以用來添加像照片中的額外線條?

.btn {
position: relative;
width: 362px;
height: 71px;
color: #FFFFFF;
background-color: #000000;
border: 3px solid #E82929;
font-family: 'Flamenco';
font-style: normal;
font-weight: 400;
font-size: 24px;
line-height: 25px;
text-align: center;
}
<button class="btn">Забронировать столик</button>
uj5u.com熱心網友回復:
使用漸變
.btn {
position: relative;
padding: 20px 50px;
color: #FFFFFF;
border: 3px solid #E82929;
font-family: 'Flamenco';
font-style: normal;
font-weight: 400;
font-size: 24px;
line-height: 25px;
text-align: center;
background: linear-gradient(90deg, #E82929 40px,#0000 0 calc(100% - 40px), #E82929 0) 50%/100% 3px no-repeat;
background-color: #000000;
}
<button class="btn">Забронировать столик</button>
uj5u.com熱心網友回復:
您不需要額外的標記,因為它可以使用::before和::after偽元素來完成。
假設左右兩行的寬度30px和左右填充應為10px,您可以將其添加到現有的 CSS 中:
.btn {
position: relative;
width: 362px;
height: 71px;
color: #FFFFFF;
background-color: #000000;
border: 3px solid #E82929;
font-family: 'Flamenco';
font-style: normal;
font-weight: 400;
font-size: 24px;
line-height: 25px;
text-align: center;
}
/* extra code comes here */
.btn {
padding: 0 40px; /* 30px line width 10px padding */
}
.btn::before,
.btn::after {
background-color: #E82929; /* border color */
content: ''; /* content is mandatory for the element to show up */
height: 3px; /* 3px border width */
position: absolute;
top: 50%; /* 50% from the top */
transform: translateY(-50%); /* half of its height back to the top */
width: 30px; /* 30px line width */
}
.btn::before {
left: 0;
}
.btn::after {
right: 0;
}
<button class="btn">Забронировать столик</button>
根據您的需要更改寬度和填充。
它的作用:它在左右添加沒有文本內容的::before和偽元素,并將它們垂直居中放置。::after
如果您對細節有任何疑問,請隨時提問。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/470434.html
上一篇:如何檢測滑鼠釋放
