使用CSS flexbox可以简化这个吗?

时间:2014-07-11 02:20:52

标签: css flexbox

我有使用常规CSS制作的照片和缩略图的设置,我想知道:可以使用flexbox进行简化吗?

http://jsfiddle.net/frank_o/n9pM2/10/

HTML:

<div class="one">
    <h1>Can this:</h1>
    <div class="wrapper">
        <div class="photos">
            <img src="http://placekitten.com/200/400" />
        </div>
        <div class="thumbnails">
            <img src="http://placekitten.com/70/70" />
            <img src="http://placekitten.com/70/70" />
        </div>
    </div>
</div>

CSS:

.one .photos {
    border: 2px solid lightgrey;
    float: left;
    width: calc(100% - 80px);
}
.one .photos img {
    width: 100%;
}
.one .thumbnails {
    width: 70px;
    float: right;
    border: 2px solid red;
}
.one .thumbnails img {
    display: block;
    margin-bottom: 5px;
}

2 个答案:

答案 0 :(得分:0)

https://codepen.io/polinq/pen/gObLoZx

请在这里看看。那是您要找的东西吗? 如果不清楚,愿意提供澄清吗?

.one .wrapper {
  display: flex;
}

.one .thumbnails {
  display: flex;
  flex-direction: column;
  border: 2px solid red;
  align-self: flex-start;
  margin-left: 5px;
}


.two .wrapper {
  display: flex;
  flex-direction: column;
}

.two .thumbnails  {
  display: flex;
  flex-direction: row;
  border: 2px solid red;
  margin-left: 5px;
}

答案 1 :(得分:0)

您可以使用网格对其进行很多简化:

.grid {
  display: grid;
  grid-template-columns: 9fr 1fr;
  grid-gap: 14px
}

img {
  width: 100%;
  border: solid 5px lightgray;
}

.thumbs img{
   border: solid 2px #f00
}
<h1>Can this:</h1>
<div class="grid">
  <img src="http://placekitten.com/200/400" />
  <div class="thumbs">
    <img src="http://placekitten.com/70/70" />
    <img src="http://placekitten.com/70/70" />
  </div>
</div>