javascript - Bootstrap 按钮底部边框宽度为百分比

标签 javascript jquery html css twitter-bootstrap

我有一个 Bootstrap 时尚的自定义按钮:

.btn
{
  background-color: #DB631E;
  border-color: #DB631E;
}
.btn-custom {
  color: #D0D4D2;
  background-color: #8F101A;
  border-color: #8F101A;
  width: 170px;
  height:120px;
  border-style: solid;
  border-bottom-color:#1252cf;
  border-bottom-width: 5px;
  font-size: 22px;
  padding: 47px 22px;  
}
.btn-custom:focus,
.btn-custom.focus {
  color: #D0D4D2;
  background-color: #8F101A;
  border-color: #8F101A;
}
.btn-custom:hover {
  color: #D0D4D2;
  background-color: #8F101A;
  border-color: #8F101A;
  width: 200px;
  height:150px;
  border-style: solid;
  border-bottom-color:#1252cf;
  border-bottom-width: 5px;
}
.btn-custom:active,
.btn-custom.active,
.open > .dropdown-toggle.btn-custom {
  color: #D0D4D2;
  background-color: #8F101A;
  border-color: #8F101A;
}
.btn-custom:active:hover,
.btn-custom.active:hover,
.open > .dropdown-toggle.btn-custom:hover,
.btn-custom:active:focus,
.btn-custom.active:focus,
.open > .dropdown-toggle.btn-custom:focus,
.btn-custom:active.focus,
.btn-custom.active.focus,
.open > .dropdown-toggle.btn-custom.focus {
  color: #D0D4D2;
  background-color: #8F101A;
  border-color: #8F101A;
}
.btn-custom:active,
.btn-custom.active,
.open > .dropdown-toggle.btn-custom {
  background-image: none;
}
.btn-custom.disabled,
.btn-custom[disabled],
fieldset[disabled] .btn-custom,
.btn-custom.disabled:hover,
.btn-custom[disabled]:hover,
fieldset[disabled] .btn-custom:hover,
.btn-custom.disabled:focus,
.btn-custom[disabled]:focus,
fieldset[disabled] .btn-custom:focus,
.btn-custom.disabled.focus,
.btn-custom[disabled].focus,
fieldset[disabled] .btn-custom.focus,
.btn-custom.disabled:active,
.btn-custom[disabled]:active,
fieldset[disabled] .btn-custom:active,
.btn-custom.disabled.active,
.btn-custom[disabled].active,
fieldset[disabled] .btn-custom.active {
  background-color: #8F101A;
  border-color: #8F101A;
}
.btn-custom .badge {
  color: #5bc0de;
  background-color: #fff;
}
<button type="button" class="btn btn-custom">Default</button>

这是我的 jsfiddle .

问题:

如何使蓝色底边框占总底边框宽度的 70% 并居中?
目前它与总底边框的宽度相同。

我的 Bootstrap 版本是

Bootstrap v3.3.5

最佳答案

不要使用边框,而是使用绝对定位的伪元素:

.btn
{
  background-color: #DB631E;
  border-color: #DB631E;
}
.btn-custom {
  position: relative;
  color: #D0D4D2;
  background-color: #8F101A;
  border-color: #8F101A;
  width: 170px;
  height:120px;
  font-size: 22px;
  padding: 47px 22px;  
}
.btn-custom:after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 15%;
  right: 15%;
  height: 5px;
  background: #1252cf;
}
.btn-custom:focus,
.btn-custom.focus {
  color: #D0D4D2;
  background-color: #8F101A;
  border-color: #8F101A;
}
.btn-custom:hover {
  color: #D0D4D2;
  background-color: #8F101A;
  border-color: #8F101A;
  width: 200px;
  height:150px;
}
.btn-custom:active,
.btn-custom.active,
.open > .dropdown-toggle.btn-custom {
  color: #D0D4D2;
  background-color: #8F101A;
  border-color: #8F101A;
}
.btn-custom:active:hover,
.btn-custom.active:hover,
.open > .dropdown-toggle.btn-custom:hover,
.btn-custom:active:focus,
.btn-custom.active:focus,
.open > .dropdown-toggle.btn-custom:focus,
.btn-custom:active.focus,
.btn-custom.active.focus,
.open > .dropdown-toggle.btn-custom.focus {
  color: #D0D4D2;
  background-color: #8F101A;
  border-color: #8F101A;
}
.btn-custom:active,
.btn-custom.active,
.open > .dropdown-toggle.btn-custom {
  background-image: none;
}
.btn-custom.disabled,
.btn-custom[disabled],
fieldset[disabled] .btn-custom,
.btn-custom.disabled:hover,
.btn-custom[disabled]:hover,
fieldset[disabled] .btn-custom:hover,
.btn-custom.disabled:focus,
.btn-custom[disabled]:focus,
fieldset[disabled] .btn-custom:focus,
.btn-custom.disabled.focus,
.btn-custom[disabled].focus,
fieldset[disabled] .btn-custom.focus,
.btn-custom.disabled:active,
.btn-custom[disabled]:active,
fieldset[disabled] .btn-custom:active,
.btn-custom.disabled.active,
.btn-custom[disabled].active,
fieldset[disabled] .btn-custom.active {
  background-color: #8F101A;
  border-color: #8F101A;
}
.btn-custom .badge {
  color: #5bc0de;
  background-color: #fff;
}
<button type="button" class="btn btn-custom">Default</button>

(注意:我没有费心去改变悬停颜色;你当然必须用伪元素的背景颜色来替换边框颜色。)

关于javascript - Bootstrap 按钮底部边框宽度为百分比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41832719/

相关文章:

javascript - 将 HTML 字符串传递给 JavaScript 函数

javascript - 如何在选中复选框时将字段设置为必填字段

javascript - 使用 BootStrap 和 Angular - 动态选择输入

javascript - 我无法在数据列表中获取输入的值?

javascript - 如何在类型为 NUMBER 的 Chrome INPUT 中显示 X(清除)?

javascript - 用动画填充颜色 SVG 路径

javascript - 调整窗口导航栏文本大小时移动

javascript - 在javascript中从平面数组构建树数组

jquery - asp.net ajax不发送数据

javascript - 带箭头的 slider 导航(HTML、CSS、JAVASCRIPT)