将另一个div中的div包装为边框

时间:2014-05-01 00:36:04

标签: html css

我有一个导航栏,我为它做了一个边框,我试图在导航栏周围包裹边框,这应该是非常容易的但由于某种原因我不能让它排成一行。这就是它现在的样子:

enter image description here

这是HTML(以及一些PHP):

<div style="background: url(/images/nav.png) top left no-repeat; width:1044px; height:60px; margin-left:auto; margin-right:auto;">
                    <nav>
                        <ul>
                            <a href=""><li class="first">Home</li></a>
                            <li class="space"></li>
                            <a href=""><li class="
                                <?php
                                if (in_array($role,array('Top','top'))) {
                                    echo 'selected';
                                }                   
                                 ?>
                                ">Top Lane</li></a>
                            <li class="space"></li>
                            <a href=""><li class="
                                <?php
                                if (in_array($role,array('Middle','middle'))) {
                                    echo 'selected';
                                }                   
                                 ?>                             
                                ">Mid Lane</li></a>
                            <li class="space"></li>
                            <a href="e"><li class="
                                <?php
                                if (in_array($role,array('Jungle','jungle'))) {
                                    echo 'selected';
                                }                   
                                 ?>                             
                                ">Jungle</li></a>
                            <li class="space"></li>
                            <a href=""><li class="
                                <?php
                                if (in_array($role,array('ADC','adc','Adc'))) {
                                    echo 'selected';
                                }                   
                                 ?>                             
                                ">AD Carry</li></a>
                            <li class="space"></li>
                            <a href=""><li class="
                                <?php
                                if (in_array($role,array('Support','support'))) {
                                    echo 'selected';
                                }                   
                                 ?>                             
                                ">Support</li></a>
                            <li class="space"></li>
                                                        <li style="float:right; cursor:auto;">
                                <form action="" method="get">
                                                            <select name="region" id="region" onchange='getSelectedValue();'>
<option value="" selected>Choose Your Region</option>
<option value="NA">NA</option>
<option value="EUW">EUW</option>
<option value="EUNE">EUNE</option>
<option value="TR">TR</option>
<option value="RU">RU</option>
<option value="OCE">OCE</option>
<option value="LAS">LAS</option>
<option value="LAN">LAN</option>
<option value="BR">BR</option>
</select>
<input name="summoner" id="summoner" placeholder="Enter Summoner Name" type="text">
<input type="submit" value="Search!">
</form>
</li>
                        </ul>

                    </nav>
                    </div>

和导航栏的样式表:

nav {
    margin-left: auto;
    margin-right: auto;
    text-align: left;
    background:url(/images/marble.jpg) top left;
    background-color: #0b0b0b;
    margin-top: 15px;
    width: 1024px;
    height: 40px;
    box-shadow: 0px 0px 5px black;
}
nav ul {
    list-style: none;
    position: relative;
    font-size: 15px;
    font-family: 'Lucida Sans Unicode', 'Lucida Grande', sans-serif;
    height: 40px;
    line-height: 250%;
    text-shadow: -1px -1px 0 #090909, 1px -1px 0 #090909, -1px 1px 0 #090909, 1px 1px 0 #090909, 2px 2px 3px black;
}
nav ul li {
    float: left;
    height: 40px;
    padding-left: 10px;
    padding-right: 10px;
}
nav ul li:hover > ul { display: block }
nav ul li a {
    display: block;
    text-decoration: none;
}
nav ul ul { display: none }
nav ul li ul li:hover { }
nav ul:after {
    content: "";
    clear: both;
    display: block;
}
nav ul ul {
    padding: 0;
    position: absolute;
    font-size: 14px;
    top: 100%;
    height: 30px;
    margin-top: 0px;
    margin-left: -11px;
    line-height: 180%;
    background-color: #252525;
    border: 1px solid black;
    box-shadow: 2px 2px 8px black;
}
nav ul li:first-child ul { margin-left: -6px }
nav ul ul li:hover { border-radius: 0 }
nav ul ul li:first-child:hover { border-radius: 0 }
nav ul ul li {
    float: left;
    color: white;
    position: relative;
    text-align: center;
    height: 30px;
    padding-left: 5px;
    padding-right: 5px;
    border-radius: 4px;
}
nav ul ul li a {
    padding: 15px 40px;
    color: #fff;
}
nav ul ul li a:hover { background: #848788 }
nav ul ul ul {
    top: 0;
    position: absolute;
    background-color: transparent;
    margin-top: 30px;
    margin-left: -6px;
    font-size: 14px;
    line-height: 180%;
    box-shadow: 0px 0px 0px black;
    border: 0;
    border-radius: 0;
}
nav ul a { color: #e6e6e6; }

nav ul a:hover { color: #ea8422 }
nav ul li:hover,
nav ul li a:hover {
    cursor: pointer;
    text-shadow: 2px 2px 5px black,  -1px -1px 0 #090909, 1px -1px 0 #090909, -1px 1px 0 #090909, 1px 1px 0 #090909;
    border-radius: 0;
}
nav ul ul ul li {
    color: white;
    float: none;
    position: relative;
    display: block;
    background-color: #252525;
    border: 1px solid black;
    border-radius: 2px;
    border-bottom: 0;
    box-shadow: 2px 2px 8px black;
}
nav ul ul ul li:last-child { border-bottom: 1px solid black }
nav ul ul ul li:first-child:hover { border-radius: 2px }

代码的JSFiddle:JSfiddle Demo

1 个答案:

答案 0 :(得分:3)

你在正确的轨道上,但导航的边缘顶部正在崩溃。在这里阅读更多内容:https://developer.mozilla.org/en-US/docs/Web/CSS/margin_collapsing(参见第二个案例,父/子)

您可以在外部div上使用填充,而不是使用边距定位导航。 https://developer.mozilla.org/en-US/docs/Web/CSS/padding

http://jsfiddle.net/REh86/1/

div {
    padding: 10px;
}