在表列之间设置边距/填充,而无需更改每列宽度

时间:2018-08-21 21:10:23

标签: html css

在全屏模式下,我有3列,并且我试图使各列之间具有填充/边距。当我将边距设置为以下值时:

margin: 0 25px;

第三列位于其他两列的下面。我的代码如下:

<div class="landscape-row">
  <div class="landscape-column">
    <img src="https://via.placeholder.com/500x500"  style="width:100%">  
    <h1>example heading</h1>
    <p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
  </div>
  <div class="landscape-column">
    <img src="https://via.placeholder.com/500x500"  style="width:100%">  
    <h1>example heading</h1>
    <p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
    </div>
  <div class="landscape-column">
    <img src="https://via.placeholder.com/500x500"  style="width:100%">  
    <h1>example heading</h1>
        <p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
    </div>
</div>

我的CSS如下:

* {
    box-sizing: border-box;
}

.landscape-row{
width:100%;
padding-left: 25px;
padding-right: 25px;
}
.landscape-column {
    float: left;
    width: 33.33%;
    padding: 5px;

    border-radius: 4px;
    border: 2px solid #e7e7e7;
    -webkit-transition: all 0.3s ease;
    -moz-transition: all 0.3s ease;
    transition: all 0.3s ease;
    box-sizing: border-box;

}

.landscape-row::after {
    content: "";
    clear: both;
    display: table;
    padding: 10px;

}

img{
padding-left:20px;
padding-right:20px;
padding-top:20px;
}

h1{
text-align:center;
}

p{
padding-left:20px;
padding-right:20px;
text-align:center;

}

@media screen and (max-width: 750px) {
    .landscape-column {
        width: 50%;
    }

    .landscape-column:last-child{
    width: 100%;
    margin-top: 25px;
    }
}

@media screen and (max-width: 500px) {
    .landscape-column {
        width: 100%;
    }
}

下面是我所拥有的JS小提琴 https://jsfiddle.net/tos3y2jk/3/

对此将提供任何帮助

0 个答案:

没有答案