javascript - css div宽度根据图像宽度

标签 javascript html css

<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。我怎样才能做到这一点?图片宽度和高度是动态的。

最佳答案

只有在图像容器 div 上设置 float: left; 才有可能,如下所示:

<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>

关于javascript - css div宽度根据图像宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50384258/

相关文章:

javascript - 在 Amcharts 中增加饼图的大小

jquery - 在其中一列中包含 slider

html - 如何解决 bootstrap4 中的轮播问题

css - 带有拆分器的 HTML、CSS 布局问题

php - 检查二十一点的赢家

javascript - jquery ajax - 调整另一个页面的 iframe 的大小

javascript - 我如何将数据传递到对象数组

html - 在 CS-Cart v4.03 中对齐两个 block

html - 选择器 li + li 麻烦

html - Jenkins 显示空白 html 而不是报告