简体   繁体   English

如何将子div放入父类的填充内?

[英]How to fit child div inside the padding of parent class?

I am creating columns inside a row using Foundation CSS front-end framework. 我正在使用Foundation CSS前端框架在一行中创建列。

<div class="row small-up-2 large-up-3 food-container">
  <div class="column food-wrap">
    <img src="http://placehold.it/500x500&amp;text=Thumbnail" class="thumbnail">

    <div class="panel food-panel-top">
        <p>Description</p>
    </div>

  </div>
  <div class="column food-wrap">
    <img src="http://placehold.it/500x500&amp;text=Thumbnail" class="thumbnail">

    <div class="panel food-panel-top">
        <p>Description</p>
    </div>

  </div>
  <div class="column food-wrap">
    <img src="http://placehold.it/500x500&amp;text=Thumbnail" class="thumbnail">

    <div class="panel food-panel-top">
        <p>Description</p>
    </div>
  </div>

</div>

This is my CSS: 这是我的CSS:

 .column, .columns {
    padding-left: 0.9375rem;
    padding-right: 0.9375rem;
}


.food-wrap { position: relative; }

.food-wrap > .panel {
    position: absolute;
    width: 100%;
    background-color: rgba(0, 0, 0, 0.2);
}


.food-panel-top { top: 0; }
.food-panel-bottom { bottom: 0; }

.food-wrap .thumbnail {
    border: medium none;
    box-shadow: none;
}

Problem: Each class .foodwrap has a padding to the left and right. 问题:每个类.foodwrap的左侧和右侧都有填充。 I want the class .food-panel-top to be wrapped inside the paddings of .foodwrap. 我希望将.food-panel-top类包装在.foodwrap的填充物中。 What happens when I give .food-panel-top a width of 100% is that it is going outside the limits. 当我将.food-panel-top的宽度设置为100%时,会发生什么事情,那就是它超出了限制。 I want the .food-panel-top to have the same width with class="thumbnail" 我希望.food-panel-top与class =“ thumbnail”具有相同的宽度

Any help is appreciated. 任何帮助表示赞赏。

I know the answer to this post now. 我现在知道该帖子的答案。 I still to post the answer so it can help out other developers out there. 我仍然要发布答案,以便它可以帮助其他开发人员。

The key in solving this question is to remove the left and right padding of class="column". 解决此问题的关键是删除 class =“ column”的左右填充 After removing the left and right paddings, we can now maximing the width of food panel classes to 100%. 除去左侧和右侧的填充物后,我们现在可以将食物面板类的宽度最大增加到100%。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM