作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如果我将鼠标悬停在矩形上,边框大小会超过矩形大小。我知道因为父节点宽度是 100
这就是显示矩形边框的原因。
如果我将父节点宽度设置为 40
,它工作正常但我需要相同的行为而不更改父节点的 width
和 stroke-width
.
我怎样才能做到这一点?
// In mouse hover, I have set the style:
var links = $('#ch');
links.hover(function() {
$('#ch').attr('class', 'st');
}, function() { //mouseout
$('#ch').attr('class', '');
});
.st {
stroke-width: 60px;
stroke: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<svg id='par' width="100" height="40">
<rect id='ch' width="40" height="40" style="fill:rgb(0,0,255)" />
</svg>
最佳答案
阻止 svg 溢出的是你的 UA 样式(在 chrome 上)中的 svg:not(:root){overflow:hidden}
,
因此,如果您将它设置为visible
,它将起作用:
svg:not(:root) { overflow : visible; }
关于javascript - 如何在 svg 中设置确切的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30393980/
我是一名优秀的程序员,十分优秀!