How to set page background color with CSS
In CSS, you can use the "background-color" attribute to set the page background color, the syntax is "background-color: color value". The background-color property sets the background color of the element, which is the total size of the element, including padding and borders (but not margins).
The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.
Set the background color of the page
CSS is implemented by setting the background-color attribute of the body tag. The background color mainly highlights the theme of the page and is consistent with the color of the foreground text. Cooperate. The specific setting method is the same as the setting of text color value. Hexadecimal, RGB components, or English words of color can be used.
<span style="font-size:24px;"><html> <head> <title> 背景颜色 </title> <style> <!-- body{ background-color:#5b8a00; margin:0px; padding:0px; color:#c4f762; } p{ font-size:15px; padding-left:10px; padding-top:8px; line-height:120%; } span{ font-size:80px; font-family:黑体; float:left; padding-right:5px; padding-left:10px; padding-top:8px; } --> </style> </head> <body> <img src=" http://scs.ganjistatic1.com/gjfs12/M09/A3/B3/CgEHC1VGJz2HZm6eAAEe8iEJ1Go460_600-0_6-0.jpg "style="float:right;"> <span>春</span> <p>季,地球的北半球开始倾向太阳,收到越来越多的太阳光直射,因而气温开始升高。随着冰雪消融,河流水位上涨。春季植物开始发芽生长,许多鲜花开放。冬眠的动物苏醒,许多以卵过冬的动物孵化,鸟类开始迁移,离开越冬地向繁衍地进发。许多动物在这段时间里发情,因此中国也将春季称为“万物复苏”的季节。春季气温和生物界的变化对人的心理和生理也有影响。</p> <p>对农民来说,春季是播种许多农作物的季节。在春季,地球的北半球开始倾向太阳,收到越来越多的太阳光直射,因而气温开始升高。随着冰雪消融,河流水位上涨。春季植物开始发芽生长,许多鲜花开放。冬眠的动物苏醒,许多以卵过冬的动物孵化,鸟类开始迁移,离开越冬地向繁衍地进发。许多动物在这段时间里发情,因此中国也将春季称为“万物复苏”的季节。春季气温和生物界的变化对人的心理和生理也有影响。</p> </body> </html></span>
The code is as above. You can see that the background color is dark green and the text color is bright green. Together with the picture and the text content itself, the resurrection of all things in spring is displayed.
Use background color to divide the page into blocks
The Background-color attribute can not only set the background color of the page, but also the background color of almost all HTML elements. set up. Therefore, many web pages achieve the effect of blocking by setting different background colors.
<span style="font-size:24px;"><html> <head> <title> 利用背景颜色分块 </title> <style> <!-- body{ padding:0px; margin:0px; background-color:#ffebe5; } .topbanner{ background-color:#fbc9ba; } .leftbanner{ width:22%;height:330px; vertical-align:top; background-color:#6d1700; color:#FFFFFF; text-align:left; padding-left:40px; font-size:14px; } .mainpart{ text-align:center; } --> </style> </head> <body> <table cellpadding="0"cellspacing="1" width="100%" border="0"> <tr> <td colspan="2"class="topbanner"><img src=" http://scs.ganjistatic1.com/gjfs12/M09/A3/B3/CgEHC1VGJz2HZm6eAAEe8iEJ1Go460_600-0_6-0.jpg "border="0"></td> </tr> <tr> <td class="leftbanner"> <br><br>首页<br><br>分类讨论 <br><br>谈天说地<br><br>精华区 <br><br>我的信箱<br><br>休闲娱乐 <br><br>立即注册<br><br>离开本站 </td> <td class="mainpart">正文内容……</td> </tr> </body> </html></span>
The code is as above. The top Banner, the left navigation bar and the middle text part use 3 different background colors respectively to achieve the purpose of page segmentation. This segmentation method is used in the web page. Often used in production.
Here, the Banner picture at the top can be a picture with a color gradient from left to right. The color transitions from the own picture to the background color of the page, which will appear very natural. This effect can be seen in Photoshop It is easy to implement and is also a common method for web page production.
Recommended learning: css video tutorial
The above is the detailed content of How to set page background color with CSS. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text
