/    Sign up×
Community /Pin to ProfileBookmark

Stuck ( CSS / DIV Background Workaround )

When using CSS / HTML I want to use one DIV Class with different backgrounds.

from the CSS

[code]
#aboutleftside {
clear: left;
float: left;
width: 165px;
height: 190px;
margin: 0px 0px 0px 7px;
padding: 10px 0px 0px 18px;
background: url(images/aboutLeft.jpg);
background-repeat: no-repeat;
line-height: 1.2em;
}
[/code]

however, instead of bloating the CSS file with the same class over and over with all the attributes of that class (ie, #aboutleftside p, p a, p a:hover, ect ect) I was wondering if it would be possible to do something along these lines.

[code]
#aboutleftside {
clear: left;
float: left;
width: 165px;
height: 190px;
margin: 0px 0px 0px 7px;
padding: 10px 0px 0px 18px;
[I][COLOR=”Red”] background: url(images/aboutLeft.jpg);[/COLOR][/I]
background-repeat: no-repeat;
line-height: 1.2em;
}
[/code]

remove the red and use it in the page as follows

[code]<div id=”aboutleftside” background=”images/aboutLeft.jpg”>
</div>

<div id=”aboutleftside” background=”images/aboutLeft2.jpg”>
</div>
[/code]

so that i can manipulate the background image and simply use the same DIV Class, i am having a serious brain meltdown right now, and for some reason the code is not appearing in my head on how to get around this simple fix.

to post a comment
CSS

4 Comments(s)

Copy linkTweet thisAlerts:
@skilled1authorOct 29.2007 — meh after a bit of punching myself in the face, and a fresh bit of coffee i finally figured it out.

&lt;div id="aboutleftside" style="background-image:URL(images/aboutLeft.jpg);"&gt;
&lt;/div&gt;


&lt;div id="aboutleftside" style="background-image:URL(images/aboutLeft2.jpg);"&gt;
&lt;/div&gt;
Copy linkTweet thisAlerts:
@KDLAOct 29.2007 — The reason it's not working is that you've coded like HTML, rather than CSS:
<i>
</i>&lt;div id="aboutleftside" style="background: url(images/aboutLeft.jpg);"&gt;
&lt;/div&gt;
Copy linkTweet thisAlerts:
@skilled1authorOct 29.2007 — The reason it's not working is that you've coded like HTML, rather than CSS:
<i>
</i>&lt;div id="aboutleftside" style="background: url(images/aboutLeft.jpg);"&gt;
&lt;/div&gt;
[/QUOTE]



its because i am using a hybrid. the code is 90% CSS with 10% HTML, however i wanted to control different backgrounds with the same CSS DIV Class, look and feel + attributes, rather then repeat the same styles and code in the CSS 8x over.

so i simply used the CSS for the DIV Class of 'aboutleftside' then defined the specific background i wanted to use in the <div> tag itself on the specific HTML page, and that is what i was trying to figure out, till i posted my own answer in the second responce if anyone else was looking to solve the problem as well.
Copy linkTweet thisAlerts:
@CentauriOct 29.2007 — You have a problem distinguishing classes from id's. An id can only be used once per page, and the css referencing this id uses a leading hash(#). A class can be used multiple times, and the css reference uses a leading period (.) [CODE].aboutleftside {
clear: left;
float: left;
width: 165px;
height: 190px;
margin: 0px 0px 0px 7px;
padding: 10px 0px 0px 18px;
background-repeat: no-repeat;
line-height: 1.2em;
}[/CODE]

[CODE]<div class="aboutleftside" style="background-image:URL(images/aboutLeft.jpg);">
</div>

<div class="aboutleftside" style="background-image:URL(images/aboutLeft2.jpg);">
</div>[/CODE]
×

Success!

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