Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 特定CSS选择器-环绕元素_Html_Css_Css Selectors - Fatal编程技术网

Html 特定CSS选择器-环绕元素

Html 特定CSS选择器-环绕元素,html,css,css-selectors,Html,Css,Css Selectors,我有以下标记: <a><div class="action_button">Log In</div></a> 但它会影响所有链接,我只想影响.action\u按钮周围的链接。为什么不只是: a .action_button:hover{ text-decoration:none; } <a class="action_button"></a> 我不认为在a中有一个DIV有什么意义。如果希望锚定是一个块,只需直接

我有以下标记:

<a><div class="action_button">Log In</div></a>
但它会影响所有链接,我只想影响
.action\u按钮周围的链接。

为什么不只是:

a .action_button:hover{
    text-decoration:none;
}
<a class="action_button"></a>

我不认为在a中有一个DIV有什么意义。如果希望锚定是一个块,只需直接在该锚定上设置
display:block

我会稍微改变一下代码,
应该嵌套在
中,因为DIV是一个块元素,锚定标记是内联的

然后,您可以简单地使用以下各项:

<style>
    .action_button a       {text-decoration:underline; }
    .action_button a:hover {text-decoration:none; }
</style>

.action_按钮a{文本装饰:下划线;}
.action_按钮a:悬停{文本装饰:无;}

我认为您需要向包含按钮的“a”元素添加一个类。您不能构建另一个方向的选择器。

您可以使用JQuery向每个具有div的“a”添加一个类,并使用class.action\u按钮

$("a").has("div.action_button").addClass("myclass");
然后,显然,使用该类来选择“a”标记


内联元素中可能存在重复的never-put block元素这是一个坏消息,我建议您将
action\u按钮
类移动到
a
并对其进行样式设置,使其行为类似于块元素。你不需要显式地创建一个
div
,它的功能就像一个块元素一样。这种样式是
div
而不是
a
jQuery非常棒。CSS问题的Javascript解决方案,没有那么多。
<style>
    .action_button a       {text-decoration:underline; }
    .action_button a:hover {text-decoration:none; }
</style>
$("a").has("div.action_button").addClass("myclass");