/    Sign up×
Community /Pin to ProfileBookmark

Background image inside a div

Is there a property to set a background image for a DIV? I know there use to be but it seams to have been discontinued by the w3c.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@fredmvNov 21.2003 — It can be done like this:

[font=courier]<a href="#" onclick="document.getElementById('foo').style.backgroundImage='url(http://www.neitherday.com/textureheaven/BlueMood/BlueMood.jpg);';">Set background image.</a>

<div id="foo" style="height: 120px;"></div>[/font]

[color=red][b]NOTE:[/b] Make sure to get the full URL since the URL is shortened.[/color]
Copy linkTweet thisAlerts:
@JishNov 21.2003 — Try this:

<i>
</i>&lt;style type="text/css"&gt;

div#myBackground {
background-image: url("myBackgroundImage.jpg");
width: 100px; height: 100px; }

&lt;/style&gt;

&lt;/head&gt;
&lt;body&gt;

&lt;div id="myBackground"&gt;&amp;bnsp;&lt;/div&gt;
Copy linkTweet thisAlerts:
@fredmvNov 22.2003 — You shouldn't use quotes around the URL to the image or external CSS file as it doesn't work in some browsers. Also, I believe [b]Dudsmack[/b] was referring to changing the background image of an element through [i]scripting[/i] since it's in the DHTML section. Just some friendly advice, welcome to the forums. ?
×

Success!

Help @ilbonparaurti 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.18,
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,
)...