html - 如何为背景的特定部分设置颜色?

标签 html css background

我目前正在尝试为页面背景的特定部分设置背景颜色。这个想法是让页面顶部的大约 1/5 或 1/4 是一种颜色,而整个剩余的底部是一种单独的颜色。我考虑过使用渐变来做到这一点,但我不知道如何通过 CSS3 设置特定的停止部分。

关于如何使用 CSS3 完成这项工作有什么想法吗?

最佳答案

使用 gradient generator

html, body {
  min-height: 100%;
}

body {
  background: #fb83fa;
  background: -moz-linear-gradient(top, #fb83fa 25%, #7ceacd 25%, #7ceacd 100%);
  background: -webkit-gradient(linear, left top, left bottom, color-stop(25%,#fb83fa), color-stop(25%,#7ceacd), color-stop(100%,#7ceacd));
  background: -webkit-linear-gradient(top, #fb83fa 25%,#7ceacd 25%,#7ceacd 100%);
  background: -o-linear-gradient(top, #fb83fa 25%,#7ceacd 25%,#7ceacd 100%);
  background: -ms-linear-gradient(top, #fb83fa 25%,#7ceacd 25%,#7ceacd 100%);
  background: linear-gradient(to bottom, #fb83fa 25%,#7ceacd 25%,#7ceacd 100%);
}

或者您可以放弃渐变并使用伪元素...

html, body {
    min-height: 100%;
}

body {
    background: #7CEACD;
}

body:before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 25%;
    background: #fb83fa;
}

关于html - 如何为背景的特定部分设置颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30332770/

相关文章:

html - 如何正确定位螺旋形状的图像

php - 如何创建随内容增长的两列 div?

jquery - 呈现大型 html 文件的问题(链接错误,图像不显示)

即使应用程序终止,iOS 也会更新位置

html - 格式化 HTML 表格单元格以便 Excel 格式化为文本?

javascript - jquery获取每张图片的宽度

javascript - 如何制作宽度为 1px 的 Vaadin 网格列?

css - React js css样式表应用于多个组件

background - 后台状态与已暂停的应用程序状态之间的混淆

android - 如何设置溢出菜单的背景颜色