Rename a CSS style?

B

Bob Altman

Using VS 2008 SP1, is there a way to rename a CSS style and all of the
references to that style (short of doing a global find-and-replace in the
code)? You'd think that the Manage Styles and Apply Styles windows would
have a simple "rename this style" option that does this, but I can't find
it...

TIA - Bob
 
H

Hongye Sun [MSFT]

Hi Bob,

This feature is not supported in VS 2008. As mentioned in MSDN:
http://msdn.microsoft.com/en-us/library/6kxxabwd.aspx.
"Rename is a refactoring feature in the Visual Studio integrated
development environment (IDE) that provides an easy way to rename
identifiers for code symbols such as fields, local variables, methods,
namespaces, properties, and types. "
However CSS style is not included in its support list.

In the meanwhile, I will suggest you to submit a new feature request at
http://connect.microsoft.com/VisualStudio.

If you have any other questions or concerns, please do not hesitate to
contact us. It is our pleasure to be of assistance. Have a nice day.

Regards,
Hongye Sun ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Göran Andersson

Bob said:
Using VS 2008 SP1, is there a way to rename a CSS style and all of the
references to that style (short of doing a global find-and-replace in
the code)? You'd think that the Manage Styles and Apply Styles windows
would have a simple "rename this style" option that does this, but I
can't find it...

TIA - Bob

As CSS can use multiple identifiers, it's not that simple to determine
what to refactor and what not to refactor. Perhaps you use CSS in a way
that it looks very simple, but it's easy to show an example where it
would be rather complex.

Consider this CSS:

..List span { float: left; }
..Header .name { background: #000; color: #fff; }
..Line .name { color: #009; }
..name { width: 100px; }

And this HTML:

<div class="List Header">
<span class="name">Name</span>
</div>
<div class="List Line">
<span class="name">Arthur</span>
</div>
<div class="List Line">
<span class="name">Trillian</span>
</div>

Now, if I rename the style ".name" to ".person", would that also
autoamtically rename ".Header .name" to ".Header .person" and ".Line
..name" to ".Line .person"? If not, should the classes in the html be
changed from "name" to "name person" instead of "person"?
 
B

Bob Altman

Göran Andersson said:
As CSS can use multiple identifiers, it's not that simple to determine
what to refactor and what not to refactor. Perhaps you use CSS in a way
that it looks very simple, but it's easy to show an example where it would
be rather complex.

Consider this CSS:

.List span { float: left; }
.Header .name { background: #000; color: #fff; }
.Line .name { color: #009; }
.name { width: 100px; }

And this HTML:

<div class="List Header">
<span class="name">Name</span>
</div>
<div class="List Line">
<span class="name">Arthur</span>
</div>
<div class="List Line">
<span class="name">Trillian</span>
</div>

Now, if I rename the style ".name" to ".person", would that also
autoamtically rename ".Header .name" to ".Header .person" and ".Line
.name" to ".Line .person"? If not, should the classes in the html be
changed from "name" to "name person" instead of "person"?

I don't understand the "if not" option in the example above. As I read the
example, that's equivalent to adding a new "person" rule (in addition to the
existing "name" rule), which is not the same as renaming the "name" rule to
"person". If I rename the style ".name" to ".person" then class "name" no
longer exists and can not be referenced from the HTML. I would expect the
HTML to be modified so that every "computed" reference to class "name" is
changed to "person".

Bob
 
G

Göran Andersson

Bob said:
I don't understand the "if not" option in the example above. As I read
the example, that's equivalent to adding a new "person" rule (in
addition to the existing "name" rule), which is not the same as renaming
the "name" rule to "person". If I rename the style ".name" to ".person"
then class "name" no longer exists and can not be referenced from the
HTML. I would expect the HTML to be modified so that every "computed"
reference to class "name" is changed to "person".

Bob

Yes, but you are missing the point. If you rename the style ".name",
should the styles ".Header .name" and ".Line .name" be automatically
renamed also?
 
B

Bob Altman

Göran Andersson said:
Yes, but you are missing the point. If you rename the style ".name",
should the styles ".Header .name" and ".Line .name" be automatically
renamed also?

You're right, I missed the fact that you have two identifiers in the style
name. What does that syntax do? I did some (brief) searching online and in
the MSDN docs, but I can't find anything that mentions that syntax.

Bob
 
G

Göran Andersson

Bob said:
You're right, I missed the fact that you have two identifiers in the
style name. What does that syntax do? I did some (brief) searching
online and in the MSDN docs, but I can't find anything that mentions
that syntax.

Bob

You can mix any number of class names, id names and element names in the
style selector, and even combine them and describe relations between them.

For example, matching an img element inside a link with class="left",
inside a div with class="Main" inside an element with id="Menu":

#Menu div.Main a.left img { ... }

I find this web site quite useful for understanding how a selector can
be assembled:

http://css.maxdesign.com.au/selectutorial/
 
B

Bob Altman

I find this web site quite useful for understanding how a selector can
be assembled:

http://css.maxdesign.com.au/selectutorial/


Thanks Göran! As I've said in other recent posts, I'm an experienced
desktop and enterprise app kind of guy, but I'm just starting to learn the
Mysterious Ways of the Web Developer. The stuff I've read about CSS up to
now (in the MSDN "how do" docs and on a couple of websites) oversimplified
things (by omitting the concept of selectors) to the point where I was let
to believe that there was a much more linear relationship between CSS rules
and the HTML markup that referenced them.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top