CSS div 内的中心选择下拉菜单
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11062727/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Center Select drop down inside div
提问by SparrwHawk
I'm struggling to centre a select drop-down inside a div. I've tried both margin: auto; and text-align: centre; to no avail
我正在努力将一个选择下拉列表放在一个 div 中。我已经尝试了 margin: auto; 和文本对齐:居中;无济于事
Here is my fiddle http://jsfiddle.net/U8Kja/
这是我的小提琴http://jsfiddle.net/U8Kja/
Can anyone figure this out? Am I missing something?
任何人都可以弄清楚吗?我错过了什么吗?
Thanks
谢谢
回答by Brendan Martin
Add this to the bottom of your fiddle.
将此添加到小提琴的底部。
select {
display: block;
margin: 0 auto;
}
The margin auto on right and left side will center a block element within the parent div.
右侧和左侧的边距 auto 将使父 div 内的块元素居中。
回答by Priyank Patel
You had set text-align:centre
你已经设置 text-align:centre
It should be text-align:center
它应该是 text-align:center
回答by odiszapc
You should use
你应该使用
text-align: center
The error is in text-align: centre
错误在 text-align: center
回答by Joshue
Try this:
尝试这个:
.center {
text-align: center;
/*These options are for the div to be visible in the example, the important is the first*/
border:1px solid black;
width: auto;
height: 50px;
}
.cmb {
display: block;
margin: 0 auto;
}
<div class="center">
<select class="cmb">
<option value=1>Option 1</option>
<option value=2>Option 2</option>
<option value=3>Option 3</option>
</select>
<div>
回答by Mithhu
Try this
尝试这个
text-align-last: center