html - 使用 @media only screen 和 (max-width) 在 css 中更改 div 的宽度和高度的问题
问题描述
我正在开发一个网页,并试图使其适合移动设备或在其他屏幕尺寸上工作。我打算使用 css (@media only screen and (max-width:)) 来更改包含四个圆形缩略图形式的 div 的宽度和高度。
HTML:
<div class="thumbnail">
<img src="#" class="cover1">
<img src="#" class="cover2">
<img src="#" class="cover3">
<img src="#" class="cover4">
</div>
CSS:
.thumbnail{
width: 200px;
height: 200px;
margin: 20px;
float: left;
display: flex;
flex-wrap: wrap;
border: 5px solid black;
border-radius: 50%;
}
.thumbnail img{
width: 100px;
height: 100px;
}
.
.
.
@media only screen and (max-width: 1180){
.thumbnail{ <-- does not work
width: 150;
height: 150;
}
.thumbnail img{ <-- works
width: 75px;
height: 75px;
}
}
解决方案
将单位 px 添加到(max-width:1180)
.thumbnail 宽度和高度值。
.thumbnail {
width: 200px;
height: 200px;
margin: 20px;
float: left;
display: flex;
flex-wrap: wrap;
border: 5px solid black;
border-radius: 50%;
}
.thumbnail img {
width: 100px;
height: 100px;
}
@media only screen and (max-width: 1180px) {
.thumbnail {
width: 150px;
height: 150px;
}
.thumbnail img {
width: 75px;
height: 75px;
}
}
<div class="thumbnail">
<img src="#" class="cover1">
<img src="#" class="cover2">
<img src="#" class="cover3">
<img src="#" class="cover4">
</div>
.
推荐阅读
- sql - 选择与特定记录相关但没有其他记录相关的记录
- python - 标签中的小部件放置
- c# - 如何使用单声道将 .so 文件链接到托管 DLL
- r - 除非激活另一个小部件,否则闪亮的小部件不起作用
- jquery - Bootstrap Collapse 在动态创建元素后不起作用
- wordpress - Wordpress 网站从 https 恢复...链接断开
- java - 将 HTML 的字体大小属性转换为 CSS 字体大小属性
- regex - 正则表达式在word中查找大写字符
- javascript - jQuery.ajax xhrFields: {withCredentials: true} 做什么?
- r - 用 R 中的新列表中的列表重新组织列表