【问题标题】:Keep responsive inline-blocks positioned with responsive text word wrap使用响应式文本自动换行保持响应式内联块的位置
【发布时间】:2013-09-22 19:43:37
【问题描述】:

我有两个内联块(图像然后是内容),我想像这样水平放置:

尽管当容器变小时,图像和内容块不再保持内联。我希望容器不断增加高度来处理内容文本的换行,如下所示:

如果容器达到限制,元素将移动并居中,但始终尽量不要在两侧创建尽可能少的空白,如下所示:

我有一些几乎可以工作的 HTML:Example

<div style="margin:20px; height:auto; box-shadow: 2px 2px 1px #999999;   border-style:solid; border-width:1px; border-color:#dddddd; padding:4px; background-color:white; " >
        <div style="width:100%;" >
            <div style="display:inline-block; padding-top:4px; height:100px; width:100px;">
                <img src='http://placekitten.com/100/100'>
            </div>  
            <div style="display:inline-block;  vertical-align:top; padding-top:4px; min-width:70%; max-width:70%;">
                <h2 style=" font-size:12px;">About</h2>
                <p style="font-size:10px;">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum is simply dummy text of the printing and typesetting industry. </p>
            </div>
        </div>
</div>

【问题讨论】:

  • 您的小提琴表明您将 70% 的 max-width 分配给内部 div。
  • 删除最大宽度只会让问题变得更糟:)
  • 我想我无法理解你在做什么
  • 只是为了创建图像中显示的效果

标签: jquery html css responsive-design


【解决方案1】:

只需将text-align: center 添加到外部块。内部 div 将继承这一点,因此您还应该将 text-align: left 添加到文本块中。

http://jsfiddle.net/tXke7/1/

【讨论】:

  • 如果增加窗口大小,容器会失去定位
  • 你这是什么意思?尝试删除最小宽度。
【解决方案2】:

看看我的小提琴。我想这就是你所追求的:

http://jsfiddle.net/tXke7/3/

.wrap {
    border: 1px solid #ddd;
    margin: 20px;
    padding: 15px;
}

.wrap img {
    float: left;
    margin-right: 10px;
}

.wrap p {
    margin: 0;
    overflow: hidden;
}

@media(max-width: 500px) {
    .wrap img {
        float: none;
        display: block;
        margin-left: auto;
        margin-right: auto;
        margin-bottom: 10px;
    }
    .wrap p {
        text-align: center;
    }
}

【讨论】:

  • 仅当您想使用百分比时。但它会影响图像大小,在较小的分辨率下会缩小,在较高的分辨率下会放大。这就是你想要的吗?
猜你喜欢
  • 1970-01-01
  • 2013-07-06
  • 1970-01-01
  • 1970-01-01
  • 2016-11-29
  • 2020-11-12
  • 2013-08-16
  • 2013-09-07
  • 2017-12-18
相关资源
最近更新 更多