html - 之前使用的按钮左右边框如何设置?

标签 html css border

如何仅使用一个 :before 或 :after 以及按钮左侧和右侧 20px 的空间来设置按钮左侧和右侧的边框,我尝试设置的边框请参阅设计附件 - 我想要的。请帮我看看我的截图。提前致谢。

enter image description here

.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>

最佳答案

分别对左行和右行使用 :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>

关于html - 之前使用的按钮左右边框如何设置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55757149/

相关文章:

css - font-face 似乎在 IE8 中不起作用?

html - 3 边上的两个不同宽度的边框

swift - 水平线 (NSBox) 删除背景阴影 - Swift

javascript - 如何通过单击按钮在同一选项卡上打开新网页?

html - 下拉菜单尺寸错误,下拉菜单方向错误

javascript - Stylus 是否支持变量数组?

javascript - 使用 .load() 加载后 Div 保持为空

border - 将边框应用于 CSS 转换透视图像

javascript - Particles.js 仅作为特定部分的背景

javascript - 从客户端 JavaScript 生成的站点生成静态 HTML