[英]Picture element WebP flexing
Background: Bootstrap 3 way of laying out 8 images in a row 背景: Bootstrap 3连续布置8张图像的方式
I now know how to flex 3 images: 我现在知道如何显示3张图片:
body { display: flex; flex-wrap: wrap; justify-content: space-around; align-content: space-around; align-items: flex-start; } img { width: 30%; order: 0; flex: 0 1 auto; align-self: auto; }
<img src="https://placehold.it/1024x768" /> <img src="https://placehold.it/1024x768" /> <img src="https://placehold.it/1024x768" />
But I want to introduce smaller WebP alternative images and I think you do that with the picture element . 但是我想介绍较小的WebP替代图像,我认为您可以使用picture元素来实现 。
body { display: flex; flex-wrap: wrap; justify-content: space-around; align-content: space-around; align-items: flex-start; } picture { width: 30%; order: 0; flex: 0 1 auto; align-self: auto; }
<picture> <source srcset="http://s.natalian.org/2015-12-12/1024x768.webp" type="image/webp" /> <img src="https://placehold.it/1024x768" /> </picture> <picture> <source srcset="http://s.natalian.org/2015-12-12/1024x768.webp" type="image/webp" /> <img src="https://placehold.it/1024x768" /> </picture> <picture> <source srcset="http://s.natalian.org/2015-12-12/1024x768.webp" type="image/webp" /> <img src="https://placehold.it/1024x768" /> </picture>
However, I can't figure out how to make the CSS format the PICTUREs 3 abreast like they do with IMG. 但是,我不知道如何使PICTUREs 3像CSS一样使用CSS格式。 What am I missing?
我想念什么?
When you create a flex container only the child elements become flex items. 创建flex容器时,只有子元素成为flex项目。 Descendants beyond the children do not become flex items and flex properties don't apply to them.
子代以外的子代不会成为弹性项目,弹性属性也不适用于它们。
In your first example , body
is the flex container and img
is the flex item. 在第一个示例中 ,
body
是flex容器, img
是flex项。
In your second example, however, body
is the flex container, picture
is the flex item, and img
is, well, nothing special in terms of flex. 但是,在第二个示例中,
body
是flex容器, picture
是flex项,而img
在flex方面没什么特别的。 It's a normal inline element. 这是一个普通的内联元素。
You'll need to make picture
a (nested) flex container in order to apply flex properties to the image elements. 您需要将
picture
设为(嵌套的)flex容器,以便将flex属性应用于图像元素。 But in your case, this may not be necessary . 但是对于您而言, 这可能不是必需的 。
Also note that the picture
element is not universally supported yet (see caniuse.com ). 另请注意,
picture
元素尚未得到普遍支持(请参见caniuse.com )。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.