只编码了几个月,因此感谢您的帮助:)
我设计了一个客户标题,其徽标向左浮动,号召性用语 (CTA) 按钮向右浮动,我想将它们转换为单击时的下拉菜单。我正在借用 Bootstrap 的 Dropdown 组件。我遇到了几个问题:
- 如何打开按钮下方的下拉菜单?:我已将徽标图标变成了下拉菜单,所有链接都以 Bootstrap 设置为默认设置的预期颜色显示。在 Google Chrome 中单击徽标时,菜单会直接显示在图标下方(这是我想要的位置)。但是当在 Mozilla 中单击徽标时,下拉菜单会在图标左侧打开并将图标移到上方。我已经尝试过“pull-right”类,但这并没有将下拉菜单放在图标下方,而是放在它的右侧。可以这么说,我如何创建一个“下拉”类并确保它可以跨浏览器工作?
- 如何为同一标题中的另一个按钮复制该下拉菜单?:对于 CTA 按钮,我应用了与向左浮动的图标的下拉菜单完全相同的 div 结构,因此理论上它应该工作相同。但是,除非我将鼠标悬停在选项上,否则不会显示下拉菜单选项。看起来它在某处继承了一个属性,告诉它将字体颜色设为白色并覆盖 Bootstrap 的属性。问题是我的类在任何地方都没有任何“颜色:白色/#ffffff”,所以我不确定它是从哪里继承该属性的。
- 对于 CTA 按钮,下拉菜单也会在左侧而不是底部打开。当我将代码粘贴到任何父 div 之外(作为独立的)时,菜单也会向左打开并将按钮向右移动,而不是向底部打开。
HTML:
<div id="header-container">
<div id="header-wrapper">
<div id="header-left">
<div class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
<img src="" />
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li><a href="#">Option 1</a></li>
<li><a href="#">Option 2</a></li>
<li><a href="#">Option 3</a></li>
<li><a href="#">Option 4</a></li>
</ul>
</div>
</div>
<div id="header-right">
<div class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
Take Pledge
<b class="caret"></b>
</a>
<ul class="dropdown-menu" role="menu">
<li><a href="#">Option 1</a></li>
<li><a href="#">Option 2</a></li>
<li><a href="#">Option 3</a></li>
<li><a href="#">Option 4</a></li>
</ul>
</div>
</div>
</div>
</div>
CSS:
#header-container {
/*overflow: auto;*/
width: 100%;
background-color: #231F20;
height: 50px;
}
#header-wrapper {
margin-left: auto;
margin-right: auto;
width: 80%;
min-width: 1000px;
max-width: 1300px;
overflow: auto;
}
#header-left {
float: left;
margin: 5px 0 0 0;
}
#header-right {
float: right;
margin: 15px 0 0 0;
}
.dropup,
.dropdown {
position: relative;
}
.dropdown-toggle {
*margin-bottom: -3px;
}
.dropdown-toggle:active,
.open .dropdown-toggle {
outline: 0;
}
.caret {
display: inline-block;
width: 0;
height: 0;
vertical-align: top;
border-top: 4px solid red;
border-right: 4px solid transparent;
border-left: 4px solid transparent;
content: "";
}
.dropdown .caret {
margin-top: 8px;
margin-left: 2px;
}
.dropdown-menu {
position: relative;
top: 100%;
left: 0;
z-index: 1000;
display: none;
float: left;
min-width: 160px;
padding: 5px 0;
margin: 2px 0 0;
list-style: none;
background-color: #ffffff;
border: 1px solid #ccc;
border: 1px solid rgba(0, 0, 0, 0.2);
*border-right-width: 2px;
*border-bottom-width: 2px;
-webkit-border-radius: 6px;
-moz-border-radius: 6px;
border-radius: 6px;
-webkit-box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
-moz-box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
-webkit-background-clip: padding-box;
-moz-background-clip: padding;
background-clip: padding-box;
}
.dropdown-menu.pull-right {
right: 0;
left: auto;
}
.dropdown-menu .divider {
*width: 100%;
height: 1px;
margin: 9px 1px;
*margin: -5px 0 5px;
overflow: hidden;
background-color: #e5e5e5;
border-bottom: 1px solid #ffffff;
}
.dropdown-menu > li > a {
display: block;
padding: 3px 20px;
clear: both;
font-weight: normal;
line-height: 20px;
color: #333333;
white-space: nowrap;
}
.dropdown-menu > li > a:hover,
.dropdown-menu > li > a:focus,
.dropdown-submenu:hover > a,
.dropdown-submenu:focus > a {
color: #ffffff;
text-decoration: none;
background-color: #0081c2;
background-image: -moz-linear-gradient(top, #0088cc, #0077b3);
background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#0088cc), to(#0077b3));
background-image: -webkit-linear-gradient(top, #0088cc, #0077b3);
background-image: -o-linear-gradient(top, #0088cc, #0077b3);
background-image: linear-gradient(to bottom, #0088cc, #0077b3);
background-repeat: repeat-x;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff0088cc', endColorstr='#ff0077b3', GradientType=0);
}
.dropdown-menu > .active > a,
.dropdown-menu > .active > a:hover,
.dropdown-menu > .active > a:focus {
color: #ffffff;
text-decoration: none;
background-color: #0081c2;
background-image: -moz-linear-gradient(top, #0088cc, #0077b3);
background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#0088cc), to(#0077b3));
background-image: -webkit-linear-gradient(top, #0088cc, #0077b3);
background-image: -o-linear-gradient(top, #0088cc, #0077b3);
background-image: linear-gradient(to bottom, #0088cc, #0077b3);
background-repeat: repeat-x;
outline: 0;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff0088cc', endColorstr='#ff0077b3', GradientType=0);
}
.dropdown-menu > .disabled > a,
.dropdown-menu > .disabled > a:hover,
.dropdown-menu > .disabled > a:focus {
color: #999999;
}
.dropdown-menu > .disabled > a:hover,
.dropdown-menu > .disabled > a:focus {
text-decoration: none;
cursor: default;
background-color: transparent;
background-image: none;
filter: progid:DXImageTransform.Microsoft.gradient(enabled=false);