加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

html – div顶部和底部减去20个像素

发布时间:2020-12-14 19:45:50 所属栏目:资源 来源:网络整理
导读:作为一个简单的例子,我有两个非常简单的div: (绿色的是红色的) 现在我如何从绿色div的底部和顶部减去20个像素? HTML: CSS: #container { width: 200px; height: 300px; background: red;}#rows { width: 50%; height: 100%; /* margin-top: 20px; margin

作为一个简单的例子,我有两个非常简单的div:

(绿色的是红色的)

现在我如何从绿色div的底部和顶部减去20个像素?

HTML:

CSS:

#container {
    width: 200px;
    height: 300px;
    background: red;
}

#rows {
    width: 50%;
    height: 100%;
    /* margin-top: 20px;
        margin-bottom: 20px; */

   /*  padding-top: 20px;
    padding-bottom: 20px; */    

/*     top: 20px;
    bottom: 20px;  
    height: auto; */

    background: green;

}

http://jsfiddle.net/clankill3r/2L6c2bLf/1/

最佳答案
这是一种方法,无需在父div中添加填充或在子div中使用calc.

JSFIDDLE

#container {
    width: 200px;
    height: 300px;
    background: red;
    position: relative;
}
#rows {
    position: absolute;
    width:50%;
    top: 20px;
    bottom: 20px;
    background: green;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读