容器正在获得不必要的利润

时间:2014-06-08 12:28:55

标签: javascript jquery html css

我的HTML是: -

<!DOCTYPE html>
<html>
<head>
<meta charset="US-ASCII">
<link
    rel="stylesheet"
    type="text/css"
    href="css/index.css"
>
<title>Best company in the USA</title>
</head>

<body>
    <div class="menu">
        <h2>MENU</h2>
        <ul>
            <li></li>
            <li></li>
            <li></li>
        </ul>
    </div>

    <nav role="navigation">
        <div class="navWrap">
            <h2 class="navClose"></h2>
            <ul>
                <li><a href="somelink.com">Home</a></li>
                <li></li>
                <li><a href="somelink.com">About us</a></li>
                <li></li>
                <li><a href="somelink.com">
                        Services</a></li>
                <li></li>
                <li><a href="somelink.com">Locations</a></li>
                <li></li>
                <li><a href="somelink.com">Contact Us</a></li>
                <li></li>
            </ul>
        </div>
    </nav>

    <div class="content">
        <section class="first"></section>
    </div>

</body>

</html>

我的css是: -

@CHARSET "US-ASCII";

* {
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
}

::-moz-selection {
    background: none repeat scroll 0% 0% #D8262E;
}

::selection {
    background: none repeat scroll 0% 0% #D8262E;
}

ul {
    list-style: none outside;
    clear: both;
}

.menu {
    position: absolute;
    float: right;
    cursor: pointer;
    float: right;
    z-index: 1000;
    top: 25px;
    right: 20px;
}

.menu h2 {
    display: none;
    text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.2)
}

@media only screen and (min-width:768px) {
    .menu {
        top: 32px;
        right: 40px;
    }
    .menu h2 {
        display: inline-block;
        text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.2);
        font-family: "Karla", Arial, sans-serif;
        font-size: 20px;
        margin: 0px 5px 0px 0px;
        text-transform: uppercase;
        vertical-align: top;
    }
}

.menu ul {
    display: inline-block;
    height: 30px;
    margin: 0;
    padding: 0;
    vertical-align: top;
    width: 25px;
    margin: 0;
}

.menu ul li {
    background: white;
    -webkit-border-radius: 2px;
    -moz-border-radius: 2px;
    -ms-border-radius: 2px;
    -o-border-radius: 2px;
    border-radius: 2px;
    -webkit-box-shadow: rgba(0, 0, 0, 0.2) 1px 1px 1px;
    -moz-box-shadow: rgba(0, 0, 0, 0.2) 1px 1px 1px;
    box-shadow: rgba(0, 0, 0, 0.2) 1px 1px 1px;
    height: 3px;
    margin: 3px 0;
    width: 100%;
}

html,nav,section,div {
    display: block;
    vertical-align: baseline;
    margin: 0px;
    padding: 0px;
    border: 0px none;
}

nav[role="navigation"] {
    background: #00e000;
    overflow: hidden;
    padding: 0 40px;
    position: absolute;
    top: 0;
    right: 0;
    text-align: left;
    width: 13em;
    z-index: 10;
}

.menu,.content,.first {
    -webkit-transition: all 340ms cubic-bezier(0.905, 0.015, 0.65, 0.97);
    -webkit-transition-delay: 0s;
    -moz-transition: all 340ms cubic-bezier(0.905, 0.015, 0.65, 0.97) 0s;
    -o-transition: all 340ms cubic-bezier(0.905, 0.015, 0.65, 0.97) 0s;
    transition: all 340ms cubic-bezier(0.905, 0.015, 0.65, 0.97) 0s
}

.first {
    background-color: #d8262e;
    /* background:  no-repeat scroll center  transparent; */
    width: 100%;
    /* height: 600px; */
    top: 0;
    z-index: 30;
}

.first:before {
    height: 100%;
    content: "";
    display: inline-block;
    vertical-align: middle;
    background-color: #38262e;
}

.first:after {
    background-color: #38262e;
}

.content {
    /* margin-top: -8px;
    margin-left: -7px;
    margin-right:-7px; */
    /* padding-top:-10px; */


}

content:before,content:after {
    content: "";
    display: table;
    line-height: 0;

}

content:after {
    clear: both;
}

Jquery是: -

$(document) .ready(function () {

    windowHeight = 0.9 * $(window) .innerHeight();
    $('.first').height(windowHeight);
    $(window) .resize(function () {
        windowHeight = 0.9 * $(window) .innerHeight();
        console.log("height: " + windowHeight);
    });

});

所以,我现在面临着一个特殊的问题。不知何故,我在content课程中从每一方获得8-10px或边距。我有一个解决方案。如果我在.content中注释掉css,它对我有用。

但是,如果我的天真解决方案能够变得更好,那就太棒了。或者,如果有人帮我指出额外保证金的根本原因,那就太好了。

这是一个jsfiddle:http://jsfiddle.net/kSdHU/ 感谢。

2 个答案:

答案 0 :(得分:2)

您应该重置元素。

只需添加:

* { margin: 0; padding: 0; }

Demo

答案 1 :(得分:0)

为了确保你永远不会遇到像这样的奇怪的样式问题,我建议使用css重置。它基本上会重置您的浏览器默认样式,因此您不会得到不需要的元素样式。我通常使用Eric Meyers Reset,但那里有很多。