Меню Закрыть

Document body style backgroundcolor

Содержание

Set the backgroundColor property:

Property Values

Value Description
color Specifies the background color.
transparent Default. The background color is transparent.
initial Set to default value.
inherit Inherit from parent element.

Technical Details

Default Value: transparent
Return Value: A string representing the background color
CSS Version CSS1

Example

The following code shows how to set a background color

The code above is rendered as follows:

Example 2

The following code shows how to set a background color for a

The code above is rendered as follows:

Example 3

The following code shows how to get the background color from a

The code above is rendered as follows:

Example 4

The following code shows how to get the background color for body tag.

I have a javascript function that is called when the user clicks a div to get the current background color (white on my laptop) of the web page:

Here is the checkbkcolor() function:

In other words: my web page background is white when the page appears BUT the document.body.style.backgroundColor is not set.

So is my web page set to ‘transparent’?

I don’t think so. To test, I added the following CSS background color and when the web page first appears, the entire background is yellow:

Now when my web page appears, it is no longer white (or transparent, whatever). The web page is yellow when it appears.

AND STILL. The following code shows the background color is not set:

My assumption is that my research (4 hours worth) on ‘bgColor’, ‘background’, ‘backgroundColor’ were not helpful.

Most of all I don’t understand how the entire web page background can come up yellow when I set the ‘body’ in CSS to rgb(255,255,0) and yet the following alert box says the backgroundColor is NOT SET:

Читайте также:  Ssd диск или оперативная память

I need to know, when the page first appears, what the background color is. How?

EDIT: I’m using the latest version of Firefox, version 22.0

Задание:
В конце скрипта примените к телу HTML-документа фоновый цвет, значение которого — результат вызова функции makeColorString(r, g, b) с параметрами red, green и blue. Строка с подобным вызовом сейчас последняя в script.js.

Вставляю в самый низ (есть подсказка для дураков, вставить эту строку):
document.body.style.backgroundColor = makeColorString(red, green, blue);

Выдает: "функция makeColorString возвращает неправильный результат"

Рекомендуем к прочтению

Добавить комментарий

Ваш адрес email не будет опубликован.