denise uytiepo
denise uytiepo

Reputation: 3

How to change the body background for every id page?

I want to change the body background into different color when I click a page. My HTML code is only one page so the pages are classified into <div>s. I don't want to change the background of the id. I only want to change the color of the Body.

I tried:

body #home {background-color:#099;}

But it only changes within the dimensions of the #home div and not the body background

I tried:

body#home {background-color:#099;}

but nothing happens.

Upvotes: 0

Views: 972

Answers (2)

Ram Khumana
Ram Khumana

Reputation: 842

JavaScript

<script type="text/javascript">
        function changeBackgroundColor(Bodycolor) {
            alert(Bodycolor);
            document.body.style.background = Bodycolor;
        }
    </script>

HTML

 <div>
        <a onclick="changeBackgroundColor('red');">Home</a> <a onclick="changeBackgroundColor('black');">
            About</a>
    </div>

Upvotes: 0

Quentin
Quentin

Reputation: 943746

There is no way, in CSS, to select an element based on what its descendants are.

Give the body element an id.

Upvotes: 2

Related Questions