bootstrap中下拉菜单中如果有很多项的话怎么让下拉菜单出现滚动条而不是整个页面出现滚动条?
如果,怎么让下拉列表出现滚动框而不是页面滚动呢?
代码如下:
<!DOCTYPE html>
<html lang="zh-cn">
<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></title>
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/index.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="http://cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="http://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<div class="row">
<div class="col-xs-4">
<div class="dropdown text-center">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-expanded="true" style="border:none;">
类别
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">类别1</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">类别2</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">类别3</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">类别4</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">类别1</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">类别2</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">类别3</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">类别4</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">类别1</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">类别2</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">类别3</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">类别4</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">类别1</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">类别2</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">类别3</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">类别4</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">类别1</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">类别2</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">类别3</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">类别4</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">类别1</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">类别2</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">类别3</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">类别4</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">类别1</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">类别2</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">类别3</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">类别4</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">类别1</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">类别2</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">类别3</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">类别4</a></li>
</ul>
</div>
</div>
</div>
<!------------------------------------------------->
<div class="row">
<div class="col-xs-12">
<button type="button" class="btn btn-default" style="width:100%;border:none;">加载更多...</button>
</div>
</div>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="http://cdn.bootcss.com/jquery/1.11.2/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
是在UL 里面加上max-height=“数字” 么?还是在样式里面加呢?试了一下并没有效果
@133088515 java的,非前端,据经验,加最大高度,设置滚动条是否显示, 放到div里面
但是手机上面貌似不支持
max-height
谢啦,刚才已经解决啦,跟你回答的解决方法一样~!
回复
恩,全栈工程师为您服务~,哈哈