我有一个收缩器div,它收缩缠绕在其他几个div上,因此固定器没有固定宽度.持有者内部还有另一个包含文本的div.当文本太多时,它会扩展持有者,因此它不会再收缩.这是我的问题的演示,http://jsfiddle.net/WSbAt/.这是一个照片库页面.
我想可能没有设置支架宽度的方法,因为每行的图像数量是动态的,所以我不能这样做.我可以用jQuery来解决它,但希望有一个css解决方案.
编辑:我试图不指定任何宽度,因为每行的缩略图数量取决于您的窗口大小.
CSS:
#container
{
width:600px; /*only set for demo. will be random on live page*/
border:1px solid black;
text-align:center;
}
#holder
{
display: inline-block;
border:2px solid blue;
}
.thumbnail
{
float:left;
width:100px;
height:100px;
background-color:red;
margin-right:10px;
margin-bottom:10px;
}
.expandedHolder
{
padding:10px;
border:2px solid yellow;
margin-bottom:10px;
margin-right:10px;
}
.fullImage
{
float:left;
width:250px;/*only set for demo. will be random on live page*/
height:200px;
background-color:green;
}
.text
{
float:left;
margin-left:10px;
}
Run Code Online (Sandbox Code Playgroud)
HTML:
<div id="container">
<div id="holder">
<div class="thumbnail"></div>
<div class="thumbnail"></div>
<div class="thumbnail"></div>
<div class="thumbnail"></div>
<div style="clear:both;"></div>
<div class="expandedHolder">
<div class="fullImage"></div>
<div class="text">some text here. some text here. some text here. </div>
<div style="clear:both;"></div>
</div>
<div style="clear:both;"></div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
JoJ*_*oJo -8
我使用 jQuery 来计算文本宽度应该是多少。如果有人好奇,这就是修复我的示例的方法。
var textDiv = $(".text");
textDiv.hide();//hide the text to get holder width without text
var holderWidth = $("#holder").width();
var imageWidth = $(".fullImage").width();
var textWidth = (holderWidth - imageWidth) - 45;
textDiv.css("width", textWidth + "px");
textDiv.show();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10310 次 |
| 最近记录: |