老师,为什么在导航栏的.dropdown-menu的宽度为什么不是两个浮动的子元素宽度的和?
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>bootstrap作业</title> <link href="css/bootstrap.min.css" rel="stylesheet"> <link rel="stylesheet" href="css.css"> </head> <body> <!-- 导航栏 --> <section class="pageHead"> <div class="container"> <nav class="navbar navbar-default"> <div class="container-fluid"> <!-- Brand and toggle get grouped for better mobile display --> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="#">Brand</a> </div> <!-- Collect the nav links, forms, and other content for toggling --> <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> <ul class="nav navbar-nav"> <li class="active"><a href="#">首页 <span class="sr-only">(current)</span></a></li> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">生日 <span class="caret"></span></a> <ul class="dropdown-menu dmOne"> <div> <li><a href="#">关系</a></li> <li role="separator" class="divider"></li> <li><a href="#">朋友</a></li> <li><a href="#">爱人</a></li> <li><a href="#">姐妹</a></li> </div> <div> <li><a href="#">风味</a></li> <li role="separator" class="divider"></li> <li><a href="#">巧克力</a></li> <li><a href="#">水果</a></li> </div> </ul> </li> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">婚礼 <span class="caret"></span></a> <ul class="dropdown-menu"> <div> <li><a href="#">关系</a></li> <li role="separator" class="divider"></li> <li><a href="#">朋友</a></li> <li><a href="#">爱人</a></li> <li><a href="#">姐妹</a></li> </div> <div> <li><a href="#">风味</a></li> <li role="separator" class="divider"></li> <li><a href="#">巧克力</a></li> <li><a href="#">水果</a></li> </div> <div> <li><a href="#">主旋律</a></li> <li role="separator" class="divider"></li> <li><a href="#">心型</a></li> <li><a href="#">卡通</a></li> </div> </ul> </li> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">专用 <span class="caret"></span></a> <ul class="dropdown-menu dmOne"> <div> <li><a href="#">关系</a></li> <li role="separator" class="divider"></li> <li><a href="#">朋友</a></li> <li><a href="#">爱人</a></li> <li><a href="#">姐妹</a></li> </div> <div> <li><a href="#">商铺</a></li> <li role="separator" class="divider"></li> <li><a href="#">巧克力</a></li> <li><a href="#">水果</a></li> </div> </ul> </li> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">生日 <span class="caret"></span></a> <ul class="dropdown-menu dmOne"> <div> <li><a href="#">关系</a></li> <li role="separator" class="divider"></li> <li><a href="#">朋友</a></li> <li><a href="#">爱人</a></li> <li><a href="#">姐妹</a></li> </div> <div> <li><a href="#">风味</a></li> <li role="separator" class="divider"></li> <li><a href="#">巧克力</a></li> <li><a href="#">水果</a></li> </div> </ul> </li> </ul> <ul class="nav navbar-nav navbar-right"> <li><a href="#">Link</a></li> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a> <ul class="dropdown-menu"> <li><a href="#">Action</a></li> <li><a href="#">Another action</a></li> <li><a href="#">Something else here</a></li> <li role="separator" class="divider"></li> <li><a href="#">Separated link</a></li> </ul> </li> </ul> </div><!-- /.navbar-collapse --> </div><!-- /.container-fluid --> </nav> </div> </section> <script src="js/jquery-3.1.1.js"></script> <script src="js/bootstrap.min.js"></script> </body> </html>
css
.pageHead{ height: 100px; background-color: #5D4B33; } /*导航头部的下拉菜单样式*/ .dropdown-menu div {float: left;margin:20px 20px;width:190px;} .dropdown-menu div li:first-child a{font-size: 16px;color:#f07818;} .dropdown-menu div li a{color:grey;text-decoration: none;} .dropdown-menu div li a:hover{color:#f07818;}
0
收起
正在回答 回答被采纳积分+1
2回答
响应式开发与常用框架 2018
- 参与学习 人
- 提交作业 2198 份
- 解答问题 5012 个
如果你有web端基础,既想进阶,又想进军移动端开发,那就来吧,我们专题为你带来的课程有HTML5、CSS3、移动基础、响应式、bootstrap、less等,让你在前端道路上畅通无阻!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星