Game Development Reference
In-Depth Information
If you look at the contents of the body , you see that it contains two parts. Each part is enclosed in
div tags, which are div used to divide an HTML document into divisions . You can apply a different
style to each division. In this example, the first division has a blue background and a font size of
40 pixels, and the second division has a yellow background and a font size of 20 pixels
(see also Figure 1-4 ).
Figure 1-4. A web page consisting of two divisions, each with a different background color and font size
Instead of adding a style attribute to an HTML element, you can also use JavaScript to modify
the style of that element. For example, you can change the background color of the body using
JavaScript, as follows:
<!DOCTYPE html>
<html>
<head>
<title>BasicExample</title><script>
changeBackgroundColor = function () {
document.body.style.background = "blue";
}
document.addEventListener('DOMContentLoaded', changeBackgroundColor);
</script>
</head>
<body>
That's a very nice background.
</body>
</html>
Search WWH ::




Custom Search