/    Sign up×
Community /Pin to ProfileBookmark

Reusable CSS objects?

Hi everyone,
I’m new to CSS, but can already see its awesome potential! I was wondering if it’s possible to make reusable ‘objects’ in CSS.
For example, much of my HTML is cluttered with the navigation bar layout (which is essentially the same from page to page). Is there anyway to simply lump all this code in an external file (a reusable ‘nav-bar’ object) and reference it from the HTML? This would greatly clean up my HTML!
…I know that this is possible using pure CSS (i’ve explored pure CSS navigation bar layouts…cool, but not what I need). Unfortunately though, the nav-bar I’ve got involves images and mouseover commands.
any input greatly appreciated!
HH.

to post a comment
CSS

3 Comments(s)

Copy linkTweet thisAlerts:
@LeeUJan 08.2007 — CSS is not a coding language so there are no "objects". However, you could just put your navbar code in one include file and just pull it into each file.
Copy linkTweet thisAlerts:
@ray326Jan 09.2007 — The normal way to do that is server side includes, either using server facilities or through programming techniques.
Copy linkTweet thisAlerts:
@mudeltaJan 09.2007 — Hi everyone,

Is there anyway to simply lump all this code in an external file (a reusable 'nav-bar' object) and reference it from the HTML? [/QUOTE]


When i read your post, i think you use some inline css, like
[CODE]
<div style="your ccs here"></div>
[/CODE]

Is that correct?

there are two other ways to use css:

1) put all the css in the header:
[CODE]
<head>
<style type="text/css">
here your css
</style>
</head>

[/CODE]

2) use an external stylesheet

then you put alink in the head like this:
[CODE]
<head>
<link href="main.css" rel="stylesheet" type="text/css" />
</head>
[/CODE]


and the file main.css contains all the css

i don't know how you make your menu, but when you give the outerelement of the menu an id, you can access all the elements inside using css selectors, and put all of them in an external style sheet.



let's say you use an unorded list to make your menu:
<i>
</i>&lt;ul id="menu"&gt;
&lt;li&gt;&lt;a href=""&gt;menuItem1&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=""&gt;menuItem2&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=""&gt;menuItem3&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=""&gt;menuItem4&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

by giving the menu an id, you can put all the layout code in an external stylesheet. That way your (x)html stays clean.

And there's no problem for the mouseovers:

using unobtrusive javascript and the dom, you can attach mouseovers (or anything else) to your links.

[edit]

you should take a look at this site:

http://www.w3schools.com/css/default.asp


[/edit]
×

Success!

Help @humble_hermit 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...