【问题标题】:Shrink-wrap two elements- left one on one line, the second wrapped to fit remaining width收缩包装两个元素 - 一个在一行上,第二个包装以适应剩余宽度
【发布时间】:2014-03-27 06:31:36
【问题描述】:

我想组织我的文章,使标题适合一个框,几乎与缩进一样 在发布者下方.. 如果我将最大宽度设置为 300 像素,它会起作用;但我不希望定义宽度 - 它应该适合剩余的宽度。

-----------------BODY------------------
|                                     |
||-------------CONTAINER-------------||
||-PUPLISHER-----TITLE-fits remaining||
|||____________||width, text wrapped|||
||              |___________________|||
||___________________________________||
|_____________________________________|

如果我将最大宽度设置为 300 像素,它会起作用;但我不希望定义宽度 - 它应该适合剩余的宽度。

 <div>
     <span style="display: inline-block;">
    content: one line no wrap, Stretches to fit text length;
     </span>
     <div style=" display: inline-block; max-width: 300px; " >
    content: block box, Stretches to fit remaining width, longer text is wrapped.
     </div>
 </div>

【问题讨论】:

    标签: html css shrinkwrap


    【解决方案1】:

    你可以在jQuery的帮助下实现如下,

    $(function () {
    var wrapperWidth = $('.wrapper').width();
    $('.wrapper').children('.outer').each(function () {
        var mainWidth = $(this).children('.main').width();
        var sutraction = wrapperWidth - mainWidth - 4;
        // 4 is value of total border width i.e. blue and green border can be adjusted as per ur need
        $(this).children('.sub').css('width', sutraction);
    });
    

    });

    http://jsfiddle.net/49Jpt/6/

    希望对你有帮助!

    【讨论】:

    • 这是 50 篇最新文章的循环。它如何适用于堆叠在一起的所有几个“.wrapper”。 “.wrapper”的数组?我宁愿不使用 jQuery
    • 如果你想分别计算每个项目的间距,你可以使用jsfiddle.net/49Jpt/6这样的每个函数你在找这个吗?
    • 我已经编辑了上面的答案,因此对其他人也有用:)
    猜你喜欢
    • 2016-04-13
    • 2012-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-12
    • 2021-11-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多