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

Hi,

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

e.g.


<!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>


Many thanks