之前使用的按钮如何设置左右边框?
How to set border left and right of button using before?
如何仅使用一个 :before 或 :after 设置按钮的左边框和右边框 20px space 按钮的左右两侧,我尝试设置的边框请参见设计附件 - 我想要的.请通过我的屏幕截图帮助我。提前致谢。
.btn-action {
display: block;
text-align: center;
max-width: 800px;
margin: 0 auto;
background-color: gray;
height: 400px;
-webkit-box-orient: vertical!important;
-webkit-box-direction: normal!important;
-ms-flex-direction: column!important;
flex-direction: column!important;
display: -webkit-box!important;
display: -ms-flexbox!important;
display: flex!important;
-webkit-box-pack: center!important;
-ms-flex-pack: center!important;
justify-content: center!important;
-webkit-box-align: center!important;
-ms-flex-align: center!important;
align-items: center!important;
}
.btn {
display: inline-block;
font-size: 18px;
line-height: 24px;
color: #fff;
padding: 12px 32px;
border: 2px solid #C3A165;
text-transform: uppercase;
font-weight: 500;
background-color: transparent;
border-radius: 0;
text-decoration: none;
transition: 0.3s all;
-webkit-transition: 0.3s all;
-moz-transition: 0.3s all;
-ms-transition: 0.3s all;
}
.btn:hover {
background-color: #C3A165;
color: #fff;
border-color: #C3A165;
}
.btn:before {
content: '';
height: 1px;
background-color: #C3A165;
width: 100%;
position: absolute;
left: 0;
top: 25px;
}
.border {
position: relative;
width: 100%;
}
<section class="btn-action">
<div class="border">
<a href="#" class="btn primary">Get Started</a>
</div>
</section>
由于只允许使用一个伪元素,可以使用box-shadow
来达到效果。但是,必须对位置值进行硬编码。
.btn-action {
display: block;
text-align: center;
max-width: 800px;
margin: 0 auto;
background-color: gray;
height: 400px;
-webkit-box-orient: vertical!important;
-webkit-box-direction: normal!important;
-ms-flex-direction: column!important;
flex-direction: column!important;
display: -webkit-box!important;
display: -ms-flexbox!important;
display: flex!important;
-webkit-box-pack: center!important;
-ms-flex-pack: center!important;
justify-content: center!important;
-webkit-box-align: center!important;
-ms-flex-align: center!important;
align-items: center!important;
overflow: hidden;
}
.btn {
display: inline-block;
font-size: 18px;
line-height: 24px;
color: #fff;
padding: 12px 32px;
border: 2px solid #C3A165;
text-transform: uppercase;
font-weight: 500;
background-color: transparent;
border-radius: 0;
text-decoration: none;
transition: 0.3s all;
-webkit-transition: 0.3s all;
-moz-transition: 0.3s all;
-ms-transition: 0.3s all;
}
.btn:hover {
background-color: #C3A165;
color: #fff;
border-color: #C3A165;
}
.btn:before {
content: '';
height: 1px;
background: linear-gradient(to right,#C3A165 30%,transparent 30% 70%,#C3A165 70% 100%);
width: 100%;
position: absolute;
left: 0px;
top: 25px;
}
.border {
position: relative;
width: 100%;
}
<section class="btn-action">
<div class="border">
<a href="#" class="btn primary">Get Started</a>
</div>
</section>
另一种方法是使用linear-gradient
.btn-action {
display: block;
text-align: center;
max-width: 800px;
margin: 0 auto;
background-color: gray;
height: 400px;
-webkit-box-orient: vertical!important;
-webkit-box-direction: normal!important;
-ms-flex-direction: column!important;
flex-direction: column!important;
display: -webkit-box!important;
display: -ms-flexbox!important;
display: flex!important;
-webkit-box-pack: center!important;
-ms-flex-pack: center!important;
justify-content: center!important;
-webkit-box-align: center!important;
-ms-flex-align: center!important;
align-items: center!important;
overflow: hidden;
}
.btn {
display: inline-block;
font-size: 18px;
line-height: 24px;
color: #fff;
padding: 12px 32px;
border: 2px solid #C3A165;
text-transform: uppercase;
font-weight: 500;
background-color: transparent;
border-radius: 0;
text-decoration: none;
transition: 0.3s all;
-webkit-transition: 0.3s all;
-moz-transition: 0.3s all;
-ms-transition: 0.3s all;
}
.btn:hover {
background-color: #C3A165;
color: #fff;
border-color: #C3A165;
}
.btn:before {
content: '';
height: 1px;
background: linear-gradient(to right,#C3A165 30%,transparent 30% 70%,#C3A165 70% 100%);
width: 100%;
position: absolute;
left: 0px;
top: 25px;
}
.border {
position: relative;
width: 100%;
}
<section class="btn-action">
<div class="border">
<a href="#" class="btn primary">Get Started</a>
</div>
</section>
左行和右行分别使用:before
和:after
。
.btn-action {
display: block;
text-align: center;
max-width: 800px;
margin: 0 auto;
background-color: gray;
height: 400px;
-webkit-box-orient: vertical!important;
-webkit-box-direction: normal!important;
-ms-flex-direction: column!important;
flex-direction: column!important;
display: -webkit-box!important;
display: -ms-flexbox!important;
display: flex!important;
-webkit-box-pack: center!important;
-ms-flex-pack: center!important;
justify-content: center!important;
-webkit-box-align: center!important;
-ms-flex-align: center!important;
align-items: center!important;
overflow: hidden;
}
.btn {
position: relative;
display: inline-block;
font-size: 18px;
line-height: 24px;
color: #fff;
padding: 12px 32px;
border: 2px solid #C3A165;
text-transform: uppercase;
font-weight: 500;
background-color: transparent;
border-radius: 0;
text-decoration: none;
transition: 0.3s all;
-webkit-transition: 0.3s all;
-moz-transition: 0.3s all;
-ms-transition: 0.3s all;
}
.btn:hover {
background-color: #C3A165;
color: #fff;
border-color: #C3A165;
}
.btn:before {
content: '';
height: 1px;
background-color: #C3A165;
width: 1000px;
position: absolute;
left: -1040px;
top: 25px;
}
.btn:after {
content: '';
height: 1px;
background-color: #C3A165;
width: 1000px;
position: absolute;
right: -1040px;
top: 25px;
}
.border {
position: relative;
width: 100%;
}
<section class="btn-action">
<div class="border">
<a href="#" class="btn primary">Get Started</a>
</div>
</section>
应用此 css 可能是您正在寻找的
.btn {
display: inline-block;
font-size: 18px;
line-height: 24px;
color: #fff;
padding: 12px 32px;
border: 2px solid #C3A165;
text-transform: uppercase;
font-weight: 500;
background-color: transparent;
border-radius: 0;
text-decoration: none;
transition: 0.3s all;
-webkit-transition: 0.3s all;
-moz-transition: 0.3s all;
-ms-transition: 0.3s all;
z-index:2;
}
.btn:hover {
background-color: #C3A165;
color: #fff;
border-color: #C3A165;
}
.btn:before {
content: '';
height: 1px;
background-color: #C3A165;
width: 35%;
position: absolute;
left: 0;
top: 25px;
z-index:1;
}
.btn:after {
content: '';
height: 1px;
background-color: #C3A165;
width: 35%;
position: absolute;
right: 0;
top: 25px;
z-index:1;
}
.border {
position: relative;
width: 100%;
}
如何仅使用一个 :before 或 :after 设置按钮的左边框和右边框 20px space 按钮的左右两侧,我尝试设置的边框请参见设计附件 - 我想要的.请通过我的屏幕截图帮助我。提前致谢。
.btn-action {
display: block;
text-align: center;
max-width: 800px;
margin: 0 auto;
background-color: gray;
height: 400px;
-webkit-box-orient: vertical!important;
-webkit-box-direction: normal!important;
-ms-flex-direction: column!important;
flex-direction: column!important;
display: -webkit-box!important;
display: -ms-flexbox!important;
display: flex!important;
-webkit-box-pack: center!important;
-ms-flex-pack: center!important;
justify-content: center!important;
-webkit-box-align: center!important;
-ms-flex-align: center!important;
align-items: center!important;
}
.btn {
display: inline-block;
font-size: 18px;
line-height: 24px;
color: #fff;
padding: 12px 32px;
border: 2px solid #C3A165;
text-transform: uppercase;
font-weight: 500;
background-color: transparent;
border-radius: 0;
text-decoration: none;
transition: 0.3s all;
-webkit-transition: 0.3s all;
-moz-transition: 0.3s all;
-ms-transition: 0.3s all;
}
.btn:hover {
background-color: #C3A165;
color: #fff;
border-color: #C3A165;
}
.btn:before {
content: '';
height: 1px;
background-color: #C3A165;
width: 100%;
position: absolute;
left: 0;
top: 25px;
}
.border {
position: relative;
width: 100%;
}
<section class="btn-action">
<div class="border">
<a href="#" class="btn primary">Get Started</a>
</div>
</section>
由于只允许使用一个伪元素,可以使用box-shadow
来达到效果。但是,必须对位置值进行硬编码。
.btn-action {
display: block;
text-align: center;
max-width: 800px;
margin: 0 auto;
background-color: gray;
height: 400px;
-webkit-box-orient: vertical!important;
-webkit-box-direction: normal!important;
-ms-flex-direction: column!important;
flex-direction: column!important;
display: -webkit-box!important;
display: -ms-flexbox!important;
display: flex!important;
-webkit-box-pack: center!important;
-ms-flex-pack: center!important;
justify-content: center!important;
-webkit-box-align: center!important;
-ms-flex-align: center!important;
align-items: center!important;
overflow: hidden;
}
.btn {
display: inline-block;
font-size: 18px;
line-height: 24px;
color: #fff;
padding: 12px 32px;
border: 2px solid #C3A165;
text-transform: uppercase;
font-weight: 500;
background-color: transparent;
border-radius: 0;
text-decoration: none;
transition: 0.3s all;
-webkit-transition: 0.3s all;
-moz-transition: 0.3s all;
-ms-transition: 0.3s all;
}
.btn:hover {
background-color: #C3A165;
color: #fff;
border-color: #C3A165;
}
.btn:before {
content: '';
height: 1px;
background: linear-gradient(to right,#C3A165 30%,transparent 30% 70%,#C3A165 70% 100%);
width: 100%;
position: absolute;
left: 0px;
top: 25px;
}
.border {
position: relative;
width: 100%;
}
<section class="btn-action">
<div class="border">
<a href="#" class="btn primary">Get Started</a>
</div>
</section>
另一种方法是使用linear-gradient
.btn-action {
display: block;
text-align: center;
max-width: 800px;
margin: 0 auto;
background-color: gray;
height: 400px;
-webkit-box-orient: vertical!important;
-webkit-box-direction: normal!important;
-ms-flex-direction: column!important;
flex-direction: column!important;
display: -webkit-box!important;
display: -ms-flexbox!important;
display: flex!important;
-webkit-box-pack: center!important;
-ms-flex-pack: center!important;
justify-content: center!important;
-webkit-box-align: center!important;
-ms-flex-align: center!important;
align-items: center!important;
overflow: hidden;
}
.btn {
display: inline-block;
font-size: 18px;
line-height: 24px;
color: #fff;
padding: 12px 32px;
border: 2px solid #C3A165;
text-transform: uppercase;
font-weight: 500;
background-color: transparent;
border-radius: 0;
text-decoration: none;
transition: 0.3s all;
-webkit-transition: 0.3s all;
-moz-transition: 0.3s all;
-ms-transition: 0.3s all;
}
.btn:hover {
background-color: #C3A165;
color: #fff;
border-color: #C3A165;
}
.btn:before {
content: '';
height: 1px;
background: linear-gradient(to right,#C3A165 30%,transparent 30% 70%,#C3A165 70% 100%);
width: 100%;
position: absolute;
left: 0px;
top: 25px;
}
.border {
position: relative;
width: 100%;
}
<section class="btn-action">
<div class="border">
<a href="#" class="btn primary">Get Started</a>
</div>
</section>
左行和右行分别使用:before
和:after
。
.btn-action {
display: block;
text-align: center;
max-width: 800px;
margin: 0 auto;
background-color: gray;
height: 400px;
-webkit-box-orient: vertical!important;
-webkit-box-direction: normal!important;
-ms-flex-direction: column!important;
flex-direction: column!important;
display: -webkit-box!important;
display: -ms-flexbox!important;
display: flex!important;
-webkit-box-pack: center!important;
-ms-flex-pack: center!important;
justify-content: center!important;
-webkit-box-align: center!important;
-ms-flex-align: center!important;
align-items: center!important;
overflow: hidden;
}
.btn {
position: relative;
display: inline-block;
font-size: 18px;
line-height: 24px;
color: #fff;
padding: 12px 32px;
border: 2px solid #C3A165;
text-transform: uppercase;
font-weight: 500;
background-color: transparent;
border-radius: 0;
text-decoration: none;
transition: 0.3s all;
-webkit-transition: 0.3s all;
-moz-transition: 0.3s all;
-ms-transition: 0.3s all;
}
.btn:hover {
background-color: #C3A165;
color: #fff;
border-color: #C3A165;
}
.btn:before {
content: '';
height: 1px;
background-color: #C3A165;
width: 1000px;
position: absolute;
left: -1040px;
top: 25px;
}
.btn:after {
content: '';
height: 1px;
background-color: #C3A165;
width: 1000px;
position: absolute;
right: -1040px;
top: 25px;
}
.border {
position: relative;
width: 100%;
}
<section class="btn-action">
<div class="border">
<a href="#" class="btn primary">Get Started</a>
</div>
</section>
应用此 css 可能是您正在寻找的
.btn {
display: inline-block;
font-size: 18px;
line-height: 24px;
color: #fff;
padding: 12px 32px;
border: 2px solid #C3A165;
text-transform: uppercase;
font-weight: 500;
background-color: transparent;
border-radius: 0;
text-decoration: none;
transition: 0.3s all;
-webkit-transition: 0.3s all;
-moz-transition: 0.3s all;
-ms-transition: 0.3s all;
z-index:2;
}
.btn:hover {
background-color: #C3A165;
color: #fff;
border-color: #C3A165;
}
.btn:before {
content: '';
height: 1px;
background-color: #C3A165;
width: 35%;
position: absolute;
left: 0;
top: 25px;
z-index:1;
}
.btn:after {
content: '';
height: 1px;
background-color: #C3A165;
width: 35%;
position: absolute;
right: 0;
top: 25px;
z-index:1;
}
.border {
position: relative;
width: 100%;
}