By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,876 Members | 1,206 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,876 IT Pros & Developers. It's quick & easy.

To match a particular <li> element

P: n/a
Hi at all,
please consider this :
<ul>
<li><a>No link</a></li>
<li><a href="#">This is a link</a></li>
<li><a>No link</a></li>
<li><a href="#">This is a link</a></li>
....................
</ul>
How can I do to match the <li> element that have as son the <a
href="www.----------">??? or viceversa the <li> elements that have only the
<a> into?

Thank you very much
Steel


Jul 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"Steel" <St*********@hotmail.com> wrote:
<li><a>No link</a></li>
<li><a href="#">This is a link</a></li> How can I do to match the <li> element that have as son the <a
href="www.----------">??? or viceversa the <li> elements that have only the
<a> into?


Remove the pointless <a>No link</a> anchor element.

--
Spartanicus
Jul 21 '05 #2

P: n/a
On Fri, 18 Mar 2005 10:09:52 +0100, Steel <St*********@hotmail.com> wrote:
Hi at all,
please consider this :
<ul>
<li><a>No link</a></li>
<li><a href="#">This is a link</a></li>
<li><a>No link</a></li>
<li><a href="#">This is a link</a></li>
...................
</ul>
How can I do to match the <li> element that have as son the <a
href="www.----------">??? or viceversa the <li> elements that have only
the
<a> into?


You can't select an element based on what elements it contains. You can
however select the contents in the list example above:

li a[href] {} /* For CSS2 browsers like Mozilla, Opera and Safari */

or

li a:link, li a:visited {} /* For CSS 1 browsers like MSIE 6 and Netscape
4, works also in CSS2 browsers */
--
Rijk van Geijtenbeek

The Web is a procrastination apparatus:
It can absorb as much time as is required to ensure that you
won't get any real work done. - J.Nielsen

Jul 21 '05 #3

P: n/a
"Steel" wrote in comp.infosystems.www.authoring.stylesheets:
<li><a href="#">This is a link</a></li>


This is broken, unless you actually want the link to take the user
to the top of the current page.

--

Stan Brown, Oak Road Systems, Tompkins County, New York, USA
http://OakRoadSystems.com/
Jul 21 '05 #4

P: n/a
I simply need to match the father (<li>) af a <a> that can have the href or
not
In my menu only the last choice-level have the href but I do not know how
many level are nested.
Steel
"Stan Brown" <th************@fastmail.fm>
wrote:
This is broken, unless you actually want the link to take the user to the top of the current page.
--

Jul 21 '05 #5

P: n/a
Steel wrote:
I simply need to match the father (<li>) af a <a> that can have the href or
not
In my menu only the last choice-level have the href but I do not know how
many level are nested.
Steel

CSS cannot differ between elements of the same type unless they have
different class, id or is unique in that it is the only node within its
hiearchy and the node is known before the page is rendered.
Examples:

<ul>
<li><a class="link"> 1
<li><a class="link"> 1
<li><a class="link"> 1
<li><a class="link" id="somelink"> 1,2
<li><a id="lastlink"> 3
<ul>
<li><a> 4
</ul>
</ul>

1: Styles defined as a.link {} will apply to all with the class="link"
2: Syles defined as a#somelink {} will only apply to an <a> with
id="somelink". The id style wins over class style in a conflict.
3: The style #lastlink will only apply to the <a> with id="lastlink"
4: The style ul li ul li a {} will only apply to <a> inside a <li>
inside a <ul> inside a <li> inside a <ul>

If your page is generated by a script, you can assign a class or id to
the different elements you want to apply special effects to. Otherwise
you must probably use a client side javascript that browses through the
DOM and do the changes there. I am not proficient enough with javascript
to tell you how.
Jul 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.