CSS min-width表现不正常

时间:2013-02-19 06:15:48

标签: html css html5 css3

在下面的代码中,我将我的顶部徽标设置为min-width:800px,这样用户就无法调整大小并弄乱我的导航。但是,由于某种原因它不起作用。有人能告诉我我做错了吗?

<!DOCTYPE html>
<html>
<head>
    <title>css example</title>

<style type="text/css">

#logo {
    background-color: black;
    width: 100%;
    color: rgb(255,200,0);
    height: 100px;
    min-width: 800px;
}

#logo p {
    display: inline;
    padding: 0;
}

#logo img {
    padding: 10px;
    padding-top: 15px;
    vertical-align: middle;
}

#logo h1 {
    display: inline;
    padding-right: 25px;
    vertical-align: middle;
    float: right;

}

#logo a {
    vertical-align: middle;
    float: right;
    color: rgb(255, 200, 0);
    text-decoration: none;
    font-size: 1.1em;
    margin:0;
    padding: 15px;
}

body {
    font-size: 100%;
    font-family: Arial, Helvetica, Verdana;
    margin: 0;
}

#contents {
    border: 1px solid black;
    width: 90%;
    min-height: 650px;
    height:auto !important;
    margin: 0 5%;
    margin-top: 15px;
    padding: 5px;
    border-radius: 5px;
}

#navMenu {
    width: 100%;
    height: 32px;
    background-color:rgb(255,200,0);
    border:1px #000 solid;
    font-weight:bold;
    margin-left: -2px;
}

#navMenu ul{
    margin:0;
    padding:0;
    line-height:32px;
    border:1px #000 solid;
}

#navMenu li{
    margin:0;
    padding:0;
    list-style:none;
    position:relative;
    background-color:rgb(255,200,0);
    float:left;
    border:1px #000 solid;
}

#navMenu ul li a{
    text-align:center;
    text-decoration:none;
    height:30px;
    width:150px;
    display:block;
    color:#000;

}

#navMenu ul ul{
    position:absolute;
    visibility:hidden;
    top: 31px;
    margin-left: -2px;

}

#navMenu ul li:hover ul{
    visibility: visible;

}

#navMenu ul li:hover {
    background-color:rgb(255,200,0);
}

#navMenu a:hover {
    background-color:#000;
    color:rgb(255,200,0);
}


</style>

</head>

<body>

<div id="logo">

    <p>
        <img src="demo.gif" >
    </p>

    <h1>Comic Book Subscriber Management</h1>
    <!--
    <p><a href="#">LOG-IN </a></p>
    <p><a href="#">CONTACT US </a></p>-->

</div>

<div id="navMenu">
    <nav>
        <ul>
            <li><a href="#">HOME</a></li>
            <li><a href="#">PROFILE</a></li>
            <li><a href="#">MANAGE SUB</a>
            <ul>
                <li><a href="#">VIEW TITLES</a></li>
                <li><a href="#">ADD TITLE</a></li>
                <li><a href="#">MODIFY TITLE</a></li>
                <li><a href="#">REMOVE TITLE</a></li>
            </ul>
            </li>
            <li><a href="#">NEW RELEASES</a></li>
            <li><a href="#">E-MAIL</a></li>
        </ul>
    </nav>
</div>

<div id="contents">

    <p>This is just some dummy text. Dummy. </p>

</div>

</body>
</html>

4 个答案:

答案 0 :(得分:0)

您的min-width位于容器<div>上,但是为了做您正在尝试的事情,您可能会想要img本身。

另一种选择是将其设置为div#logo的背景图片,但我不确定这是否适合您的用例。

答案 1 :(得分:0)

**use like this it vii work in mozila nd chrome**    
for IE u need to use  css3-mediaqueries.js


@media screen and (min-width: 800px) 
    {
        #logo {
        background-color: black;
        width: 100%;
        color: rgb(255,200,0);
        height: 100px;
        width: 800px;

    }

答案 2 :(得分:0)

试试这个

#logo {
    background-color: black;
    width: 800px;
    color: rgb(255,200,0);
    height: 100px;
    margin-left:auto;
    margin-right:auto;
}

答案 3 :(得分:0)

请使用@media Query我认为您的要求已在@media Query

中得到满足
/* 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 */
}