开发者

Multiple CSS class, with a element

开发者 https://www.devze.com 2023-03-30 00:14 出处:网络
I have links in a table. like: <table> <tr> <td><a href=\"lalala\"></a></td>

I have links in a table.

like:

<table>
 <tr>
   <td><a href="lalala"></a></td>
   <td><a href="lalala"></a></td>
   <td><a href="lalala"</a></td>
   <td><a href="lalala"></a></td&开发者_JS百科gt;
 </tr>
</table>

I want to use mutliple classes:

<td class="XYtableItem itemID"><a href="lalala" /></td>

The problem is: I cant reach the a elements in CSS I tried these:

.XYtableItem a {}
a.XYtableItem {}
XYtableItem > a {}

none of these works. I dont rly know this should work or not. +I cant put classes to the a elements, but doesnt matter, not working eiter.


They should work, out of curiosity what CSS rules are you trying to apply to the link ? Bare in mind that there may be some other rules in the CSS overriding your ones, giving you the impression you're not targeting the link correctly.

.XYtableItem a

This one should be good


The first rule should match as that selects any a element that is the descendant of an element with the XYtableItem class.

The second rule will any a with the class XYtableItem and the third any a element that is a descendant of a XTtableItem element - possibly just missing the class selector (.).

Try adding content to your a tag as it shouldn't be self closing.

Example at http://jsfiddle.net/mfhHG/


As other answers suggest, most probably your style might be overriding by something else.. You firebug to inspect the element and trace the style.. it should show you what exactly is being overridden by which style..


There are some problems with your HTML,

<table>
 <tr>
   <td><a href="lalala">Link</a></td>
   <td><a href="lalala">Link2</a></td>
   <td><a href="lalala">Link3</a></td>
   <td><a href="lalala">Link4</a></td>
 </tr>
</table>

And the selectors should be very simple.

Check this example.


<style>
    td.aaa a {
        color: green;
    }
    td.bbb a {
        color: yellow;
    }
</style>

<table>
    <tr>
        <td class="XYtableItem aaa"><a href="lalala">aa</a></td>
        <td class="XYtableItem bbb"><a href="lalala">bb</a></td>
    </tr>
</table>

The above works for me. (Although I have had some problems with some styles like padding etc when using on a tags on IE)

0

精彩评论

暂无评论...
验证码 换一张
取 消