开发者

Display: table-cell, contents and padding

开发者 https://www.devze.com 2023-02-10 16:05 出处:网络
I have a very straightforward HTML page that开发者_如何学Python displays content in two columns. To format the columns I\'m using <div> as the outer container (display: table-row) and two inner

I have a very straightforward HTML page that开发者_如何学Python displays content in two columns. To format the columns I'm using <div> as the outer container (display: table-row) and two inner <div> as the actual columns (display: table-cell). One of these columns has a padding at the top. The markup looks like the following - extra markup and styles omitted for clarity:

<style>
.row { display: table-row }
.cell { display: table-cell; border: 1px solid black; width: 150px }
.content { background-color: yellow }
</style>

<div class="row">
   <div class="cell">
      <div class="content">Some content; this is not padded.</div>
   </div>

    <div class="cell">
        <div class="content">More content; padded at the top.</div>
    </div>
</div>

I'm getting this:

Display: table-cell, contents and padding


But I expected this:

Display: table-cell, contents and padding


The behavior is the same whether the padding-top is applied to the cell or the content. Am I missing anything? Thanks.


You can achieve your two desired results just by using padding and margin on your div with the class content. Remember, padding will contribute to the overall width and height of an object, so that will extend the background color.

First screen shot:

<div class="content" style="margin-top: 10px">More content; padded at the top.</div>

Second screen shot:

<div class="content" style="padding-top: 10px">More content; padded at the top.</div>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号