html - 我的 div 大于窗口的宽度

标签 html css

这是我的 divcss。 © 期望背景填满整个屏幕,但它比我的屏幕分辨率大,所以出现底部滚动条

.hero-unit {
  padding:60px;
  margin-top: 60px;
  background: url("../img/bar2.jpg") no-repeat scroll 0;
  height:233px;
  width:100%;
  left:0px;
  background-size: cover;
  position:absolute;
  background-color:#eeeeee;
}

最佳答案

你可以使用 box-sizing

-webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
-moz-box-sizing: border-box;    /* Firefox, other Gecko */
box-sizing: border-box;

这样一来,当您添加填充、边距或边框时,它不会影响宽度。 (这不适用于 IE7 及以下版本)

关于html - 我的 div 大于窗口的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12677898/

相关文章:

python - 我的背景图片没有完全展开或显示为完整尺寸。 html部分中的背景图片有问题

javascript - 用行号填充 div

html - Chrome 中的文件上传样式

javascript - 使用 D3 转换禁用 SVG 上的悬停 CSS

c# - 如何解决 "striped"表的 Blazor/Bootstrap 5 CSS 问题?

javascript - 我可以在选择元素的选项中使用 HTML 标签吗?

javascript - 我将如何填充 Bootstrap 模式?

javascript - 在 slider 上动态添加类

php - 使用 "variable"包装类输出 HTML

css - 如何在 Genesis Framework 中应用 Less css