边距左右宽度100% [英] margin left and right on width 100%

查看:147
本文介绍了边距左右宽度100%的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个div设置为宽度100%。我想设置一个左右边距20px。由于某种原因,只有左边被推到20px。它忽略了权利。这是因为100%?

I have a div that's set to width 100%. I wanted to set a margin right and left of 20px. For some reason only the left is being pushed over 20px. It ignores the right. Is this because of the 100%?

推荐答案

删除宽度。与所有块元素一样,div将自动展开以填充可用宽度。当您指定宽度为100%时,您将告诉它与其容器的大小相同,而不是填充可用宽度。由于宽度不包括边距,因此除了宽度之外指定边距会使div向右移动左边距量,右边距在屏幕外。

Remove the width. As with all block elements, divs will automatically expand to fill the available width. When you specify a width of 100%, you are telling it to be the same size as its container, not to fill the available width. As width does not include margins, specifying the margin in addition to the width causes the div to be shifted to the right by the left margin amount, and the right margin exists off the screen.

这篇关于边距左右宽度100%的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