如何正确使用媒体查询

时间:2013-04-05 21:05:01

标签: html css twitter-bootstrap responsive-design media-queries

我正在设计一个响应式网页。我有一个div,当屏幕尺寸减小时,宽度应该减小。

此div还包含两个图像链接的列表。即使屏幕宽度减小,它们也应保持内联。

/* The CSS */
div.mymenu{
margin-right:7%;
margin-top:-53px;
background:#000;
width: 28.5%;
opacity:0.8;
}

div.mymenu > .nav-pills{
margin-bottom:7px;
}

div.mymenu > .nav-pills a{
color:#fff;
margin-left: 30%;
}

div.mymenu > .nav-pills a:hover{
background:none;
} 

<!-- The HTML -->

<div class="mymenu pull-right">
            <ul class="nav nav-pills">
                <li><a href="">Why Us</a></li>
                <li><a href=""><img src="img/news.png" /></a></li>
                <li><a href=""><img src="img/help.png" /></a></li>
            </ul>
        </div>

我正在使用twitter bootstrap。我尝试对bootstrap-responsive.css进行更改 - 但没有变化。我做了一些改动,如: -

@media (min-width: 768px) and (max-width: 979px) {
.mymenu{
 width: 20%;
}
}

3 个答案:

答案 0 :(得分:3)

对于流体设计,我非常推荐使用Skeleton:http://www.getskeleton.com/

这里有@media查询的标准

/* #Tablet (Portrait)
================================================== */
    /* Note: Design for a width of 768px */

    @media only screen and (min-width: 768px) and (max-width: 959px) {

    }


/*  #Mobile (Portrait)
================================================== */
    /* Note: Design for a width of 320px */

    @media only screen and (max-width: 767px) {

    }


/* #Mobile (Landscape)
================================================== */
    /* Note: Design for a width of 480px */

    @media only screen and (min-width: 480px) and (max-width: 767px) {

    }

来自阿根廷的问候!

答案 1 :(得分:2)

您当前的媒体查询会将这些样式限制在768px979px之间的浏览器。删除第二个媒体查询(979),使其适用于宽度超过768 px的所有视口。

@media (min-width: 768px)  {
    .mymenu {
      width: 20%;
    }
}

另外,只是一个注释,我建议修剪选择器,如div.mymenu,只有.mymenu div限制选择器的适用性(也许你会想要一个{{1}与ul)具有相同的样式,并且更多的输入:)

答案 2 :(得分:2)

/* Smartphones (portrait and landscape) ----------- */
@media only screen 
and (min-device-width : 320px) 
and (max-device-width : 480px) {
/* Styles */
}

/* Smartphones (landscape) ----------- */
@media only screen 
and (min-width : 321px) {
/* Styles */
}

/* Smartphones (portrait) ----------- */
@media only screen 
and (max-width : 320px) {
/* Styles */
}

/* iPads (portrait and landscape) ----------- */
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) {
/* Styles */
}

/* iPads (landscape) ----------- */
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : landscape) {
/* Styles */
}

/* iPads (portrait) ----------- */
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : portrait) {
/* Styles */
}

/* Desktops and laptops ----------- */
@media only screen 
and (min-width : 1224px) {
/* Styles */
}

/* Large screens ----------- */
@media only screen 
and (min-width : 1824px) {
/* Styles */
}

/* iPhone 4 ----------- */
@media
only screen and (-webkit-min-device-pixel-ratio : 1.5),
only screen and (min-device-pixel-ratio : 1.5) {
/* Styles */
}
相关问题