图像边框悬停不起作用

时间:2022-11-05 13:53:45

I have an image centered on the screen that I would like a border around, which when hovered over changes color. I am trying to do this as you can see in the code below, but the problem is that the image just keeps being a link but no border, what is wrong?

我有一个以屏幕为中心的图像,我想要一个边框,当它在变色时盘旋。我试图这样做,你可以在下面的代码中看到,但问题是图像只是一个链接但没有边框,有什么问题?

html code:

HTML代码:

<div id="container">

    <div id="content">

        <div class="10Img">
            <a href=""><img src="10Pimg.png" alt="10img" style="width:900px; height:200px"></a>
        </div>

    </div>


    </div>

css code:

css代码:

#content{
    padding-bottom: 200px;
    position: absolute;
    float: left;
    left: 50%;
    margin-left: -450px;
    top: 200px;
}

#container{
    height:100%;
}

.10Img{
    border: 2px solid grey;
}

.10Img a:hover{
    outline: 2px solid black;
}

4 个解决方案

#1


1  

The main issue is you are starting your class name with a numerical character change 10Img and start it with an alphabetic character. Ex. i change it from 10Img to aImg

主要问题是您正在使用数字字符更改10Img开始您的类名,并以字母字符开头。防爆。我把它从10Img改为aImg

Then you can use

然后你可以使用

.aImg  img {
 border: 2px solid grey;
}

or only

或者只是

.aImg {
     border: 2px solid grey;
    }

#2


0  

Try this: Demo

试试这个:演示

a img {
    border: 2px solid grey;
}
a img:hover {
    border: 2px solid black;
}

#3


0  

See This Demo

见本演示

.Img{border: 2px solid grey;}
.Img a:hover{
outline: 2px solid black;}

Note: Class Name can not start with integer.

注意:类名称不能以整数开头。

Refer This for Rules regarding naming.

有关命名的规则,请参阅此处。

#4


0  

Your css class 10Img doesn't work, because css class names must not begin with a number, see:

您的css类10Img不起作用,因为css类名称不能以数字开头,请参阅:

Which characters are valid in CSS class names/selectors?

哪些字符在CSS类名/选择器中有效?

So if you call your class Img10 instead of 10Img it should work.

因此,如果你打电话给你的班级Img10而不是10Img它应该工作。

<div id="container">
    <div id="content">
        <div class="Img10">
            <a href=""><img src="http://dummyimage.com/900x200/000/fff" alt="10img" style="width:900px; height:200px" /></a>
        </div>
    </div>
</div>

Also you may want to have the :hover border on the div instead on the a:

此外,您可能希望在div上使用:hover border而不是a:

#content{
    padding-bottom: 200px;
    position: absolute;
    float: left;
    left: 50%;
    margin-left: -450px;
    top: 200px;
}

#container{
    height:100%;
}

.Img10{
    border: 2px solid grey;
}

.Img10:hover{
    outline: 2px solid black;
}

Here is a working fiddle: http://jsfiddle.net/k2Ld7yfe/

这是一个工作小提琴:http://jsfiddle.net/k2Ld7yfe/

#1


1  

The main issue is you are starting your class name with a numerical character change 10Img and start it with an alphabetic character. Ex. i change it from 10Img to aImg

主要问题是您正在使用数字字符更改10Img开始您的类名,并以字母字符开头。防爆。我把它从10Img改为aImg

Then you can use

然后你可以使用

.aImg  img {
 border: 2px solid grey;
}

or only

或者只是

.aImg {
     border: 2px solid grey;
    }

#2


0  

Try this: Demo

试试这个:演示

a img {
    border: 2px solid grey;
}
a img:hover {
    border: 2px solid black;
}

#3


0  

See This Demo

见本演示

.Img{border: 2px solid grey;}
.Img a:hover{
outline: 2px solid black;}

Note: Class Name can not start with integer.

注意:类名称不能以整数开头。

Refer This for Rules regarding naming.

有关命名的规则,请参阅此处。

#4


0  

Your css class 10Img doesn't work, because css class names must not begin with a number, see:

您的css类10Img不起作用,因为css类名称不能以数字开头,请参阅:

Which characters are valid in CSS class names/selectors?

哪些字符在CSS类名/选择器中有效?

So if you call your class Img10 instead of 10Img it should work.

因此,如果你打电话给你的班级Img10而不是10Img它应该工作。

<div id="container">
    <div id="content">
        <div class="Img10">
            <a href=""><img src="http://dummyimage.com/900x200/000/fff" alt="10img" style="width:900px; height:200px" /></a>
        </div>
    </div>
</div>

Also you may want to have the :hover border on the div instead on the a:

此外,您可能希望在div上使用:hover border而不是a:

#content{
    padding-bottom: 200px;
    position: absolute;
    float: left;
    left: 50%;
    margin-left: -450px;
    top: 200px;
}

#container{
    height:100%;
}

.Img10{
    border: 2px solid grey;
}

.Img10:hover{
    outline: 2px solid black;
}

Here is a working fiddle: http://jsfiddle.net/k2Ld7yfe/

这是一个工作小提琴:http://jsfiddle.net/k2Ld7yfe/