Допустим, я хочу применить правило CSS ко всем якорям тогда и только тогда, когда:
href начинается точно с «http: // www.»; *а также *target имеет точное значение _blank.Как мне представить этот а также как комбинатор?
Если я сделаю именно это, он выполнит операцию или же. Сам синтаксис делает очевидным, что это будет или же.
a[href^ = "http://www."]::after, a[target = "blank"]::after {
content : "->"
}
Есть комбинатор а также?
Рассмотрим полный пример ниже.
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>a[href^ = "http://www."][target = "_blank"]::after { content : "->" }; должен работать, не так ли?
a[href^ = "http://www."], и все же вам все равно нужно спросить?
@ Джереми Спасибо. Я этого не знал. Это действительно работает. :-)
@CBroe Не совсем очевидно, что компоненты селектора атрибутов податливы, как вы это делаете. Кто-то должен указать вам на это, как вы только что сделали. Это не означает недостаток интеллекта у человека, задающего вопрос.
Добавлен более конкретный дубликат, хотя общий случай уже охватывает его, говоря, что «селекторы атрибутов ничем не отличаются от любого другого простого селектора».






Конечно,
Поместите оба атрибута друг за другом (без пробела)
a[href^ = "http://www."][target = "_blank"]
Также обратите внимание, что я исправил опечатку, вы пропустили подчеркивание перед пробелом.
p {
font-weight: bold;
}
a[href^ = "http://www."][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>
Почему бы вам не определить класс и не добавить его к тем, которые вы хотите включить, включая эту атрибуцию?