html - 基于宽度的不同 CSS

标签 html css

我有一个使用“卡片” View 的网站。在桌面上查看时,我将卡片的 CSS 设置为:

width: 75%
margin: auto

我这样做是为了让“卡片”不会占据整个宽度,这在桌面上看起来更漂亮:

enter image description here

但我想弄清楚的是,当屏幕尺寸变为移动较小的屏幕时,如何自动关闭宽度和边距。出于显而易见的原因,我希望卡片在移动 View 中的宽度为 100%。如何根据窗口宽度更改 CSS?

最佳答案

这是一个标准的引导媒体查询。确保你把这个元标签放在头上

 <meta name="viewport" content="width=device-width, initial-scale=1.0">




/*==========  Mobile First Method  ==========*/

/* Custom, iPhone Retina */ 
@media only screen and (min-width : 320px) {

}

/* Extra Small Devices, Phones */ 
@media only screen and (min-width : 480px) {

}

/* Small Devices, Tablets */
@media only screen and (min-width : 768px) {

}

/* Medium Devices, Desktops */
@media only screen and (min-width : 992px) {

}

/* Large Devices, Wide Screens */
@media only screen and (min-width : 1200px) {

}



/*==========  Non-Mobile First Method  ==========*/

/* Large Devices, Wide Screens */
@media only screen and (max-width : 1200px) {

}

/* Medium Devices, Desktops */
@media only screen and (max-width : 992px) {

}

/* Small Devices, Tablets */
@media only screen and (max-width : 768px) {

}

/* Extra Small Devices, Phones */ 
@media only screen and (max-width : 480px) {

}

/* Custom, iPhone Retina */ 
@media only screen and (max-width : 320px) {

}

关于html - 基于宽度的不同 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35546721/

相关文章:

javascript - 在模式中从 SQL 数据库加载数据

javascript - 尝试循环 ajax 加载调用

父级和子级的 HTML/CSS 绝对位置

javascript - 如何在 php 循环中使用 jquery 更改 css

php - 灯箱上的表格

c# - 在单个 FormView C# 中实现不同的字体样式

javascript - 创建 UI 框架的方法

javascript - 如何使用下拉菜单在 JavaScript 中实现多个过滤器

jquery - 整页背景图像尺寸建议

html - 如何使用 CSS 制作内联 block