473,808 Members | 2,835 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

parent selector?

In order to mark links leaving my site, I recently added this rule to my
stylesheet.

A[href][class="offsite"]:after { content: "\2197" }
The character is a northeast-pointing arrow, since that seems to be
fairly common notation for this. I wanted to avoid using an image,
though, and this content rule works great!

My problem is that some of my offsite links are graphics. I don't want
an arrow hanging off my button links. Is it possible to disable this
rule somehow, or change the content back to "", if the anchor contains
an image? I know there is a child selector A>IMG but that selects the
image not the anchor. It seems I need a parent selector, and there is
no A<IMG equivalent.

Am I missing something obvious?

Thanks,
Tim

--
Tim & Alethea
www.ChristTrek.org

Jul 20 '05 #1
25 11954
On Tue, 12 Oct 2004 09:43:39 -0500, Tim & Alethea Larson
<th********@ll. net> wrote:
In order to mark links leaving my site, I recently added this rule to my
stylesheet.

A[href][class="offsite"]:after { content: "\2197" }
The character is a northeast-pointing arrow, since that seems to be
fairly common notation for this. I wanted to avoid using an image,
though, and this content rule works great!

My problem is that some of my offsite links are graphics. I don't want
an arrow hanging off my button links. Is it possible to disable this
rule somehow, or change the content back to "", if the anchor contains
an image? I know there is a child selector A>IMG but that selects the
image not the anchor. It seems I need a parent selector, and there is
no A<IMG equivalent.

Am I missing something obvious?


Assuming all the img anchors are in one section of the page, enclose them
in a div with an id. Then use that id as the parent.
Jul 20 '05 #2
Tim & Alethea Larson <th********@ll. net> wrote:
In order to mark links leaving my site, I recently added this rule to my
stylesheet.

A[href][class="offsite"]:after { content: "\2197" }

The character is a northeast-pointing arrow, since that seems to be
fairly common notation for this. I wanted to avoid using an image,
though, and this content rule works great!
It doesn't, the glyph you are using is not present on my system.
My problem is that some of my offsite links are graphics. I don't want
an arrow hanging off my button links. Is it possible to disable this
rule somehow, or change the content back to "", if the anchor contains
an image? I know there is a child selector A>IMG but that selects the
image not the anchor. It seems I need a parent selector, and there is
no A<IMG equivalent.

Am I missing something obvious?


a.offsite:after {content:"somet hingappropriate "}

<a href="http://localhost/" class="offsite" >foobar</a>
<a href="http://localhost/"><img src="foobar" alt="foobar"></a>
<a href="index.htm ">foobar</a>

--
Spartanicus
Jul 20 '05 #3
Tim & Alethea Larson wrote:
In order to mark links leaving my site, I recently added this rule to
my stylesheet.

A[href][class="offsite"]:after { content: "\2197" }
You can also use

A.offsite[href]:after {}

which you might find easier to read. Better still,

A.offsite:after {}

assuming you have no <A> elements used as target anchors. I use id for
that, so there are no <A> elements in my page without an href attribute.
The drawback is that Netscape 4- will not recognize id for targets. But
its usage is low enough for me that I don't fret about target failures. :-)
The character is a northeast-pointing arrow, since that seems to be
fairly common notation for this. I wanted to avoid using an image,
though, and this content rule works great!
On Opera and Moz, possibly Safari and others, sure. But you do know it
fails on MSIE, right?
My problem is that some of my offsite links are graphics. I don't
want an arrow hanging off my button links. Is it possible to disable
this rule somehow, or change the content back to "", if the anchor
contains an image?
Spartanicus gave you the easiest solution: remove the class "offsite"
from links with images. If you want to keep that class for other
reasons, you can also use multiple classes:
<a href="samesite. html">this link has no icon after it</a>

<a href="http://www.example.com/bar" class="offsite" >this link has a
nifty icon to show that it goes offsite</a>

<a href="http://www.example.com/foo" class="offsite withImg"><img
src="foobar.png " alt="this link does *not* have an icon after it"></a>
A.offsite:after {content:"arrow "}

A.offsite.withI mg:after {content: ""}

