472,954 Members | 1,728 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,954 software developers and data experts.

Removing Unnecessary Styles

Over the course of building a very large site, I've wound up with an
enormous style sheet containing plenty of superfluous styles. Is there
a tool that can recognize which styles are not being used in a site
and eliminate them? Can Dreamweaver perform that function?
Jan 10 '08 #1
5 2266
In article
<eb**********************************@t1g2000pra.g ooglegroups.com
>,
fl******@comcast.net wrote:
Over the course of building a very large site, I've wound up with an
enormous style sheet containing plenty of superfluous styles. Is there
a tool that can recognize which styles are not being used in a site
and eliminate them? Can Dreamweaver perform that function?
I will just tell you one method I use: you see .class in the css
and wonder if it is being used. So use the Search and Replace
function in your text editor and search the whole set of html
docs for (to take the simplest case) class="class". If it #id you
are wondering about, search for (again, to take the simplest
case), id="id"

There are more complicated searches that you might need to make
and a familiarity with GREP functions would assist you. But you
*can* get by mostly without. For example, if you suspect you have
muliple classes specified in your page like class="class1 class2"
then you can simply search for "class1 and then search later for
class1" and then later "class2 and then class2". If you suspect a
triple class and you need to capture the middle one, well there
is always simply class.

--
dorayme
Jan 10 '08 #2
Thanks for the response, dorayme. Yeah, I was hopin' there'd be an
easier solution than performing a search for each individual class and
id. Like I said, this style sheet has gotten huge over time, so it's
going to be a laborious task. :\

Jan 10 '08 #3
In article
<a7**********************************@v4g2000hsf.g ooglegroups.com
>,
fl******@comcast.net wrote:
Thanks for the response, dorayme. Yeah, I was hopin' there'd be an
easier solution than performing a search for each individual class and
id. Like I said, this style sheet has gotten huge over time, so it's
going to be a laborious task. :\
I guess it depends on how big your project is. The actual global
Find functions work in less than the time you can say, "O hells
bells, I have been making this site up as I go without sufficient
strategic planning" <g>

You can also use intuition and guess work. On this, here is a
further strategy I recommend:

The extra classes and things that do no work in the css might do
no harm. So you have time on your side. So comment out anything
you even suspect is a cog that is not engaged with any machinary.
And browse away on your local machine or server and if nothing
ever shows up wrong you ever notice after a few days or weeks,
dump the cog.

(btw... Please try to quote the gist of the thread before
replying as many folk here do not use Google to read newsgroups
and some of us have online readers that dump old posts).

--
dorayme
Jan 10 '08 #4
On 11 Jan, 01:06, GTalbot <newsgr...@gtalbot.orgwrote:
Most of the time, beginners at CSS do not understand what is
inheritance and how to use it.
Probably a good thing. CSS rules aren't inherited.
CSS property values may be inherited, but that's different. An
assumption that CSS uses "inheritance" in hoow selectors are applied
(it actually uses cascading) is a common mis-understanding, especially
amongst O-O programmers.
Jan 11 '08 #5
On 10 Jan, 20:42, fleem...@comcast.net wrote:
Over the course of building a very large site, I've wound up with an
enormous style sheet containing plenty of superfluous styles. Is there
a tool that can recognize which styles are not being used
In the full and generalised case, no. It's a computationally difficult
problem. It's _impossible_ to do so for a stylesheet alone, as it
requires knowledge of the HTML to which it's being applied.

As a quick start though, try using a simple CSS validator, like the
W3C online one. This will give you a "normalised" rendition of the CSS
that's usually a good starting point. Where the CSS contains lots of
simple verbosity and literal duplication, then this can be useful.

The real problem though is more difficult. You will typically have
much CSS that repeats rules (or at least properties) but applies them
through different selectors. It's not ppossible to simplify this
automatically, as the CSS _is_ actually different. Only by applying
external knowledge of the HTML it's applied to (a HTML meta-structure
for the site) is it even _possible_ to recognise what's superfluous
duplication.

As an example, it's commonly-seen bad practice to apply CSS rules to
an <lielement, especially when there's a class repeated onto each
<litoo. A better CSS structure is to re-code this to style the <ul>
and then inherit (font settings etc. would inherit happily, but
obviously box-sizing couldn't), or even to apply the class to the <ul>
element and use selectors of the form ul.foo li {} instead. Making
these changes though requires an overall view of the problem, right
back to the HTML meta-structure level. It's not something you can
expect a simple dupe-stripping script on the CSS alone to achieve.

IMHE, it's very difficult to improve complex existing CSS. The trick
is to structure and design carefully from the outset. Refactoring it
afterwards is hard!
Jan 11 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: simon place | last post by:
Removing __slots__ ~~~~~~~~~~~~~~~~~~~ To do this nicely requires the renaming of __dict__ to, say, __attribs__ , ( since dict is unnecessarily unspecific, this seem like a small improvement...
0
by: Quinton | last post by:
I'm running a website that uses CSS to format the text and a CGI program Coranto that icludes news updates via SSI. My problem is that some parts of the CSS don't seem to take effect on the...
12
by: Ole Noerskov | last post by:
The function below is supposed to remove all childnodes with a name that starts with "keywords" in "myform" in the window.opener. It works fine if there's one keyword node. But you have to run...
12
by: dan.vendel | last post by:
Hi, I know nothing about javascript, but quite a lot about regulat html and CSS. Have bumped into a problem that people in this fine congregation perhaps can help me with. I'm making a...
4
by: Drew | last post by:
I have a permission tracking app that I am working on, and I have made the insert page for it. I am having issues on how to prevent duplicates from getting entered. Currently the interface for...
3
by: JezB | last post by:
What's the generally accepted approach for using Styles and Stylesheets in a web application based on .aspx files, Web Controls, User Controls, and code-behind modules (c# in my case)? Most style...
11
by: MikeT | last post by:
This may sound very elementary, but can you trap when your object is set to null within the object? I have created a class that registers an event from an object passed in the constructor. When...
2
by: beatTheDevil | last post by:
Hey guys, As the title says I'm trying to make a regular expression (regex/regexp) for use in removing the comments from code. In this case, this particular regex is meant to match /* ... */...
11
by: ramu | last post by:
Hi, Suppose I have a string like this: "I have a string \"and a inner string\\\" I want to remove space in this string but not in the inner string" In the above string I have to remove...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.