宽度和高度 100% 不适用于弹出图像
Width and Height 100% doesn't work on pop up image
我有一个“联系我”按钮,但是,每当有人将鼠标悬停在该按钮上时,我希望显示全屏图像背景。但是,此图像不是全屏的。
a {
text-decoration: none;
color: white;
/*Let's Chat colour*/
}
.Oval {
position: relative;
font-family: 'Open Sans', sans-serif;
top: 510px;
text-align: center;
font-size: 25px;
text-color: white;
left: 30%;
z-index: 75;
background-color: orange;
width: 140px;
height: auto;
background: #162129;
border-radius: 40px;
padding: 0px;
text-decoration: none;
}
.Oval:hover {
position: relative;
}
.Oval:hover:after {
content: url(Lightning1.JPG);
display: block;
position: absolute;
center: 100%;
top: -510px;
opacity: 0.5;
z-index: -10;
height: 100%;
width: 100%;
}
<div class="Oval"><a href="mailto:">Let's Chat</a></div>
a {
text-decoration: none;
color: white;
/*Let's Chat colour*/
}
.Oval {
position: relative;
font-family: 'Open Sans', sans-serif;
top: 510px;
text-align: center;
font-size: 25px;
text-color: white;
left: 30%;
z-index: 75;
background-color: orange;
width: 140px;
height: auto;
background: #162129;
border-radius: 40px;
padding: 0px;
text-decoration: none;
}
.Oval:hover {
position: inherit;
left:0;
}
.Oval:hover a{display:none;}
.Oval:hover:after {
content:'';
background: url(https://i.imgur.com/QgfTfOU.jpg);
background-size:cover;
display: block;
position: absolute;
center: 100%;
top:0;
left:0;
opacity: 0.5;
z-index: 1;
height: 100%;
width: 100%;
}
<div class="Oval"><a href="mailto:">Let's Chat</a></div>
CSS 属性 position:absolute 准确地说:
It is positioned relative to its closest positioned ancestor
- 如果你想让背景图片占满屏幕space,
然后可以用 CSS 属性 position:fixed 来实现
使用它,您可以将其放置在相对于视口的位置。
然后将顶部、底部、左侧、右侧值精确到
0
以获得
元素到所有视口。
例如:
a {
text-decoration: none;
color: white;
/*Let's Chat colour*/
}
.Oval {
position: relative;
font-family: 'Open Sans', sans-serif;
top: 510px;
text-align: center;
font-size: 25px;
text-color: white;
left: 30%;
z-index: 75;
background-color: orange;
width: 140px;
height: auto;
background: #162129;
border-radius: 40px;
padding: 0px;
text-decoration: none;
}
.Oval:hover {
position: relative;
}
/* Original
.Oval:hover:after {
content: url(Lightning1.JPG);
display: block;
position: absolute;
center: 100%;
top: -510px;
opacity: 0.5;
z-index: -10;
height: 100%;
width: 100%;
}
*/
.Oval:hover::after {
content: url(https://i.imgur.com/QgfTfOU.jpg);
display: block;
position: fixed;
opacity: 0.5;
z-index: -10;
top: 0;
border: 0;
left: 0;
right: 0;
}
<div class="Oval"><a href="mailto:">Let's Chat</a></div>
- 如果你只想在
div.Oval
上使用背景图片,那么你应该 CSS 属性 position:absolute
a {
text-decoration: none;
color: white;
/*Let's Chat colour*/
}
.Oval {
position: relative;
font-family: 'Open Sans', sans-serif;
top: 510px;
text-align: center;
font-size: 25px;
text-color: white;
left: 30%;
z-index: 75;
background-color: orange;
width: 140px;
height: auto;
background: #162129;
border-radius: 40px;
padding: 0px;
text-decoration: none;
clip-path: border-box; /* Added */
overflow: hidden; /* Added */
}
/* Original
.Oval:hover {
position: relative;
}
*/
/* Original
.Oval:hover:after {
content: url(Lightning1.JPG);
display: block;
position: absolute;
center: 100%;
top: -510px;
opacity: 0.5;
z-index: -10;
height: 100%;
width: 100%;
}
*/
/* Added */
.Oval:hover::after {
content: '';
background: url(https://i.imgur.com/QgfTfOU.jpg);
background-size: auto;
background-size: cover;
display: block;
position: absolute;
opacity: 0.5;
z-index: -10;
top: 0;
border: 0;
left: 0;
right: 0;
bottom: 0;
}
<div class="Oval"><a href="mailto:">Let's Chat</a></div>
您需要在 .Oval:hover:after
上添加 pointer-events: none;
+z-index: -1;
属性 类似下面的代码片段。
我希望下面的代码片段对你有很大帮助。
a {
text-decoration: none;
color: white;
}
.Oval {
position: relative;
font-family: 'Open Sans', sans-serif;
top: 100px;
text-align: center;
font-size: 25px;
color: white;
left: 50%;
margin-left: -70px;
background-color: orange;
width: 140px;
height: auto;
background: #162129;
border-radius: 40px;
padding: 0px;
text-decoration: none;
}
.Oval:hover:after {
content:'';
background: url(https://i.imgur.com/QgfTfOU.jpg);
background-size: cover;
display: block;
position: fixed;
top: 0;
left: 0;
z-index: -1;
height: 100%;
width: 100%;
pointer-events: none;
}
<div class="Oval"><a href="mailto:">Let's Chat</a></div>
我有一个“联系我”按钮,但是,每当有人将鼠标悬停在该按钮上时,我希望显示全屏图像背景。但是,此图像不是全屏的。
a {
text-decoration: none;
color: white;
/*Let's Chat colour*/
}
.Oval {
position: relative;
font-family: 'Open Sans', sans-serif;
top: 510px;
text-align: center;
font-size: 25px;
text-color: white;
left: 30%;
z-index: 75;
background-color: orange;
width: 140px;
height: auto;
background: #162129;
border-radius: 40px;
padding: 0px;
text-decoration: none;
}
.Oval:hover {
position: relative;
}
.Oval:hover:after {
content: url(Lightning1.JPG);
display: block;
position: absolute;
center: 100%;
top: -510px;
opacity: 0.5;
z-index: -10;
height: 100%;
width: 100%;
}
<div class="Oval"><a href="mailto:">Let's Chat</a></div>
a {
text-decoration: none;
color: white;
/*Let's Chat colour*/
}
.Oval {
position: relative;
font-family: 'Open Sans', sans-serif;
top: 510px;
text-align: center;
font-size: 25px;
text-color: white;
left: 30%;
z-index: 75;
background-color: orange;
width: 140px;
height: auto;
background: #162129;
border-radius: 40px;
padding: 0px;
text-decoration: none;
}
.Oval:hover {
position: inherit;
left:0;
}
.Oval:hover a{display:none;}
.Oval:hover:after {
content:'';
background: url(https://i.imgur.com/QgfTfOU.jpg);
background-size:cover;
display: block;
position: absolute;
center: 100%;
top:0;
left:0;
opacity: 0.5;
z-index: 1;
height: 100%;
width: 100%;
}
<div class="Oval"><a href="mailto:">Let's Chat</a></div>
CSS 属性 position:absolute 准确地说:
It is positioned relative to its closest positioned ancestor
- 如果你想让背景图片占满屏幕space,
然后可以用 CSS 属性 position:fixed 来实现
使用它,您可以将其放置在相对于视口的位置。
然后将顶部、底部、左侧、右侧值精确到
0
以获得 元素到所有视口。
例如:
a {
text-decoration: none;
color: white;
/*Let's Chat colour*/
}
.Oval {
position: relative;
font-family: 'Open Sans', sans-serif;
top: 510px;
text-align: center;
font-size: 25px;
text-color: white;
left: 30%;
z-index: 75;
background-color: orange;
width: 140px;
height: auto;
background: #162129;
border-radius: 40px;
padding: 0px;
text-decoration: none;
}
.Oval:hover {
position: relative;
}
/* Original
.Oval:hover:after {
content: url(Lightning1.JPG);
display: block;
position: absolute;
center: 100%;
top: -510px;
opacity: 0.5;
z-index: -10;
height: 100%;
width: 100%;
}
*/
.Oval:hover::after {
content: url(https://i.imgur.com/QgfTfOU.jpg);
display: block;
position: fixed;
opacity: 0.5;
z-index: -10;
top: 0;
border: 0;
left: 0;
right: 0;
}
<div class="Oval"><a href="mailto:">Let's Chat</a></div>
- 如果你只想在
div.Oval
上使用背景图片,那么你应该 CSS 属性position:absolute
a {
text-decoration: none;
color: white;
/*Let's Chat colour*/
}
.Oval {
position: relative;
font-family: 'Open Sans', sans-serif;
top: 510px;
text-align: center;
font-size: 25px;
text-color: white;
left: 30%;
z-index: 75;
background-color: orange;
width: 140px;
height: auto;
background: #162129;
border-radius: 40px;
padding: 0px;
text-decoration: none;
clip-path: border-box; /* Added */
overflow: hidden; /* Added */
}
/* Original
.Oval:hover {
position: relative;
}
*/
/* Original
.Oval:hover:after {
content: url(Lightning1.JPG);
display: block;
position: absolute;
center: 100%;
top: -510px;
opacity: 0.5;
z-index: -10;
height: 100%;
width: 100%;
}
*/
/* Added */
.Oval:hover::after {
content: '';
background: url(https://i.imgur.com/QgfTfOU.jpg);
background-size: auto;
background-size: cover;
display: block;
position: absolute;
opacity: 0.5;
z-index: -10;
top: 0;
border: 0;
left: 0;
right: 0;
bottom: 0;
}
<div class="Oval"><a href="mailto:">Let's Chat</a></div>
您需要在 .Oval:hover:after
上添加 pointer-events: none;
+z-index: -1;
属性 类似下面的代码片段。
我希望下面的代码片段对你有很大帮助。
a {
text-decoration: none;
color: white;
}
.Oval {
position: relative;
font-family: 'Open Sans', sans-serif;
top: 100px;
text-align: center;
font-size: 25px;
color: white;
left: 50%;
margin-left: -70px;
background-color: orange;
width: 140px;
height: auto;
background: #162129;
border-radius: 40px;
padding: 0px;
text-decoration: none;
}
.Oval:hover:after {
content:'';
background: url(https://i.imgur.com/QgfTfOU.jpg);
background-size: cover;
display: block;
position: fixed;
top: 0;
left: 0;
z-index: -1;
height: 100%;
width: 100%;
pointer-events: none;
}
<div class="Oval"><a href="mailto:">Let's Chat</a></div>