您可以尝试使用绝对定位。看起来您正在创建一个购物车布局,所以我假设您有一个相当结构化的页面作为开始。
请参阅小提琴演示:http: //jsfiddle.net/audetwebdesign/rC59T/
您的 HTML 基本上是这样的:
<div calss="panel-wrap">
<ul class="rank">
<li class="rank-1">
<img ... />
<p>1</p>
</li>
<li class="rank-2">
<img ... />
<p>2</p>
</li>
<li class="rank-3">
<img ... />
<p>3</p>
</li>
</ul>
</div>
对于 CSS:
.panel-wrap {
width: 460px;
}
如果要添加背景图像等,这.panel-wrap
很有用。
ul.rank {
list-style: none outside none;
padding: 0;
margin: 0;
position: relative; /* this will force the li to be positioned with respect
to this block level container */
border: 1px solid gray;
height: 200px;
}
ul.rank li {
width: 150px;
top: 0; /* pin top and bottom so that the li fills in the height
of the parent container */
bottom: 0;
border: 1px solid red;
position: absolute;
}
ul.rank img {
width: 150px;
xheight: 90px; /* Careful not to adjust both width and height which could
distort your images */
}
ul.rank p {
border: 1px dotted blue;
text-align:center;
position: absolute;
bottom: 10px;
left: 0; /* pin left and right so the p fills in the
width of the li... */
right: 0;
margin: 0;
}
诀窍是以均匀间隔的增量调整每个列表项的左偏移量:
.rank-3 {
top: 0;
left: 0;
}
.rank-1 {
top: 0;
left: 160px;
}
.rank-2 {
top: 0;
left: 320px;
}
大优势
您可以做的是使用 JavaScript/jQuery 动态设置左侧偏移,并创建一个交互式页面,用户可以在其中单击按钮并滚动浏览一系列目录项。