SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2007
    Posts
    87
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    giving a <ul> without a class under an <a> with a class?

    Hi there,

    I am trying to apply a style to a <ul> element, but I cannot give the <ul> a class because of the way the script is written. There is an <a> tag directly above this which has a class.

    Is there a way I can give the <ul> a class or style based on the <a> class?

    This is what my code looks like:

    <a class="myclass"></a>
    <ul>
    <li>

    So, I want to style the <ul> without giving it a class.

    Is this possible?

    Thanks

  2. #2
    The CSS Clinic is open silver trophybronze trophy
    Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    39,784
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Hi,

    You can use the adjacent sibling selector to select the ul that folows the .myclass element.

    e.g.

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Untitled Document</title>
    <style type="text/css">
    .myclass + ul { background:red }
    </style>
    </head>
    
    <body>
    <a class="myclass"></a>
    <ul>
    		<li>test red</li>
    </ul>
    <ul>
    		<li>test not red</li>
    </ul>
    </body>
    </html>

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2007
    Posts
    87
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Many thanks


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •