Html 我如何做一个有超过1个背景色的网站?

Html 我如何做一个有超过1个背景色的网站?,html,css,colors,background,Html,Css,Colors,Background,这是我得到的,但只有一种背景色占据了90%的屏幕。但我想换一种颜色 position: fixed; top: 0px; left: 0px; width: 100%; height: 90%; background-color: #20a2d6;} 如果你在spelltower.com上查看源代码,你会发现你看到的不是应用于整个页面的多个背景色,你可以找到我想要的示例。每个部分都有自己的背景色 正在为这些彩色背景使用标记。它不仅仅是一个具有多种背景颜色的单一元素。Javascript用于在调

这是我得到的,但只有一种背景色占据了90%的屏幕。但我想换一种颜色

position: fixed;
top: 0px;
left: 0px;
width: 100%;
height: 90%;
background-color: #20a2d6;}

如果你在spelltower.com上查看源代码,你会发现你看到的不是应用于整个页面的多个背景色,你可以找到我想要的示例。每个部分都有自己的背景色

正在为这些彩色背景使用标记。它不仅仅是一个具有多种背景颜色的单一元素。Javascript用于在调整浏览器窗口的大小时调整每个部分的大小

HTML Javascript
//调整浏览器窗口大小时。。。
$(窗口)。调整大小(函数(){
//获取新窗口的高度
var windowHeight=$(window.height();
//确定我们想要的每个部分的高度,在这里
//我们不希望它的高度低于600像素
var newHeight=窗高;

如果(newHeight如果你想让你的身体90%是一种颜色,剩下的10%是另一种颜色,那么你应该在你的HTML身体中创建两个容器:每个容器都分配一个不同的CSS。为了向你解释逻辑(我让你做剩下的关于定位、大小等的事情):

HTML:这里您创建了两个单独的div容器

<body>

    <div id="first_section">

    <div/>

    <div id = "second_section">

    <div/>

<body/>
我特别建议,这是一个很好的类和Javascript函数集合,允许您的网站在浏览器大小发生变化时(例如,从全屏到平板电脑或手机)立即响应

#first_section { background_color: blue; }
#second_section { background_color: red; }
#third_section { background_color: green; }
//When the browser window is resized...
$(window).resize(function() {
    // Get the new window height
    var windowHeight = $(window).height();

    //Determine the height we want each section, in this
    //case we don't want it to be less than 600 pixels tall
    var newHeight = windowHeight;
    if(newHeight<600) newHeight = 600;

    $('section').css('height', newHeight);
});
<body>

    <div id="first_section">

    <div/>

    <div id = "second_section">

    <div/>

<body/>
#first_section{
    width: 100%;
    height: 90%;
    background-color: red;
}

#second_section{
    width: 100%;
    height: 10%;
    background-color: blue;
}