/    Sign up×
Community /Pin to ProfileBookmark

background image of an <div> ?

I split my page into 3 divs: header, main and footer.

Is there a way to put a background image on just the main division?
I’d prefer to use inline styling, because I only want this image on one
page, and I am using one css file for all pages.

I tried adding a style=”background-image:URL” to the <div> tag, but
that didn’t do what I wanted…

Any other suggestions?

to post a comment
HTML

5 Comments(s)

Copy linkTweet thisAlerts:
@tracknutJan 16.2012 — background-image should work.... show us the code.

Dave
Copy linkTweet thisAlerts:
@ggallenauthorJan 16.2012 — In double checking, I found I had a typo.

I now have <div style="background: url(URL)"

This does work, however, it only shows the top of the image.

here's what I'm not sure how to do.

My <div> size setup is as follows:

#main {

position:absolute;

width:100%;

top:140px;

bottom:50px;

background-color: #ffff66;

border-top: none;

border-bottom: none;

overflow: scroll;

}

I'm defining the top to be 140 pixels down, and the bottom to be 50 pixels from the bottom. Is there a way to make the background image 100% vertically between those and 100% horizontally, without actually specifying an actual number? This way I could make the image size smaller and just have it auto enlarged. The image I'm using can stretch without too much issue, so that won't be a problem.
Copy linkTweet thisAlerts:
@rtretheweyJan 16.2012 — Positioning does not determine the size of an element. If #main is the div you're using to hold the content of your page, try:
<i>
</i>#main {
width:100&amp;#37;;
margin-top:140px;
margin-bottom:50px;
background-color: #ffff66;
border-top: none;
border-bottom: none;
overflow: scroll;
}
Copy linkTweet thisAlerts:
@flashcusJan 16.2012 — I think he's hit the problem of the middle div not expanding down to the bottom div? If so, you need to create a parent div which is width 100% and height 100%, and then set the background to the image, and background position to offset the top and bottom divs.
Copy linkTweet thisAlerts:
@rtretheweyJan 16.2012 — Yeah, I didn't think that through. I'll have to come back to it later.
×

Success!

Help @ggallen spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...