tags:

views:

44

answers:

5

How to know the correct selector/group of selector for any html element quickly? I'm working on very long bloated html code. and want to apply css on some specfic areas but it's taking to so much time to find a right css selector for any deeply nested html tag in tables.

for example

#id1 #id2 .class1 .class2 table.no1 tbody td

Is there any quick way or tool to know perfect css selector for any needed elemnt quickly?

I also need to override some css on some elements?

Edit:

After to get answer from @BalucC

In addition i also found this tool for IE users it work same like Web developer toolbar"

MRI: test your selectors

MRI is a bookmarklet for Internet Explorer 6+, and Webkit and Mozilla based browsers (including Safari, Firefox, Camino or Mozilla). Use it to test and play with selectors. http://www.westciv.com/mri/

See screenshot here

+1  A: 

IMO, Firebug is the best tool suited to your case. Just "inspect" the page and click on the element either in the page layout or the code itself.

Soufiane Hassou
If you don't have Firefox, there is a similar functionality in Safari.
kiamlaluno
no it's not works like i want
metal-gear-solid
it's only shows if something is defined in css already otherwise it shows element properties
metal-gear-solid
A: 

I use this to show me tag hierarchy.

http://westciv.com/xray/

Also, you might try Firebug:

https://addons.mozilla.org/en-US/firefox/addon/1843

EDIT Due to addition information provided:

To override a CSS rule, use "!important". For example,

<style type="text/css">
#id-to-overwrite {
width:25px !important;
}

</style>
jchapa
But x-ray doesn't show any info about #id and .classes it only shows html tag
metal-gear-solid
+1  A: 

No automated tool can know your intent. For example which of these is correct?

td { background: yellow; }
tbody td { background: yellow; }
table table td { background: yellow; }
tr.odd td { background: yellow; }

It's impossible to say without knowing your intent. You may want to deliberate include and/or include elements not only on this page but other pages that also use the same stylesheet. Relevant elements may or may not exist on that page based on dynamic conditions and criteria that determine if they are created.

Short answer? No.

cletus
+1. Backgrounds and Borders are the quickest ways of debugging.
Nimbuz
+1  A: 
  • Firebug for Firefox
  • Web Inspector for Webkit, Safari and Chrome
  • IE Developer Toolbar for Internet Explorer
  • XyleScope and CSSEdit for Mac
Nimbuz
+2  A: 

The Web Developer Toolbar helps me a lot with this. Just do Ctrl+Shift+F, click the element of interest and check the element chain in the bottom of the toolbar or the Ancestors listing.

Here's a screen (click for full):

BalusC
Cool. this is the answer
metal-gear-solid
You're welcome.
BalusC
I found same purpose tool for other browser also , see my edited question
metal-gear-solid