【发布时间】:2015-03-21 01:21:54
【问题描述】:
我有两个 CSS 媒体查询,分别是纵向和横向。我想使用 javascript 修改这些,以便我可以根据传递给页面的变量动态更改其中的样式。我知道我可以使用 document.styleSheets[x].rules[x] 来修改 css,但我不确定如何只修改特定媒体查询下的样式。
这是我当前的代码:
@media screen and (orientation:portrait) {
#Header {
background-color: #000;
height: 60px;
width: 100%;
position: fixed;
top: 0px;
z-index: 100;
}
#Main .row ul li {
width: 110px;
height: 145px;
padding: 2px;
margin: 2px 4px 2px 0px;
vertical-align: middle;
text-align: center;
background-color: #FFF;
position: relative;
display:table-cell;
float:left;
}
#Main .row ul li img {
border: 0;
width: 86px;
height: 86px;
padding: 12;
}
}
@media screen and (orientation:landscape) {
#Header {
background-color: #000;
height: 45px;
width: 100%;
position: fixed;
top: 0px;
z-index: 100;
}
#Main .row ul li {
width: 115px;
height: 110px;
padding: 2px;
margin: 2px 4px 2px 0px;
vertical-align: middle;
text-align: center;
background-color: #FFF;
position: relative;
display:table-cell;
float:left;
}
#Main .row ul li img {
border: 0;
width: 66px;
height: 66px;
padding: 8px;
}
}
我需要在两个方向之间分别更改样式。
这个页面让我了解了如何指定媒体查询,但不是我如何在这些媒体查询中指定媒体功能。 http://www.howtocreate.co.uk/tutorials/javascript/domstylesheets
【问题讨论】:
标签: javascript css html media-queries