HTML baggrund

En god baggrund gør webstedet ser særligt godt ud.

Eksempel

God kombination af baggrundsfarve og tekstfarve
Et eksempel på en god kombination af baggrundsfarve og tekstfarve, hvilket gør det nemt at læse teksten på siden.
Dårlig kombination af baggrundsfarve og tekstfarve
Et eksempel på en dårlig kombination af baggrundsfarve og tekstfarve, hvilket gør det svært at læse teksten på siden.

Du kan finde flere eksempler nederst på denne side。)

Baggrund (Backgrounds)

<body> Har to tags til konfiguration af baggrund. Baggrunden kan være en farve eller et billede.

Baggrundsfarve (Bgcolor)

Baggrundsfarveegenskaben sætter baggrunden til en bestemt farve. Værdien kan være et hexadecimalet tal, en RGB-værdi eller et farvenavn.

<body bgcolor="#000000">
<body bgcolor="rgb(0,0,0)">
<body bgcolor="black">

The above code sets the background color to black.

Background (Background)

The background property sets the background to an image. The value of the property is the URL of the image. If the image size is smaller than the browser window, the image will be copied across the entire browser window.

<body background="clouds.gif">
<body background="http://www.codew3c.com/clouds.gif">

The URL can be a relative address, such as the first line of code. It can also be an absolute address, such as the second line of code.

Tip:If you plan to use background images, you need to keep the following in mind:

  • Does the background image increase the page loading time? Tip: Image files should not exceed 10k.
  • Is the background image well coordinated with other images on the page?
  • Is the background image well coordinated with the text color on the page?
  • Does the image look good when tiled across the page?
  • Is the attention to the text distracted by the background image?

Basic Considerations - Useful Tips:

The background color (bgcolor), background (background), and text (text) properties in the latest HTML standards (HTML4 and XHTML) have been deprecated. W3C has removed these properties from their recommended standards.

You should use Cascading Style Sheets (CSS) to define the layout and display properties of HTML elements.

More Examples

Highly usable background image
Examples where background images and text colors make page text easy to read.
Highly usable background image 2
Another example where background images and text colors make page text easy to read.
Poorly usable background images
Examples where background images and text colors make page text difficult to read.