简体   繁体   English

删除元素之间的空白

[英]Removing white space in between elements

Just got in to web design, I know basic HTML and CSS and I am trying to create a standard home page just to increase my skills and knowledge. 刚开始从事网页设计,我就知道基本的HTML和CSS,并且我试图创建一个标准的主页只是为了增加我的技能和知识。

I have created a standard nav bar and my next step is to create a hero box with an image underneath the nav bar. 我已经创建了一个标准的导航栏,下一步是创建一个带有导航栏下方图像的英雄框。 I am using a section tag to achieve this, however there is a gap between the nav bar and the section and I am not sure how to remove this. 我正在使用section标签来实现此目的,但是导航栏和该部分之间存在间隙,我不确定如何删除它。 Below is the link, any advice would be greatly appreciated. 以下是链接,任何建议将不胜感激。

<nav class="navbar navbar-inverse">
            <div class="container">
                <ul class="main-nav navbar-right">
                    <li>
                        <a href="#">Home</a>
                    </li>
                    <li>
                        <a href="#">Contact Us</a>
                    </li>
                    <li>
                    <a href="#">About Us</a>
                    </li>
                </ul>
            </div>
        </nav>

        <section>
            <div class="container">
                section 1
            </div>
        </section>

Link 链接

Many browsers now have an inspect tool - to look at the element in question, see what CSS is effecting it, and what the box model - it's padding, size and positioning. 现在,许多浏览器都有一个检查工具-查看有问题的元素,查看影响CSS的元素以及盒子模型的内容-填充,大小和位置。

Looking at your fiddle, it's going to either be a property effecting the top of section, .container, or a property affecting the bottom of nav. 查看您的小提琴,它将是影响该部分顶部的属性(.container),或者是影响导航底部的属性。 For nav - given that the black background stops - it would be a margin and not padding if it is that. 对于导航-鉴于黑色背景停止了-如果是那样,这将是一个空白并且不填充。 The inspector when hightlighting elements suggests it is the bottom of the nav. 检查员在提示​​要素提示它是导航仪的底部时。

It appears that there is a .navbar style effecting it - which has margin-bottom: 20px . 似乎有一个.navbar样式会影响它- margin-bottom: 20px If you remove this - you will no longer have a gap between the nav and your content. 如果删除此选项,则导航和内容之间将不再有空隙。 However, since it comes from the bootstrap min css - you'll need to override it. 但是,由于它来自bootstrap min css,因此您需要覆盖它。

You can add this after the bootstrap inclusion to do so: 您可以在包含引导程序之后添加它:

.navbar {
  margin-bottom: 0;
}

Fix: Add a class .nav-bar-custom in navbar because you can use multiple navbar and use custom css againist this navbar's main nav . 修复:在navbar中添加一个类.nav-bar-custom ,因为您可以使用多个navbar并再次使用自定义css对该navbar的主nav进行操作 ul.main-nav{margin-bottom:0px;}

 /* Latest compiled and minified CSS included as External Resource*/ /* Optional theme */ @import url('//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css'); .nav-bar-custom ul.main-nav{margin-bottom:0px;} .main-nav li{ list-style: none; display: inline-block; padding-right: 20px; padding-top: 5px; font-size: 20px; } .main-nav a{ text-decoration: none; color: #fff; } section{ background-color: #808080; margin-top: 0; } 
 <nav class="navbar navbar-inverse nav-bar-custom"> <div class="container"> <ul class="main-nav navbar-right"> <li><a href="#">Home</a></li> <li><a href="#">Contact Us</a></li> <li><a href="#">About Us</a></li> </ul> </div> </nav> <section> <div class="container">section 1</div> </section> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM