【发布时间】:2012-01-10 22:15:52
【问题描述】:
我有一个 div,其标题文本向右对齐。接下来是一个无序列表,其列表项是我向左浮动的图像。
当您水平扩展浏览器时,随着可用空间的增加,图像会水平对齐(每行更多)。
但是,文本保持向右对齐,并且在新图像无法水平对齐的那一刻,文本与最右边的图像之间存在未对齐。
我想将文本与最右边的图像对齐,而不是与父 div 对齐。这可能吗?
<div class="container">
<span>Text goes here.</span>
<ol>
<li><img src="http://t3.gstatic.com/images?q=tbn:ANd9GcTsOZfG8edaAiTfWbHx1a26hJIhUbZPbLzCH2BHakudlSTtI5SZOSEyvFGJpw" /></li>
<li><img src="http://t3.gstatic.com/images?q=tbn:ANd9GcTsOZfG8edaAiTfWbHx1a26hJIhUbZPbLzCH2BHakudlSTtI5SZOSEyvFGJpw" /></li>
<li><img src="http://t3.gstatic.com/images?q=tbn:ANd9GcTsOZfG8edaAiTfWbHx1a26hJIhUbZPbLzCH2BHakudlSTtI5SZOSEyvFGJpw" /></li>
<li><img src="http://t3.gstatic.com/images?q=tbn:ANd9GcTsOZfG8edaAiTfWbHx1a26hJIhUbZPbLzCH2BHakudlSTtI5SZOSEyvFGJpw" /></li>
<li><img src="http://t3.gstatic.com/images?q=tbn:ANd9GcTsOZfG8edaAiTfWbHx1a26hJIhUbZPbLzCH2BHakudlSTtI5SZOSEyvFGJpw" /></li>
<li><img src="http://t3.gstatic.com/images?q=tbn:ANd9GcTsOZfG8edaAiTfWbHx1a26hJIhUbZPbLzCH2BHakudlSTtI5SZOSEyvFGJpw" /></li>
<li><img src="http://t3.gstatic.com/images?q=tbn:ANd9GcTsOZfG8edaAiTfWbHx1a26hJIhUbZPbLzCH2BHakudlSTtI5SZOSEyvFGJpw" /></li>
<li><img src="http://t3.gstatic.com/images?q=tbn:ANd9GcTsOZfG8edaAiTfWbHx1a26hJIhUbZPbLzCH2BHakudlSTtI5SZOSEyvFGJpw" /></li>
<li><img src="http://t3.gstatic.com/images?q=tbn:ANd9GcTsOZfG8edaAiTfWbHx1a26hJIhUbZPbLzCH2BHakudlSTtI5SZOSEyvFGJpw" /></li>
</ol>
</div>
CSS:
.container {
width: auto;
}
.container span {
width: 100%;
float: right;
text-align: right;
clear: both;
}
.container li img {
float: left;
margin: 0 10px 10px 0;
}
【问题讨论】:
-
jsfiddle.net/jcDqW 请注意,当您展开浏览器时,即使图像仍“卡”在下一行“等待”更多水平空间,文本仍保持向右对齐。我希望文本只能到达第一行最远的图像。