Link to home
Start Free TrialLog in
Avatar of kadin
kadinFlag for United States of America

asked on

Is there a professional way to share class selectors across multiplie pages?

When one class is used on multiple pages and I want to make a change to that class, I don't know how that will effect the other pages, how many pages, which pages, it becomes complicated. I have to search painstakingly through every page looking for the same class name.

I would prefer to just share a class selector across one page only and have a different class name for each page even if there is duplicate css code, at leased I can find the elements in just one page and be certain I did not mess up another page.

I only have one css page and I group my css selectors by the page they refer to so they are easier to find, I don't have to scroll up and down the css page as much. For example,

account.php -  all class names start with a.
center.php -  all class names start with c.
upload.php -  all class names start with u.

.a-form-outer {
	font-weight: bold;
	margin: 100px auto 0px auto;
}

.a-wall-inner {
	margin: 100px auto 0px auto;
}

.c-page-lock {
	margin-left: 20px;
}

.c-no-nav {
	margin-left: 10px;
	width: 602px;
}

.u-logo {
	display: block;
	margin: 10px 0px 30px 10px;
	width: 170px;
}
	
.u-logo:hover {
	background-color: #FFF;
}

Open in new window


Does someone know if there is only one professional way to do this?
Do you know how google, yahoo or any major site handles this?
Thanks.
Avatar of Gary
Gary
Flag of Ireland image

Add another class to the element on the page where the changes should be and add the new css for that element.
There is no way to say only apply this class on this page.
Avatar of kadin

ASKER

Thanks for your response.

I am not sure we are understanding each other. What I am trying to find out is not what is a fix for one element with a shared CSS. Because that fix would be after the fact and would require me to search through every page of the site looking for any and all classes using that same class name to determine if and how my change to that CSS is going to effect the other elements sharing that class.

I am trying to find out what strategy the pros at google, yahoo, facebook etc. use when designing their code. Do they share their classes with the whole website or do they share classes by website region, or by page.

From my perspective it seems to be a trade off between (having some duplicated code in my CSS file [same code, different class names], but easier to maintain with greater certainty that I don't break another part of my site)  vs. (keeping my CSS file as short as possible [I guess for efficiency] by using a one class fits all strategy).

I try to follow Google's style guide but I could not find anything pertaining to an overall strategy.
http://google-styleguide.googlecode.com/svn/trunk/htmlcssguide.xml
SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kadin

ASKER

Thanks for your help.