Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/74.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_Xhtml - Fatal编程技术网

Html 可能是一个相当简单的CSS问题

Html 可能是一个相当简单的CSS问题,html,css,xhtml,Html,Css,Xhtml,我有这个CSS规则来获得按下链接的“按下”效果: a:active { position: relative; top: 1px; } 现在,这一切正常,但我想写一条规则,在链接图像上禁用此功能,如下所示: <a href="#"><img src="..." /></a> 可能吗 谢谢。您可以逆转对孩子的影响: a:active img { position: relative; top: -1px; } 您可以反转

我有这个CSS规则来获得按下链接的“按下”效果:

a:active {
    position: relative;
    top: 1px;
}
现在,这一切正常,但我想写一条规则,在链接图像上禁用此功能,如下所示:

<a href="#"><img src="..." /></a>

可能吗


谢谢。

您可以逆转对孩子的影响:

a:active img {
    position: relative;
    top: -1px;
}

您可以反转对子对象的影响:

a:active img {
    position: relative;
    top: -1px;
}

我相信您可以将最初的风格改为:

a {
    padding-bottom: 1px;
}

a:active {
    padding-top: 1px;
    padding-bottom: 0;
}
然后将其用于图像:

a:active img {
    position: relative;
    top: -1px;
}

还没有机会测试它,但我认为这应该可以做到。

我相信您可以将初始样式更改为:

a {
    padding-bottom: 1px;
}

a:active {
    padding-top: 1px;
    padding-bottom: 0;
}
然后将其用于图像:

a:active img {
    position: relative;
    top: -1px;
}

我还没有机会测试它,但我认为这应该可以做到。

我还没有尝试过,但我认为它应该可以工作

a:active {
    position: relative;
    top: 1px;
}

a:active img{
    position: relative;
    top: -1px;
}

另一个解决方案是在所有包含图像的
a
标记中添加一个类

我还没有尝试过这个方法,但我认为应该可以

a:active {
    position: relative;
    top: 1px;
}

a:active img{
    position: relative;
    top: -1px;
}

另一种解决方案是在包含图像的所有
a
标记中添加一个类

不幸的是,还没有一个选择器来区分仅文本链接到图像链接。但是,您可以通过以下方式逃脱:

p a:active {
    position: relative;
    top: 1px;
}

如果你的链接都包含在段落标记中,这将起作用,并且不会影响你的图像标记。您可以为H1、H2等任何需要包含的标记创建一个选择器。

不幸的是,目前还没有一个选择器来区分文本链接和图像链接。但是,您可以通过以下方式逃脱:

p a:active {
    position: relative;
    top: 1px;
}
如果你的链接都包含在段落标记中,这将起作用,并且不会影响你的图像标记。您可以为H1、H2等任何需要包含的标记创建一个标记