I know there is a child selector A>IMG but that selects the image not
the anchor. It seems I need a parent selector, and there is no A<IMG
equivalent.


Correct, there is no parent selector in css 2.

--
Brian (remove "invalid" to email me)
http://www.tsmchughs.com/
Jul 20 '05 #4
Neal wrote:
Assuming all the img anchors are in one section of the page, enclose
them in a div with an id. Then use that id as the parent.

No, they could be anywhere.

Tim

--
Tim & Alethea
www.ChristTrek.org
Jul 21 '05 #5
Spartanicus wrote:
It doesn't, the glyph you are using is not present on my system.


Actually the rule works fine, it's your browser/system that's not up to
par. ;)
a.offsite:afte r{content:"some thingappropriat e"}

<a href="http://localhost/" class="offsite" >foobar</a>
<a href="http://localhost/"><img src="foobar" alt="foobar"></a>
<a href="index.htm ">foobar</a>


You seem to be suggesting I remove the class if the anchor has an image.
That changes the semantics of what I'm doing. The link _is_ offsite,
whether it's text or image, and I should be able to mark it as such. I
don't put classes on things just because I want to hang a style on them,
I put classes on things because it means something. Having
distinguishing styles based on those classes to give a visual cue to the
reader is a nice side-effect.

Tim

--
Tim & Alethea
www.ChristTrek.org
Jul 21 '05 #6
Brian wrote:
Tim & Alethea Larson wrote:
A[href][class="offsite"]:after { content: "\2197" }

You can also use

A.offsite[href]:after {}

..offsite is equivalent to class~="offsite ", which is not the same as my
rule. I purposely want to not match anchors with more than one class,
which possibly (probably) have some other style by virtue of those other
classes.
A.offsite:after {}

assuming you have no <A> elements used as target anchors. I use id for
that, so there are no <A> elements in my page without an href attribute.
The drawback is that Netscape 4- will not recognize id for targets. But
its usage is low enough for me that I don't fret about target
failures. :-)

You're probably right that the [href] is unnecessary in this case. I
started by copying another anchor rule.
The character is a northeast-pointing arrow, since that seems to be
fairly common notation for this. I wanted to avoid using an image,
though, and this content rule works great!

On Opera and Moz, possibly Safari and others, sure. But you do know it
fails on MSIE, right?

I'm not overly concerned about broken browsers. ;) Seriously though,
that is acceptable behavior. IE doesn't try to implement the rule and
do it wrong, it is just ignoring it. It wouldn't be the first time that
IE users get a substandard experience.
Spartanicus gave you the easiest solution: remove the class "offsite"
from links with images. If you want to keep that class for other
reasons, you can also use multiple classes:
<a href="samesite. html">this link has no icon after it</a>

<a href="http://www.example.com/bar" class="offsite" >this link has a
nifty icon to show that it goes offsite</a>

<a href="http://www.example.com/foo" class="offsite withImg"><img
src="foobar.png " alt="this link does *not* have an icon after it"></a>
A.offsite:after {content:"arrow "}

A.offsite.withI mg:after {content: ""}

I shouldn't have to attach a class that says it has an image or not.
This should be apparent from the document tree. It appears that CSS
just has no way of accessing this particular information. Neither
should I have to remove the offsite class. It _is_ an offsite link
whether it is text or graphical, and by removing the class I remove that
meaning.
I know there is a child selector A>IMG but that selects the image not
the anchor. It seems I need a parent selector, and there is no A<IMG
equivalent.

Correct, there is no parent selector in css 2.

Major bummer.

Thanks,
Tim

--
Tim & Alethea
www.ChristTrek.org
Jul 21 '05 #7
Tim & Alethea Larson <th********@ll. net> wrote:
a.offsite:aft er{content:"som ethingappropria te"}

<a href="http://localhost/" class="offsite" >foobar</a>
<a href="http://localhost/"><img src="foobar" alt="foobar"></a>
<a href="index.htm ">foobar</a>


You seem to be suggesting I remove the class if the anchor has an image.
That changes the semantics of what I'm doing. The link _is_ offsite,
whether it's text or image, and I should be able to mark it as such. I
don't put classes on things just because I want to hang a style on them,
I put classes on things because it means something. Having
distinguishi ng styles based on those classes to give a visual cue to the
reader is a nice side-effect.


