css - 使用窗口调整大小调整按钮大小
问题描述
我制作了两排按钮(带有字母 AZ)。按钮和行的 CSS 代码是:
.buttons{
display: flex;
background-color: #009999;
border: none;
border-radius: 0.3em;
color: white;
text-align: center;
text-decoration: none;
display: inline-block;
cursor: pointer;
width: 2em;
height: 2em;
font-size: 1.6em;
padding: 0.2em ;
margin: 0.1em;
text-align: center;
font-weight: bold;
}
.firstRow, .secondRow {
display: flex;
flex-direction: row;
align-items: center;
padding: 0.2rem;
list-style-type: none;
width: 90%;
}
当我调整窗口大小时,我希望这些按钮也根据窗口的大小调整大小。我的问题是,当我减小窗口大小时,字母保持相同大小,并且它们并未全部显示在屏幕上。
解决方案
尝试使用vw(viewport)
而不是em
.buttons{
display: flex;
background-color: #009999;
border: none;
border-radius: 0.3em;
color: white;
text-align: center;
text-decoration: none;
display: inline-block;
cursor: pointer;
width: 5vw;
height: 5vw;
font-size: 1.5vw;
padding: 2%;
margin: 1%;
text-align: center;
font-weight: bold;
}
.firstRow, .secondRow {
display: flex;
flex-direction: row;
align-items: center;
padding: 0.2rem;
list-style-type: none;
width: 90%;
}
推荐阅读
- sql - SQL Server 子表按什么顺序删除?
- spring-boot - 防止在 JUnit 中执行 jpa @Query
- python - Discord.py raw_reaction_add 找不到成员
- python-3.x - 如何为 wx.html2.WebView 设置 socks5
- flutter - Flutter 的有状态小部件中未显示文本
- javascript - Markdown 段落标签正则表达式
- python - 从 python 脚本创建的可执行文件只启动一个 DOS 窗口
- python - 为熊猫中的每一行动态选择匹配的列子集
- javascript - 在单击按钮时使用道具反应渲染组件
- python - 使用 Python 从预先存在的数据框创建新的数据框