html - 使用 Bootstrap 和 Rails 让 HTML <body> 填充整个垂直空间?

标签 html css ruby-on-rails twitter-bootstrap

我正在尝试用如下所示的渐变填充我的 Rails 网页的背景:

.gradient {
  background: #43cea2;
  background: -webkit-linear-gradient(to right, #185a9d, #43cea2);
  background: linear-gradient(to right, #185a9d, #43cea2);
}

渐变效果完美,但是正文的内容并没有填满屏幕的整个垂直空间,因此渐变背景在页面中途被切断。

我已经在 Stack Overflow 上引用了其他帖子,例如 this one ,但这些答案似乎都没有帮助。

在我的 application.scss 中添加这些行似乎根本没有任何效果:

html {
   margin: 0px;
   height: 100%;
   width: 100%;
}

body {
   margin: 0px;
   min-height: 100%;
   width: 100%;
}

如有任何帮助,我们将不胜感激!

最佳答案

将 body height 设置为 100% 而不是最小高度,然后将 .gradient 元素设置为 100% 高度

见下文

html {
height: 100%;
}

body {
height: 100%;
}

.gradient {
  height: 100%; /*If you're placeing this class on the body then remove this as it is redundent*/
  background: #43cea2;
  background: -webkit-linear-gradient(to right, #185a9d, #43cea2);
  background: linear-gradient(to right, #185a9d, #43cea2);
}
<div class="gradient"></div>

然而,更简单的方法是将要放置渐变类的元素设置为 100vh:

.gradient {
...
height: 100vh
}

这会将其设置为视口(viewport)(浏览器)高度的 100。 Here is some information on viewport units

关于html - 使用 Bootstrap 和 Rails 让 HTML <body> 填充整个垂直空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49884188/

相关文章:

ruby-on-rails - 加载错误 : cannot load such file -- bcrypt_ext on Windows 2008 x64 server

javascript - 如何解决根据窗口宽度/高度自动调整大小的网站中的手机/电话键盘

html - 为什么 & 在页面加载后变成 & ?

html/css,如何使元素填充不覆盖以前的元素?

html - img-circle 类不对图像进行四舍五入

Android:应用于一个 TextView 的不同格式样式

html - 将父 div 与动态和设置宽度子 div 居中

ruby-on-rails - 安装多个版本的 Rails 会覆盖以前的安装吗?

ruby-on-rails - 使用自定义状态代码或为 ajax 呈现自定义文本?

javascript - 在 IFrame 中覆盖 window.open