2014-10-01 104 views
2

如何在不使用高度的情況下刪除下拉箭頭並同時在使用Bootstrap 3時隱藏邊框?Bootstrap:刪除下拉字段的邊框和箭頭

這裏是一個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 */ 
} 

編輯:如果我添加到我的無邊界邊境重要的話,它解決了邊界有關的問題:

.no-border { 
    border: 0 !important; 
    box-shadow: none; 
} 

所以後來仍然toggeling定製選擇去除/添加下拉列表,箭頭時,高度變化問題...

+0

試試這個 - http://jsfiddle.net/dfdon4gb/ – Anonymous 2014-10-01 13:13:03

+0

我在你的css中添加了'.custom-select:before {display:none!important;}'來根據你的第一個要求去掉下拉箭頭_ 「我怎樣才能刪除下拉箭頭而不搞亂高度?」_看到這裏 - http://jsfiddle.net/xj3zjLmz/ – Anonymous 2014-10-01 13:27:27

+0

哦,現在看。但是它解決了什麼問題(與我已經擁有的龐克相比,有問題的鏈接)?刪除箭頭的作品(如你的小提琴)。我的問題是增加的高度(如果你在你的小提琴中添加下面的一些內容,並刪除/添加自定義選擇類,或只是檢查我的plunk,你會看到這一點),並在同一時間刪除邊界。 – EricC 2014-10-01 13:33:35

回答

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;,而你給它一個邊框,youself。相反,我只是刪除了它。或者您也可以將其更改爲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屬性。你應該刪除一個。

+1

+0001爲_using'!important'是懶惰的出路._ – Anonymous 2014-10-02 04:33:55

+1

我不會說謊...我以前使用它的方式比我應該有的更多。 ;) – Oberst 2014-10-02 04:36:55

+0

謝謝,@Oberst!我意識到,我不需要無邊界類的下拉字段來滿足我需要的東西(我只需切換自定義選擇類),因此沒有理由使用!重要:)謝謝! – EricC 2014-10-02 07:39:54