我有一个ul列表,它位于bootstrap网格元素中:
<div class="row">
<div class="col-sm-8">
<div id="playlist-wrapper">
<ul id="playlist">
<li>
...
</li>
<li>
...
</li>
<li>
...
</li>
</ul>
</div>
</div>
</div>
如果那些li元素大于col-sm-8的宽度,它们将跳转到下一行。
我想添加一个水平滚动条,这样所有的li元素都在同一个li中,只有col-sm-8的宽度可见,并且可以水平滚动它们。
我尝试为包装器设置一个固定的高度(因此只能看到一行)并添加overflow-y hidden和white-space nowrap但它不起作用:
#playlist-wrapper{
height: 150px;
overflow-y: hidden;
overflow: auto;
Tried also with overflow-x: scroll;
white-space: nowrap;
}
也尝试过:
#playlist-wrapper ul {
white-space: nowrap;
}
其余的css不会影响溢出,只是为了使它成为水平列表和一些文本/颜色属性。
ul#playlist {
list-style-type: none;
margin: 0;
padding: 0;
background-color: black;
}
ul#playlist li {
float: left;
margin-left: 10px;
margin-top: 20px;
}
ul#playlist li p {
text-align: center;
color: white;
font-weight: bold;
text-decoration: none;
}
使用那个css我有一个垂直滚动条。是否有可能以某种方式有一个水平滚动条?
答案 0 :(得分:1)
我认为你需要这样的东西
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
#playlist-wrapper ul li{
height: 50px;
overflow-y: hidden;
overflow: auto;
white-space: nowrap;
}
#playlist-wrapper{
height: 150px;
width:150px;
overflow-y: hidden;
overflow: auto;
white-space: nowrap;
}
</style>
</head>
<body>
<div class="row">
<div class="col-sm-2">
<div id="playlist-wrapper">
<ul id="playlist">
<li>Fabian Eduardo Sierra Pineda</li>
<li>Fabian Eduardo Sierra Pineda</li>
<li>Fabian Eduardo Sierra Pineda</li>
</ul>
</div>
</div>
</div>
</body>
</html>