Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 如何删除元素之间的空间?_Html_Css_Twitter Bootstrap - Fatal编程技术网

Html 如何删除元素之间的空间?

Html 如何删除元素之间的空间?,html,css,twitter-bootstrap,Html,Css,Twitter Bootstrap,您好,我正在使用Bootstrap3.3.7处理我的web项目 以下是我的HTML代码示例: <nav class="navbar navbar-default nobottommargin" role="navigation"> <div class="container-fluid"> <div class="navbar-header"> <button type="button" class="n

您好,我正在使用Bootstrap3.3.7处理我的web项目

以下是我的HTML代码示例:

<nav class="navbar navbar-default nobottommargin" role="navigation">
    <div class="container-fluid">

        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-9">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">Brand</a>
        </div>

        <div class="collapse navbar-collapse" id="">
            <ul class="nav navbar-nav">
                <li class="active"><a href="#">Home</a></li>
                <li><a href="#">Link</a></li>
                <li><a href="#">Link</a></li>
            </ul>
        </div>

    </div>
</nav>

<iframe src="https://www.news.sky.com" style="width:100%;height:100%" frameborder="3"></iframe>
这就是工作

正如您在示例中所看到的,导航栏和框架之间有一些空间

如何删除此空间?如何使iframe元素靠近navbar?

。navbar有一个边距底部:20px;。只需使用自己的CSS类将其删除:

.nobottommargin {
  margin-bottom: 0;
}
.navbar有一个底部边距:20px;。只需使用自己的CSS类将其删除:

.nobottommargin {
  margin-bottom: 0;
}
添加以下内容:

.navbar {
    margin-bottom: 0px !important;
}
添加以下内容:

.navbar {
    margin-bottom: 0px !important;
}

导航标签已设置底部边距添加到导航样式的边距底部:0px,它应该可以工作

<nav class="navbar navbar-default nobottommargin" role="navigation" style="margin-bottom: 0px">

导航标签已设置底部边距添加到导航样式的边距底部:0px,它应该可以工作

<nav class="navbar navbar-default nobottommargin" role="navigation" style="margin-bottom: 0px">

在你的提琴中,你已经将nobottommargin类添加到你的导航栏中,如果你在html中添加一些自定义CSS,如下所示,你会看到空白消失

.nobottommargin {
    margin-bottom: 0px;
}

在你的提琴中,你已经将nobottommargin类添加到你的导航栏中,如果你在html中添加一些自定义CSS,如下所示,你会看到空白消失

.nobottommargin {
    margin-bottom: 0px;
}
需要使用自定义CSS删除引导程序底部的边距

nobottommargin先生{ 页边距底部:0px!重要; } 切换导航 需要使用自定义CSS删除引导程序底部的边距

nobottommargin先生{ 页边距底部:0px!重要; } 切换导航
更改预定义的引导样式不是好的做法,即使使用!重要的

您只需为iframe设置负边距上限:

iframe {
   margin-top: -20px;
}

更改预定义的引导样式不是好的做法,即使使用!重要的

您只需为iframe设置负边距上限:

iframe {
   margin-top: -20px;
}

导航栏有页边距底部:20px您需要将页边距底部:0添加到类NoBottomMargin导航栏有页边距底部:20px您需要将页边距底部:0添加到类nobottommarginBecause。导航栏css是根据特定原因创建的,更改它可能会意外地影响其他元素的定位,具体取决于上下文。想象一下,如果您对不同的页面使用相同的样式,而其中一些页面不包含iframe。在我看来,这是错误的答案。这只解决了单个页面的问题,如果包含了。在所有其他情况下,您需要添加更多样式表来调整边距。我还认为,直接调整引导样式不是一个好的做法。因此,只需使用已定义的.nobottommargin。顺便说一句,Bootstrap 4有很多有用的东西,比如mb-0。@MarcScheib你的笔记是有道理的,但无论如何它取决于上下文,最后OP必须决定什么解决方案是最可接受的。也许在所有其他情况下,他不需要设置这个调整。我认为最好的办法是定义具有负上边距的特殊类。它看起来像是您解决方案的镜像:因为.navbar css是根据特定原因创建的,更改它可能会影响其他元素的位置,具体取决于上下文。想象一下,如果您对不同的页面使用相同的样式,而其中一些页面不包含iframe。在我看来,这是错误的答案。这只解决了单个页面的问题,如果包含了。在所有其他情况下,您需要添加更多样式表来调整边距。我还认为,直接调整引导样式不是一个好的做法。因此,只需使用已定义的.nobottommargin。顺便说一句,Bootstrap 4有很多有用的东西,比如mb-0。@MarcScheib你的笔记是有道理的,但无论如何它取决于上下文,最后OP必须决定什么解决方案是最可接受的。也许在所有其他情况下,他不需要设置这个调整。我认为最好的办法是定义具有负上边距的特殊类。它看起来像是您的解决方案的镜像: