如何制作半透明的select2?

时间:2015-01-20 10:44:15

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

我使用以下CSS应用按钮看起来是半透明的 -

.navbar-toggle {
    position:relative;
    float:left;
    display:block;
    padding: 9px 10px;
    background: rgba(0, 0, 0, 0.2);
    background-image: none;
    border: 0 none;
    top:0px;
    -webkit-border-radius: 2px;
       -moz-border-radius: 2px;
            border-radius: 2px;
    outline: 0;
    opacity: 1;
    -webkit-transition: all .45s;
       -moz-transition: all .45s;
            transition: all .45s;
            float: left;
}

但是当我将它应用于select2组件时,它并不会使它看起来透明。看起来像select2应用自己的主题并覆盖我的工作。选择2也supports themes,但详细文档is missing

如何将select2样式更改为与按钮相同的方式(请参阅jsfiddle demo

2 个答案:

答案 0 :(得分:2)

我试试这个:http://jsfiddle.net/crxepevy/1/它的工作正常吗?

<强> JS

var data = [{
    id: 0,
    text: 'enhancement'
}, {
    id: 1,
    text: 'bug'
}, {
    id: 2,
    text: 'duplicate'
}, {
    id: 3,
    text: 'invalid'
}, {
    id: 4,
    text: 'wontfix'
}];


$(".js-example-data-array").select2({
    data: data,
    theme: "themes-dark"
});

<强> CSS

<body>
<nav class="mainmenu">
    <div class="container">
        <div class="navbar-right">
            <select class="js-example-data-array themes-dark"></select>
            <button type="button" class="navbar-toggle"><font color="white"><i class="fa fa-search fa-lg fa-fw"></i></font>
            </button>
            <button type="button" class="navbar-toggle"><font color="white"><i class="fa fa-play fa-lg fa-fw"></i></font>
            </button>
            <button type="button" class="navbar-toggle"><font color="white"><i class="fa fa-vk fa-lg fa-fw"></i></font>
            </button>
        </div>
    </div>
</nav>

<强> CSS

html {
background:#505D6E url(http://habrastorage.org/files/a01/ca3/b36/a01ca3b360454f539b4275a3ad274c87.jpg) no-repeat center center fixed;
min-height:100%;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover; }

body {
    background:transparent;
    min-height:100%;
    -webkit-font-smoothing: antialiased;
    -webkit-overflow-scrolling: touch;
    line-height: 1.5em;
    font-size:14px;
    font-family: Helvetica, Arial, sans-serif;
    color:#fff;
    color:rgba(255,255,255,.8);
    font-weight: normal;
}

.mainmenu { z-index: 999999; width:100%;  padding: 30px 0 0 0;}
@media (min-width: 768px) {
    .mainmenu { position: fixed; }
}

.navbar-toggle, .themes-dark, .select2-container--themes-dark {
    position:relative;
    display:block;
    padding: 9px 10px;
    background: rgba(0, 0, 0, 0.2);
    background-image: none;
    border: 0 none;
    top:0px;
    -webkit-border-radius: 2px;
       -moz-border-radius: 2px;
            border-radius: 2px;
    outline: 0;
    opacity: 1;
    -webkit-transition: all .45s;
       -moz-transition: all .45s;
            transition: all .45s;
            float: left;
}
select {
    height: 39px !important;
    width: 100px;
    margin: 8px 20px !important;
}

span.select2.select2-container.select2-container--themes-dark.select2-container--below, .select2-container--themes-dark {
margin-right: 20px !important;
margin-top: 8px;
height: 39px;
}

答案 1 :(得分:2)

Fiddle

将select2放入容器中。

<div class="nav-sel">SELECT2</div>

有了它,你可以使它看起来像一个带有css的引导2 nav元素:

<强> CSS

.nav-sel {
   margin-top: 9px;
   margin-right: 15px;
   float: left;
}

现在为select2: 添加了大量透明背景和半透明背景。

<强> CSS

.select2-container {
    background: transparent;
}

.select2-container .select2-selection {
    border: none;
    height: 40px;
    background: rgba(0, 0, 0, 0.2);
}

.select2-container .select2-selection span:first-child {
    color: white;
}

.select2-results ul li {
    color: white;
}

.select2-dropdown {
    background: rgba(0, 0, 0, 0.2);
}
.select2-search input:first-child {
    background: transparent;
}