Html Bootstrap 选择菜单样式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37198699/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 13:16:27  来源:igfitidea点击:

Bootstrap select menu styling

htmlcsstwitter-bootstraptwitter-bootstrap-3bootstrap-4

提问by Beginner

I am trying to give my <select>menu a custom color and padding. As of now, It looks like this:

我正在尝试为我的<select>菜单提供自定义颜色和填充。截至目前,它看起来像这样:

enter image description here

在此处输入图片说明

select {
  display: block;
  margin: 0 auto;
  background-color: #2A3F54;
}
<select name="ad_account_selected" onchange="this.form.submit()" class="selectpicker" data-style="btn-primary">
  <option>Mustard</option>
  <option>Ketchup</option>
  <option>Relish</option>
</select>

I want a small gap between the menus and the left side and give it the color of my sidebar ( seen around the menu above ). However, the button remains in the default color and even if I add padding-left: 20pxthe menu is stuck to the left side. Any help?

我希望菜单和左侧之间有一个小间隙,并给它我的侧边栏的颜色(在上面的菜单周围看到)。但是,按钮保持默认颜色,即使我添加padding-left: 20px菜单也卡在左侧。有什么帮助吗?

回答by AndrewL64

Change your data-styleto btn-newlike this:

改变你data-stylebtn-new这样的:

<select data-style="btn-new">
    ....
</select>

And then style that button like this:

然后像这样设置按钮的样式:

.btn-new {
    background-color: #2A3F54;
}

Link to CodePen: http://codepen.io/anon/pen/pyBjrr

CodePen 链接:http://codepen.io/anon/pen/pyBjrr