【发布时间】:2017-09-17 15:12:06
【问题描述】:
我正在使用新的 CSS 网格布局模块来布局一些内容。有几个 8 列宽的段落,我想在 1-3 列中添加一个 3 列宽的 figure,并让它后面的段落流入 figure 右侧的空间.
这可能吗?在非网格世界中,我只需将float:left; 添加到figure。这是我想模仿的行为。
我不知道figure 后面的段落会有多长,所以我不能只说“接下来的 X 段占据第 4-8 列。”
这是CodePen of a stripped-down example。
.grid-container {
display:grid;
grid-template-columns: repeat( 6, 1fr );
width: 50%;
border:1px solid #eee;
margin: 1em auto;
}
.grid-container p {
grid-column: 1 / 6;
}
.grid-container figure {
grid-column: 1/3;
background: rgba( 155, 155, 255, 0.5 );
margin:0;
padding: 1em;
/* Hoping this will be enough to make the paragraphs after the figure flow around it, but apparently not. */
float:left;
}
figure img {
width: 100%;
height:auto;
}
figcaption {
margin-top:0.5em;
}
<html>
<head>
<title>A Floating Grid Item?</title>
</head>
<body>
<div class="grid-container">
<p>Fake Lipsum - is that even a real thing? Lipsi lipsum lipsooo doo.</p>
<figure>
<img src="http://38.media.tumblr.com/3a8dee9aae420a0048907c54ff701fc8/tumblr_n8m6qv50X11r238sko1_500.jpg" alt="A cat">
<figcaption>I want the paragraph(s) below to flow around this box.</figcaption>
</figure>
<p>I want this to flow around the image. Please?</p>
<p>It would be great if this would flow too, if it's not naturally below the image because of the amount of text.</p>
<p>Again, it would be great if this would flow too, if it's not naturally below the image because of the amount of text.</p>
<p>Yet again, it would be great if this would flow too, if it's not naturally below the image because of the amount of text.</p>
</div>
</body>
</html>
【问题讨论】:
-
请发布您尝试过的代码。如果我们可以重现问题,我们可以更有效地帮助您。
-
@Michael_B 刚刚添加了一个精简代码笔的链接。