我一直在教自己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%或160px的高度和50px的宽度。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句