Michael
Michael

Reputation: 13636

How can I remove this space between elements?

Hello I working on my web project using bootstrap 3.3.7

Here is my HTML code example:

<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>

And here is working JSFiddle.

As you can see in the example, there are some space between navbar and frame.

How can I remove this space? And how can I make iframe element close to navbar?

Upvotes: 1

Views: 170

Answers (6)

Banzay
Banzay

Reputation: 9470

It's not good practice to change predefined bootstrap styles, even using !important.

You just need to set negative margin-top for iframe:

iframe {
   margin-top: -20px;
}

Upvotes: 2

Gokul P P
Gokul P P

Reputation: 962

Need to remove margin-bottom of bootstrap with custom CSS

.nobottommargin {
  margin-bottom: 0px !important;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<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>

Upvotes: 1

Mauro
Mauro

Reputation: 4511

In your fiddle you have added the class nobottommargin to your navbar, if you then add some custom CSS to your html as below you will see the margin disappears.

.nobottommargin {
    margin-bottom: 0px;
}

Upvotes: 1

RandomNoobName
RandomNoobName

Reputation: 81

Nav tag has set bottom margin add to nav style margin-bottom: 0px and it's should work

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

Upvotes: 1

Tak&#225;cs Botond
Tak&#225;cs Botond

Reputation: 136

Add this:

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

Upvotes: 1

Marc Scheib
Marc Scheib

Reputation: 2009

.navbar has a margin-bottom: 20px;. Simply remove this with an own CSS class:

.nobottommargin {
  margin-bottom: 0;
}

Upvotes: 4

Related Questions