官术网_书友最值得收藏!

Using flex and media queries for horizontal layout

To achieve the first goal, we can apply the following properties to the list container:

.related-items {
display:flex;
flex-wrap: wrap;
list-style: none;
}

This nearly gets us there. However, it's a little messy: there is no consistency in item width, and depending on the screen width, the list will end up being both horizontal and vertical (as shown in the following image), when we wanted it to be either horizontal or vertical:

Related content thumbnails with a flexible container: incorrect alignment

We can fix this with a media query. Let's say we have four items. When displayed horizontally, we'll want each to take up 25 percent of the available space. We'll use a width of 50rem as our breakpoint:

@media (min-width:50rem) {
figure {
margin:40px;
}

.related-thumb {
flex-basis:25%;
flex-wrap:wrap;
}

.related-thumb amp-img, .related-thumb figcaption{
flex-basis:100%
}

.related-items li {
width:25%;
}
}
Horizontal thumbnail layout on larger screen (tablet device in landscape orientation)

This will give us a 4x1 horizontal list of items on wider screens and a 1x4 vertical list on small screens.

We can push this even further. On mid-sized screens, let's go for a 2x2 grid. To achieve this, we'll add another media query that matches screens between our default and our large screen media queries (full code at /ch3/related-flex-media.html):

    @media (min-width:35rem) and (max-width:50rem) {
...
.related-items li {
width:50%;
}
}
主站蜘蛛池模板: 化德县| 阿拉善右旗| 巴塘县| 奉化市| 衡南县| 五华县| 天柱县| 芒康县| 石门县| 曲阜市| 微山县| 罗山县| 井冈山市| 信阳市| 东台市| 南和县| 台前县| 南宫市| 孙吴县| 白银市| 胶州市| 白玉县| 安平县| 江油市| 呼玛县| 东宁县| 重庆市| 搜索| 天台县| 台山市| 宜君县| 鄂伦春自治旗| 鹤庆县| 东安县| 胶南市| 辽阳县| 五河县| 辽宁省| 两当县| 苍溪县| 双城市|