我有一个包含ul的div,每个li都有一张图片.我把剩下的图片漂浮起来让它们排成一条直线但是一旦它到达div的末尾,它就会包裹起来.我希望这些图片继续向右,隐藏,以便我能够创建一个旋转木马.我的代码如下.
HTML
<div id="container">
<div class="lfbtn"></div>
<ul id="image_container">
<li class="the_image">
<img src="" />
</li>
</ul>
<div class="rtbtn"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS
#container {
width: 900px;
height: 150px;
margin: 10px auto;
}
#image_container {
position: relative;
left: 50px;
list-style-type: none;
width: 700px;
height: 110px;
overflow: hidden;
}
#image_container li {
display: inline-block;
padding: 7px 5px 7px 5px;
float: left;
}
.lfbtn {
background-image: url(../../img/left.gif);
background-repeat: no-repeat;
margin: 10px;
position: relative;
float: left;
top: -12px;
left: 50px;
height: 90px;
width: 25px;
}
.rtbtn {
background-image: url(../../img/right.gif);
background-repeat: no-repeat;
height: 90px;
width: 25px;
margin: 10px;
position: relative;
top: -101px;
left: 795px;
}
Run Code Online (Sandbox Code Playgroud)
提前致谢!
这是一个有效的SSCCE,它具有最低要求的样式:
<!doctype html>
<html lang="en">
<head>
<title>SO question 2472979</title>
<style>
#images {
width: 700px;
height: 100px;
overflow: hidden;
white-space: nowrap;
}
#images li {
list-style-type: none;
display: inline;
}
</style>
</head>
<body>
<div id="images">
<ul>
<li><img src="http://sstatic.net/so/img/logo.png" width="250" height="61"></li>
<li><img src="http://sstatic.net/so/img/logo.png" width="250" height="61"></li>
<li><img src="http://sstatic.net/so/img/logo.png" width="250" height="61"></li>
</ul>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
你看,关键是white-space: nowrap;.如果你想成为一个完全成熟的转盘,只需更换overflow: hidden;的overflow-x: scroll;和overflow-y: hidden;.
更新您的样式以反映这一点:
<div id="container">
<div class="lfbtn"></div>
<div style="width: 700px; overflow: hidden;">
<ul id="image_container" style="width: 1000000px;">
<li class="the_image">
<img src="Untitled-1.gif" />
</li>
</ul>
</div>
<div class="rtbtn"></div>
<br style="clear: both;" />
</div>
Run Code Online (Sandbox Code Playgroud)
您需要设置包裹 UL 的 div 的宽度,然后设置溢出。将 UL 设置为具有一定的宽度,这样即使有很多 LI,它也不会换行。
老实说,我不确定为什么 UL 不会像 DIV 一样处理这个问题,即使 UL 设置为显示块。任何CSS大师都愿意发表评论。
| 归档时间: |
|
| 查看次数: |
10762 次 |
| 最近记录: |