我想在不同的浏览器上使下拉列表的样式相同, 首先,我删除了箭头的默认样式
select {
appearance: none;
-moz-appearance: none;
-webkit-appearance: none;
}
select::-ms-expand {
display: none;
}
.Default{
padding:0px 0px;
background: url(http://cdn1.iconfinder.com/data/icons/cc_mono_icon_set/blacks/16x16/br_down.png) no-repeat right center;
}
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<div class="col-lg-12">
Method 1:
<div >
<select class=" Default">
<option value="1">Test long text ...text text text</option>
<option value="2">Test 2</option>
<option value="3">Test 3</option>
</select>
</div>
</div>
<br/>
<div class="col-lg-6">
Method 2
<div class="input-group">
<select class="form-control">
<option value="1">Test long text ...text text text</option>
<option value="2">Test 2</option>
<option value="3">Test 3</option>
</select>
<span class="input-group-btn">
<button class="btn btn-default" type="button">▼</button>
</span>
</div><!-- /input-group -->
</div>
我的问题,
在方法1中,文本变为背景,文本是否可以在不使用填充的情况下变为背景? ,我不想使用填充,因为我想要语言RTL的左右填充相同,LTR建议。
在方法2中,我可以制作JavaScript,当点击按钮时,列表会下拉吗?
在浏览器上更改选择行为很容易吗? 在IE上,有灰色悬停,蓝色选择
在Google Chrome上,有蓝色悬停并选择
答案 0 :(得分:1)
我认为这可能会对你有所帮助。这是自定义选择选项,您可以根据您的要求更改外观:
<强> HTML 强>
<div class="select_holder">
<div class="select">
<table>
<tr>
<th id="selector"><span class="opt_selected">Select your option</span><span class="arrow"> > </span></th>
</tr>
<tr>
<th class="disabled">Select your option</th>
</tr>
<tr>
<td>Option 1</td>
</tr>
<tr>
<td>Option 2</td>
</tr>
<tr>
<td>Option 3</td>
</tr>
<tr>
<td>Option 4</td>
</tr>
</table>
</div>
<br>
<input type="hidden" name="option" id="option"/> <!-- To store value in Database -->
</div>
<强> CSS 强>
.select_holder {
display: block;
margin-top: 100px;
width:auto;
height:auto;
text-align: center;
background: #fff;
}
.select {
display:inline-block;
width:200px;
height:40px;
overflow:hidden;
}
.select_show {
height:auto;
}
table {
width:100%;
text-align:left;
margin:0px;
font-family:Calibri;
border-radius:3px;
border-collapse:collapse;
}
.arrow {
display:inline-block;
-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);
-o-transform: rotate(90deg);
-ms-transform: rotate(90deg);
transform: rotate(90deg);
float:right;
position:relative;
line-height:20px;
font-size:25px;
}
tr {
width:100%;
margin:0px;
height:40px;
border-bottom:1px solid #ddd;
cursor:pointer;
}
tr:nth-child(1) {
background:#ddd;
}
td {
margin:0px;
background:#eee;
transition: all 5 ease-in-out;
}
td, th {
padding:0px 10px;
}
td:hover {
background:#ccc;
-webkit-transition: all 0.2s ease-in-out;
-moz-transition: all 0.2s ease-in-out;
-o-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
}
.disabled {
background:#eee;
font-weight:normal;
color:grey;
}
#selector {
border-radius:3px;
-webkit-border-radius:3px;
-moz-border-radius:3px;}
<强> JS / JQuery的强>
$(document).ready(function(){
$("tr").click(function () {
$(".select").toggleClass("select_show");
});
$("td").click(function () {
var curOption = this.innerHTML;
$("#selector").html(curOption);
document.getElementById("option").setAttribute("value", curOption);
});
});
<强> PHP 强>
$selectedOption = $_Post['option']; /* Value from the input type="hidden" */