您可以@media
在 CSS 中使用查询。例如,如果您的浏览器width
是1024
,则显示一个内容,但如果较少,则不显示。一个代码是:
@media (max-width: 500px) {
.left-sidebar {
display: none;
}
}
@media (min-width: 500px) {
.left-sidebar {
display: block;
}
}
IE 7 和 IE 8 尚不支持它!在这种情况下,您需要使用 JavaScript 或 jQuery 来触发。试试看。:) 希望能帮助到你!:)
在此处查看基本示例Media Query Demo。调整浏览器宽度并检查底部。
的CSS是:
@media only screen and (min-width: 320px) {
body:after {
content: "320 to 480px";
background-color: hsla(90,60%,40%,0.7);
}
}
@media only screen and (min-width: 480px) {
body:after {
content: "480 to 768px";
background-color: hsla(180,60%,40%,0.7);
}
}
@media only screen and (min-width: 768px) {
body:after {
content: "768 to 1024px";
background-color: hsla(270,60%,40%,0.7);
}
}
@media only screen and (min-width: 1024px) {
body:after {
content: "1024 and up";
background-color: hsla(360,60%,40%,0.7);
}
}