css - 在悬停时缩放一个圆圈,保持边框的宽度

标签 css css-transitions css-transforms

我有一个没有背景、只有边框的圆圈,我希望它在悬停时缩放:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <link type="text/css" rel="stylesheet" href="css/main.css"  />
    <style>
    #circle{
        border: 1px solid black;
        width: 40px;
        height: 40px;
        border-radius: 50%;
        margin: 20% auto;
        transition: all 0.5s ease;
    }
    #circle:hover{
        cursor: pointer;
        transform: scale(6);
        border: 1px solid black;
        transition: all 0.5s ease;
    }
    </style>
</head>
<body>
    <div id="circle">
    </div>
</body>
</html>

这是一个 fiddle :https://jsfiddle.net/u36nfxs0/2/

如您所见,问题在于边框的宽度也会缩放。有什么方法可以缩放保持其边框宽度的圆圈?

谢谢!

最佳答案

不要使用转换,而是调整尺寸(宽度、高度和显式边距:

#circle {
  border: 1px solid black;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  margin: 20% auto 0 auto;
  transition: all 5s ease;
}

#circle:hover {
  cursor: pointer;
  width: 240px;
  height: 240px;
  margin-top: calc(20% - 100px);
}
<div id="circle">
</div>

关于css - 在悬停时缩放一个圆圈,保持边框的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46370819/

相关文章:

CSS - Jumpy Scale 过渡问题

javascript - 3d 框网格(只有两个面)

html - 翻译属性不适用于 div

CSS 防止 div 子元素的多重转换

html - 使用 CSS 使两个链接在悬停在不同链接上时淡入

css - 为什么 transform : scale(xx. y) 从 Browser 变为 Browser

css - 在样式表中定义时不显示背景图像

css - 媒体查询中的两个最大宽度

html - 为什么这个元素在同样大小的容器中会导致溢出?

javascript - 如何设置彼此相邻的图像列表