【发布时间】:2017-06-23 07:43:43
【问题描述】:
如何使整个浮动面板的宽度与其中的最大文本宽度匹配? 它应该是这样的:
面板 html 是:
.pannel{
width: auto;
float: left;
margin: 10px 10px 10px 0px;
border: #88F 4px solid;
padding: 10px;
background-color: rgb(240,240,255);
border-radius: 8px;
font-size: 150%;
}
.pannel>a>div
{
width: auto;
text-align: center;
border: #AAF 1px solid;
margin: 0 auto 0;
overflow: hidden;
border-radius: 9px;
margin: 3px;
}
<div class="pannel">
<a href="someref1">
<div>
<img src="http://www.w3schools.com/css/img_fjords.jpg">
<div>Some text</div>
</div>
</a>
<a href="someref2">
<div>
<img src="https://camo.mybb.com/e01de90be6012adc1b1701dba899491a9348ae79/687474703a2f2f7777772e6a71756572797363726970742e6e65742f696d616765732f53696d706c6573742d526573706f6e736976652d6a51756572792d496d6167652d4c69676874626f782d506c7567696e2d73696d706c652d6c69676874626f782e6a7067">
<div>Some text2</div>
</div>
</a>
<a href="someref3">
<div>
<img src="http://keenthemes.com/preview/metronic/theme/assets/global/plugins/jcrop/demos/demo_files/image1.jpg">
<div>Text with a maximum width</div>
</div>
</a>
</div>
如您所见,面板尺寸与最大图像尺寸匹配,但我希望图像适合元素的宽度。
【问题讨论】:
-
你想设置一些文本 div 整个内容和图像也显示所有内容区域?
-
图像的宽度应与最大文本大小宽度相同