【问题标题】:Wrapping text to the width of an image that isn't set将文本换行到未设置的图像宽度
【发布时间】:2010-12-22 01:09:08
【问题描述】:

我会保持简单。我有一个使用以下 css 的图像: .img-right { 浮动:对; 边距:0px 0px 10px 20px; }

然后我有一个位于图像下方的标题,它是以下 css: .img-右 p { 边距顶部:5px; 填充顶部:5px; 字体大小:11px; 颜色:#858d93; }

我想让段落标签的宽度适应我正在使用的图像的大小。使用该类的图像宽度不同,因此有人告诉我,实现这一目标的唯一方法是通过 jQuery。任何人都可以协助完成这项工作吗?

谢谢,节日快乐!

【问题讨论】:

    标签: jquery css image html width


    【解决方案1】:

    好的,试试这样的,HTML:

    <div class="img-wrapper">
    <img src="foo.jpg" />
    <div class="caption">This is my caption</div>
    </div>
    

    CSS:

    .img-wrapper{width:auto; min-width:100px; float:right; margin:0px 0px 10px 20px;}
    .img-wrapper img{min-width:100px;}
    .img-wrapper .caption{width:auto; min-width:100px; margin-top: 5px; padding-top: 5px; font-size: 11px; color: #858d93; }
    

    【讨论】:

    • 我最终使用了 Jared Williams 创建的 jQuery 代码:
    猜你喜欢
    • 2012-04-18
    • 1970-01-01
    • 1970-01-01
    • 2018-10-19
    • 2015-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-01
    相关资源
    最近更新 更多