【发布时间】:2014-10-02 09:02:19
【问题描述】:
当我使用 Bootstrap 3 时,如何在不弄乱高度的情况下删除下拉箭头并同时隐藏边框?
这是一个plunk,我尝试这样做。隐藏箭头(自定义选择类)基于this blog 复制this code。
也许最好检查一下 plunk,但这里是 CSS:
.no-border {
border: 0;
box-shadow: none;
}
.custom-select {
background-color: #fff;
border: 1px solid #ccc;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
margin: 0 0 2em;
padding: 0;
position: relative;
width: 100%;
z-index: 1;
}
.custom-select:hover {
border-color: #999;
}
.custom-select:before {
color: #333;
display: block;
font-family: 'FontAwesome';
font-size: 1em;
height: 100%;
line-height: 2.5em;
padding: 0 0.625em;
position: absolute;
top: 0;
right: 0;
text-align: center;
width: 1em;
z-index: -1;
}
.custom-select select {
background-color: transparent;
border: 0 none;
box-shadow: none;
color: #333;
display: block;
font-size: 100%;
line-height: normal;
margin: 0;
padding: .5em;
width: 100%;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
}
.custom-select select::-ms-expand {
display: none; /* to ie 10 */
}
.custom-select select:focus {
outline: none;
}
/* little trick for custom select elements in mozilla firefox 17/06/2014 @rodrigoludgero */
/* pseudo class https://developer.mozilla.org/en-US/docs/Web/CSS/:any */
:-moz-any(.custom-select):before {
background-color: #fff; /* this is necessary for overcome the caret default browser */
pointer-events: none; /* https://developer.mozilla.org/en-US/docs/Web/CSS/pointer-events */
z-index: 1; /* this is necessary for overcome the pseudo element */
}
编辑:如果我将 !important 添加到我的无边框边框,那么它解决了与边框相关的问题:
.no-border {
border: 0 !important;
box-shadow: none;
}
因此,当切换自定义选择以删除/添加下拉箭头时,高度变化问题仍然存在......
【问题讨论】:
-
试试这个 - jsfiddle.net/dfdon4gb
-
我在您的 css 中添加了
.custom-select:before{display:none !important;},以根据您的第一个要求删除下拉箭头 “如何在不弄乱高度的情况下删除下拉箭头?”看这里 - jsfiddle.net/xj3zjLmz -
哦,现在看。但它解决了什么问题(与我已经拥有的 plunk 相比,有问题的链接)?移除箭头是有效的(就像你的小提琴一样)。我的问题是增加的高度(如果你在小提琴下面添加一些内容并删除/添加自定义选择类,或者只是查看我的 plunk,你会看到这个)和同时删除边框。
-
如果我在我的无边界边界定义中改用“!重要”,那么它解决了边界问题。然后添加的高度问题仍然存在......
-
@MaryMelody 你的小提琴在里面使用了很棒的字体。 OP不是。如果是这种情况,您可以通过从选择中删除
fa-caret-down类来轻松删除箭头。
标签: css twitter-bootstrap twitter-bootstrap-3