user2021399
user2021399

Reputation:

Can I make div as a background?

Good day, can I make my div as a Background?

or how can I set my div at the back of another Div.

Upvotes: 2

Views: 3251

Answers (4)

Shelef
Shelef

Reputation: 668

the right way to do it is this 4 things:

  • width:100%
  • height:100%
  • position:fixed
  • z-index:-1

    .background_div { background-color:red; width:100%; height:100%; position:fixed; z-index:-1; }

Upvotes: 4

MarcoK
MarcoK

Reputation: 6110

If you want to get really funky, you could go with the CSS element()-function (Only working in Firefox). As by the specification:

Starting in Gecko 2.0, you can use the element() CSS function to use an arbitrary HTML element as a background image for background and background-image

This simply means that you can use an actual div (or any other HTML element) to be the background-image or another element. I experimented with this feature before, gave some pretty interesting results.

(But it isn't that really useful...)

Upvotes: 1

İlker Korkut
İlker Korkut

Reputation: 3250

HTML

    <div class="test"></div>

CSS

    .test{width:100%;height:100%;background:red;display:block;position:absolute;}

Live Example http://jsfiddle.net/YC6wD/

Upvotes: 0

Sanober Malik
Sanober Malik

Reputation: 2805

I think you can use two div tags and give the position as absolute and then give background to one of the div like this :

<div class="abc">

</div>
<div class="xyz">
    dgffsgf
</div>

and css like :

.abc{
    position:absolute;
    background-color:red;
    height:100%;
    width:100%;
}

.xyz{
    position:absolute;
}

This will get your work done!!

Working Code :Div

Upvotes: 3

Related Questions