媒体查询不起作用?

时间:2013-07-28 11:28:30

标签: css3 responsive-design media-queries

尝试应用一点媒体查询。

没有媒体查询的CSS

blockquote {
margin: 1.5em 0;
font-family: 'Gentium Basic', Georgia, serif;
font-size: 20px;
line-height: 1.6em;
font-weight: normal;
font-style: italic;
border-left: 1px dotted;
padding: 0 0 0 25px;
left: 50%;
margin-left: -150px;
width: 650px;
}

然后申请:

/* larger than 800px */
@media only screen and (min-width: 801px) {
  #mobileNav {
    height: 0 !important;
  }
}
/* 800px and smaller */
@media only screen and (max-width: 800px) {
  #bannerImage {
    background-attachment: scroll !important;
  }

blockquote {
margin: 1.5em 0;
font-family: 'Gentium Basic', Georgia, serif;
font-size: 20px;
line-height: 1.6em;
font-weight: normal;
font-style: italic;
border-left: 1px dotted;
padding: 0 0 0 25px;
}

网站here

我要做的是让blockquote适合屏幕。目前,当页面宽度发生变化时,它会执行此操作:

enter image description here

当我希望它这样做时:

enter image description here

1 个答案:

答案 0 :(得分:3)

如果您没有在媒体查询中定义width,它只会使用通用样式表中定义的width(在本例中为650px),所以你需要在媒体查询规则块中再次定义width

@media only screen and (max-width: 800px) {
    blockquote {
       margin: 1.5em 0;
       font-family: 'Gentium Basic', Georgia, serif;
       font-size: 20px;
       line-height: 1.6em;
       font-weight: normal;
       font-style: italic;
       border-left: 1px dotted;
       padding: 0 0 0 25px;
       width: 100%; /* Specify some width here */
       /* You should use auto value as you are using margins and paddings */
    }

    /* Other styles goes here */
}
  

注意:如果媒体查询中只有您粘贴的样式   在这里,我想通知你,你没有关闭   媒体查询块。

Demo

相关问题