我有一个 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/