So? Change the class name.

--
Spartanicus
Jul 21 '05 #8
Tim & Alethea Larson wrote:
Brian wrote:
Spartanicus gave you the easiest solution: remove the class
"offsite" from links with images. If you want to keep that class
for other reasons, you can also use multiple classes:

I shouldn't have to attach a class that says it has an image or not.


Whether you should or should not, I'm afraid you'll have to.
This should be apparent from the document tree. It appears that CSS
just has no way of accessing this particular information.
Correct. Those who wrote the spec might have good reasons for that --
perhaps a parent selector would cost too much in processing overhead.
You'd have to ask them to get a better answer.

There's lots that we can't do without resorting to class, due to
shortcomings in MSIE, the dominant browser. Two fairly straightforward ones:

foo[id] {}

foo > bar {}

And lots more. My code would be a bit more readable if it weren't for
that os component we all love to hate.
Neither should I have to remove the offsite class. It _is_ an
offsite link whether it is text or graphical, and by removing the
class I remove that meaning.


What meaning is that? Your classname only has meaning to you. No ua will
use it; no ua can use it, since it's your namespace. I think you're not
seeing the big picture.

--
Brian (remove "invalid" to email me)
Jul 21 '05 #9
Tim & Alethea Larson wrote:
The character is a northeast-pointing arrow, since that seems to be
fairly common notation for this. I wanted to avoid using an image,
though, and this content rule works great!


Why do you want to avoid using an image?

I'm no CSS expert, and this may require changes to your html, but this works
well for me:

a.offsite span.linkText {
padding-right:24px;
background-image:url(/offsite.gif);
background-repeat:no-repeat;
background-position:center right;
}

<a class="offsite" href="site"><sp an class="linkText ">Offsite!</span></a>

Just a thought.

--
Matt Kruse
http://www.JavascriptToolbox.com
Jul 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2798
by: Zane | last post by:
Hi, I am having some grieve with the following part of my CSS, basically when using a composite selector using an ID as the first element the it doesn't display the expected results. Am I doing something incorrect? For example my CSS goes something like this: #leftnavbar a:link { color: #333; text-decoration: none; }
2
3864
by: tagbert | last post by:
I'm trying to localize the setting of colors on a series of webpages by defining color palettes that will be used for various page areas. I've defined some palette classes like .clrLt, .clrMd, .clrDk and associated link colors using selectors. One of the aims is to ensure that matching text color, background, and link colors are maintained. These palettes are applied as multiple classes to various page modules which also have abstract...
19
4911
by: Thomas Mlynarczyk | last post by:
Hello, The following gives different results in IE and "Non-IE" browsers: <div style="background-color: green; width: 200px"> <div style="margin-top: 20px; background-color: red"> Hello </div> </div>
1
1687
by: Gt394 | last post by:
I have the following tables. tbl_customer CustID Primary key Custname Custaddr tbl_Quote QuoteNo Primary key ProjectName
2
2152
by: Chris Sharman | last post by:
See http://services.ccagroup.co.uk/testform.htm Looks as intended in firefox, is valid (bulk of inputs centred in a div occupying the left half of the page). ie ignores the child selector, positioning everything aligned left. I'm familiar with http://w3development.de/css/hide_css_from_browsers/ I thought the ie child selector bug only occurred where there were no spaces (parent>child) - I'd thought it worked when there were (parent >
3
2010
by: RobG | last post by:
The link below is to a CSS selector test suite that tests 6 popular libraries: <URL: http://ajaxian.com/archives/slickspeed-css-selector-testsuite It might be of interest to some. -- Rob
0
591
by: Stanimir Stamenkov | last post by:
Wed, 07 May 2008 08:26:43 -0800, /darius/: In short no. One of the reasons is it makes the progressive rendering harder if not impossible. Next I've heard there are issues with the performance in cases of dynamic DOM and style changes, but I'm not really a CSS implementor and cannot give you further details.
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10631
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10374
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10374
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10114
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7651
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6880
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5686
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3011
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.