css - 为什么CSS框改变大小时Border-Radius比率会改变
问题描述
下面2个框的border-radius量虽然相同,但显示的结果不同。这是什么原因?我们怎样才能让它在每个盒子里看起来都一样。我们是否必须根据盒子的大小进行数学运算?(我说的是为什么框 2 不那么圆。)
我知道这是一种视错觉,但考虑到盒子的大小,我希望它看起来一样。
* {
margin: 1rem;
}
.box {
width: 10rem;
height: 5rem;
background-color: black;
border-radius: 3rem;
}
.box2 {
width: 20rem;
height: 10rem;
background-color: black;
border-radius: 3rem;
}
<div class="box"></div>
<div class="box2"></div>
当我使用百分比时,边界半径会变得参差不齐。
* {
margin: 1rem;
}
.box {
width: 10rem;
height: 5rem;
background-color: black;
border-radius: 20%;
}
.box2 {
width: 20rem;
height: 10rem;
background-color: black;
border-radius: 20%;
}
<div class="box"></div>
<div class="box2"></div>
解决方案
您可以定义border-radius
百分比。
* {
margin: 1rem;
}
.box {
width: 10rem;
height: 5rem;
background-color: black;
border-radius: 15%/30%;
}
.box2 {
width: 20rem;
height: 10rem;
background-color: black;
border-radius: 15%/30%;
}
<div class="box"></div>
<div class="box2"></div>
推荐阅读
- sorting - Proc Report 降序排序
- reactjs - 如何要求接口成员提供响应数据?
- firebase - 为“任何拥有链接的人都可以查看”风格的功能公开文档 ID 的安全性
- ios - XCode:如何调整 UIStackView 中的项目
- c++ - ARM Cortex 上 Sobel 函数的 SIMD 矢量化
- sql - 如何编写一个 SQL 查询,它使用表 a_json 的 JSON 格式在 postgresql 中用其各自的值填充表 b
- python - Python - “KeyError:System.Object” - Pyadomd - 查询 SSAS 数据源
- javascript - 其他主机和我的客户端正常运行,但我的服务器端在 onClick Javascript youtube 播放器上失败
- python - 为什么这个函数在 CUDA 与并行时运行得更慢?
- guidewire - 我有这个 gosu 代码,但它没有为我编译 .6 版本的 gosu,请有任何想法