在现有 CSS class 中使用 CSS 媒体查询
Use CSS media query within an existing CSS class
我有一个现有的 CSS class 用于所有设备,我想添加一个媒体字段来覆盖现有的,以便应用于一些小的 phone 屏幕。
你能举例说明我们如何使用它吗?
最佳
为此你需要媒体查询。在此块中添加您的样式
@media only screen and (max-device-width:480px){
/* styles for mobile browsers smaller than 480px; (iPhone) */
}
同样,您也可以在以下块中进行媒体查询。
@media only screen and (device-width:768px){
/* default iPad screens */
}
/* different techniques for iPad screening */
@media only screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait) {
/* For portrait layouts only */
}
@media only screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:landscape) {
/* For landscape layouts only */
}
示例
假设您有以下风格
.color-me {
color : red;
}
@media only screen and (max-device-width:480px){
.color-me {
color : blue;
}
}
这是您的标记
<div class="color-me">Color me</div>
现在,除宽度小于等于 480px 的设备外,所有地方的文本颜色都是红色。
我有一个现有的 CSS class 用于所有设备,我想添加一个媒体字段来覆盖现有的,以便应用于一些小的 phone 屏幕。
你能举例说明我们如何使用它吗?
最佳
为此你需要媒体查询。在此块中添加您的样式
@media only screen and (max-device-width:480px){
/* styles for mobile browsers smaller than 480px; (iPhone) */
}
同样,您也可以在以下块中进行媒体查询。
@media only screen and (device-width:768px){
/* default iPad screens */
}
/* different techniques for iPad screening */
@media only screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait) {
/* For portrait layouts only */
}
@media only screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:landscape) {
/* For landscape layouts only */
}
示例
假设您有以下风格
.color-me {
color : red;
}
@media only screen and (max-device-width:480px){
.color-me {
color : blue;
}
}
这是您的标记
<div class="color-me">Color me</div>
现在,除宽度小于等于 480px 的设备外,所有地方的文本颜色都是红色。