简体   繁体   English

以最小宽度“变成块”的流体元件

[英]Fluid element that “becomes a block” at minimum width

I have a fixed size element, an image for example, that I want to display alongside an element that contains paragraphs describing it. 我有一个固定大小的元素(例如图像),希望与包含描述该元素的段落的元素一起显示。

The result I want is that the paragraphs will be as wide as they need to be and will shrink if the container gets smaller. 我想要的结果是,段落的宽度将与所需的一样宽,并且如果容器变小,则会缩小。 I want to impose a minimum width on the paragraphs so that when they reach that width and go smaller they will go down to the next line and essentially become a block element while the image will be centered in the line. 我想在段落上加上一个最小宽度,以便当它们达到该宽度并变小时,它们将下降到下一行,并且实际上成为一个块元素,而图像将在该行居中。

I also want this to happen without the use of media queries because each article could have a different sized image. 我也希望在不使用媒体查询的情况下发生这种情况,因为每篇文章的图片大小可能不同。

When I saw go to the next line I mean the paragraphs will appear below the image as if both the image and paragraphs were block elements. 当我看到转到下一行时,我的意思是段落将出现在图像下方,就像图像和段落都是块元素一样。

http://jsfiddle.net/wu9ekLm4/ http://jsfiddle.net/wu9ekLm4/

<article>
    <section class = "media"></section>
    <section class = "info">
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
    </section>
</article>

article {
    border:1px solid black;
    padding:1px 0;
    text-align:center;
}

.media {
    background:orange;
    width:200px;
    height:200px;
    display:inline-block;
}

.info {
    background:yellow;
    padding:10px;
    margin:0;
    display:inline-block;
    vertical-align:top;
    min-width:200px;
}

This fiddle behaves how I want it to except for when you are shrinking the container. 除了缩小容器时,此小提琴的行为与我想要的一样。 The paragraph will go to the next line as soon as the container becomes too small. 一旦容器变得太小,该段将转到下一行。 What I want is for the paragraph to shrink with the container until the paragraph reaches 200px for example. 我想要的是该段落随容器缩小,例如,直到该段落达到200px。 Then it should go to the next line if the container goes any smaller. 如果容器变小,则应转到下一行。

You could do it with some max-width, min-width and calc. 您可以使用一些最大宽度,最小宽度和计算来实现。 Try adding this to your .info class 尝试将其添加到您的.info类中

.info{
    max-width: calc(100% - 250px);
    min-width: 200px;
}

Check it out here: http://jsfiddle.net/wu9ekLm4/1/ 在这里查看: http : //jsfiddle.net/wu9ekLm4/1/

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

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