选择父级的同级 [英] Selecting a sibling of a parent

查看:96
本文介绍了选择父级的同级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个HTML:

<font>
   <b>
      <a href="profile/user">user</a>
   </b>
   <font>message</font>
</font>

我知道字体标签很烂,但他们想要字体标签,所以我把字体标签。
我可以选择用户的名字与

a [href * =user]

想要能够选择包含消息的字体。

I know the font tag sucks, but they wanted font tags so I put font tags. I can select the user's name with a[href*="user"] but I want to be able to select the font containing the message, too. Is that possible with CSS?

推荐答案

您不能使用CSS选择父级 - 您可能会发现这是一个有趣的主题阅读: 为什么我们没有父级选择器。不过,您可以执行下列操作之一:

You cannot select the parent with CSS - you might find this an interesting read on the topic: Why we don't have a parent selector. However, you can do one of the following:

1。使用一些JavaScript

1. Use a bit of JavaScript

2。将HTML更改为

<font>
   <a href="profile/user"><b>user</b></a>
   <font>message</font>
</font>

您可以这样做:

a[href*="user"] + font { /* YOUR STYLES HERE */ }

这篇关于选择父级的同级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