繁体   English   中英

css div宽度根据图像宽度

[英]css div width according to image width

 <div style="position: relative"> <img src="http://52.66.90.164/Show_barcode"> <div stule="position: absolute;top:100%;"> <p style="float:left;width: 33.33%">Hello world my name is Rushabh Shah.</p> <p style="float:left;width: 33.33%">Hello world my name is Rushabh Shah.</p> <p style="float:left;width: 33.33%">Hello world my name is Rushabh Shah.</p> </div> </div> 

我希望图像的33.33%不是父div。 我该如何实现? 图像的宽度和高度是动态的。

尝试以下操作:

将img标签放入div中,并将图像宽度设置为div

 <div style="position: relative"> <div style="position: absolute;top:100%;width:285px"> <img src="http://52.66.90.164/Show_barcode" style="display:block"> <p style="float:left;width: 33.33%">Hello world my name is Rushabh Shah.</p> <p style="float:left;width: 33.33%">Hello world my name is Rushabh Shah.</p> <p style="float:left;width: 33.33%">Hello world my name is Rushabh Shah.</p> </div> </div> 

仅当您可以设置float: left;时才可能float: left; 在图像容器div ,如下所示:

 <div style="position:relative; float:left;"> <img src="http://via.placeholder.com/650x150"> <div style="position:absolute; width:100%; left:0; top:100%;"> <p style="float:left;width: 33.33%">Hello world my name is Rushabh Shah.</p> <p style="float:left;width: 33.33%">Hello world my name is Rushabh Shah.</p> <p style="float:left;width: 33.33%">Hello world my name is Rushabh Shah.</p> </div> </div> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM