Let's say I want to apply a CSS rule to all anchors, if and only if:
- Their
href
attribute starts with exactly "http://www."; *and * - Their
target
attribute has the exact value_blank
.
How do I represent this and as a combinator?
If I do just this, it performs an or operation. The syntax itself makes it obvious that it will be an or.
a[href^="http://www."]::after, a[target="blank"]::after {
content : "->"
}
Is there an and combinator?
Consider the full example below.
p {
font-weight: bold;
}
a[href^="http://www."]::after, a[target="blank"]::after {
content : "->"
}
<p>Valid ones that I'd like the rule to match</p>
<a href = "http://www.google.com"
target = "_blank">Google</a>
<br />
<a href = "http://www.yahoo.com"
target = "_blank">Yahoo!</a>
<br />
<p>Invalid ones that I'd like the rule NOT to match</p>
<a href = "http://www.microsoft.com">Microsoft</a>
<br />
<a target = "_blank">Anchor without href</a>
<br />
<a href = "NamedAnchor"
target = "_blank">Amazon within this document</a>
<br />
<a href = "https://www.facebook.com"
target = "_blank">Facebook</a>
<br />
<a href = "http://apple.com"
target = "_blank">Apple</a>
<p>Observe how even the anchor <i>Microsoft</i> gets
selected by the combinator because the anchor starts with
the right <code>href</code> even though it does not have
the <code>target</code> attribute</p>