gpt4 book ai didi

html - 内联 SVG 元素移动悬停区域

转载 作者:太空宇宙 更新时间:2023-11-03 18:03:26 25 4
gpt4 key购买 nike

我一直在自学 HTML 和 CSS,最近开始接触 SVG,因为我在寻找跨浏览器的文本渐变。我设置了一个小按钮的样式,覆盖了一个 div 以创建阴影透明效果,一个 SVG 文本特定的 div 来避免一些不透明问题,然后 SVG 文本位于按钮中间。

我还设计了一个悬停区域以使背景图像恢复可见。

问题来了:

在 Firefox 和 Opera 中,元素将 :hover 区域向下和向右扩展大约 50 像素。

但是,在 Chrome 和 Safari 中,这很好。

我试过弄乱边距和填充,但我想知道这是否只是 SVG 兼容性问题?

另外,附加的代码纯粹是为了实验目的,它不是为了客户或工作或任何东西。

这是 HTML:

<!DOCTYPE html>
<html>
<head>
<title>Testing out some designs</title>
<link rel="stylesheet" tyle="text/css" href="stylesheet.css"/>
</head>

<body>
<div class="artBox">
<div class="artBoxButton">
<div class="buttonSVG">
<svg>
<defs>
<linearGradient id="txtgrad" x1="0%" y1="0%" x2="0%" y2="100%">
<stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/>
<stop offset="100%" style="stop-color:rgb(0,0,0);stop-opacity:1"/>
</linearGradient>
</defs>
<text
fill="url(#txtgrad)"
style="font-family:'Helvetica Neue','Helvetica','Verdana','Arial',sans-serif;
font-size:30px;
font-weight:200"
x="15"
y="35">Read More</text>
</svg>
</div>
</div>
</div>

</body>
</html>

这是 CSS:

* {
margin: 0px;
padding: 0px;
}
.artBox {
width: 260px;
height: 89px;
border-radius: 10px;
position: relative;
top: 10em;
left: 10em;
background-image: url('http://i.imgur.com/ki4OY5X.png');
background-repeat: no-repeat;
}
.artBoxButton {
text-align: center;
width: 260px;
height: 89px;
background-color: #e6e6e6;
opacity: 0.9;
border-radius: 10px;
box-shadow: 0px 1px 1px 1px #b2b2b2;
margin: 0px;
}
.artBoxButton:hover {
opacity: 0.5;
cursor: pointer;
}
.buttonSVG {
width: 160px;
height: 50px;
position: relative;
left: 50px;
top: 19.5px;
opacity: 1.0;
}

再说一次,我只写了大约两周的 HTML 和 CSS,请温柔一点..

最佳答案

您没有为 <svg> 指定高度或宽度元素。我想你想要的要么是每个 100%,要么是 160 像素的高度和 50 像素的宽度。

关于html - 内联 SVG 元素移动悬停区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25085634/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com