Bootstrap:删除下拉字段的边框和箭头

时间:2014-10-01 13:01:20

标签: css twitter-bootstrap twitter-bootstrap-3

当我使用Bootstrap 3时,如何在不弄乱高度的同时删除下拉箭头,同时隐藏边框?

这是plunk,我尝试这样做。隐藏箭头(类自定义选择)基于this blog复制this code

也许最好看一下插件,但这里是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;
}

因此,当使用自定义选择删除/添加下拉箭头时,仍然存在高度变化问题......

1 个答案:

答案 0 :(得分:3)

使用!important实际上只能作为最后的手段使用 在我看来,它是懒惰的出路。

.custom-select课程中,您有两件事

.custom-select {
    background-color: #fff;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    margin: 0 0; /* "0 0 2em" reads as margin-top: 0; margin-left: 0; margin-right: 0; margin-bottom: 2em; (32px) */
    padding: 0;
    position: relative;
    width: 100%;
    z-index: 1;
}

你的保证金是margin: 0 0 2em;,而你自己给了它一个边界。我只是将其删除了。或者您可以将其更改为border: 0;

另外:语义......但是:

<select id="status" class="form-control" ng-class="{'no-border': border}" id="inputEmail3">
    <option>First option</option>
    <option>Another option</option>
    <option>We also have a tird</option>
</select>

您有两个id属性。你应该删除一个。

相关问题