javascript - HTML CSS, Bootstrap responsive DIV height - Stack Overflow

Good day,I am trying to make my first responsive layout with the help of the Bootstrap Framework.As a b

Good day,

I am trying to make my first responsive layout with the help of the Bootstrap Framework.

As a base layout I have taken an example template and I am now trying to modify this template.

I have added the following:

    <div class="row col-xs-12 col-md-6 border1" id="HeadBar">
        This is not showing up
    </div>

Here I want to place the page header (logo and pany title)

My CSS code :

#HeadBar {
    background-color: #ffffff;
    height: 10%;
    width: 100%;
    position: relative;
    display: block;
}
#HeadBar h1 {
    margin: 0px;
    padding: 10px;
}

The problem is.. The #HeadBar doesn't show up at all. Let alone being responsive.

Adding a H1 tag does make it visible. But I want it to be visible without any additions.

I hope that anyone could see my errors. I know this is very basic. But I need to get a hang of it

/

Good day,

I am trying to make my first responsive layout with the help of the Bootstrap Framework.

As a base layout I have taken an example template and I am now trying to modify this template.

I have added the following:

    <div class="row col-xs-12 col-md-6 border1" id="HeadBar">
        This is not showing up
    </div>

Here I want to place the page header (logo and pany title)

My CSS code :

#HeadBar {
    background-color: #ffffff;
    height: 10%;
    width: 100%;
    position: relative;
    display: block;
}
#HeadBar h1 {
    margin: 0px;
    padding: 10px;
}

The problem is.. The #HeadBar doesn't show up at all. Let alone being responsive.

Adding a H1 tag does make it visible. But I want it to be visible without any additions.

I hope that anyone could see my errors. I know this is very basic. But I need to get a hang of it

https://jsfiddle/ferencik/zb50wgve/

Share Improve this question asked Oct 15, 2015 at 9:23 AlexAlex 1,3092 gold badges20 silver badges31 bronze badges 3
  • 2 you shouldnt add row to divs that also have column classes. rows are wrappers for columns – Alex Commented Oct 15, 2015 at 9:29
  • this is float issue – Sachink Commented Oct 15, 2015 at 9:37
  • Simply use a div instead of applying all kind of classes just use ID #headbar as you are using currently, it will work. @Alex – CreativePS Commented Oct 15, 2015 at 9:38
Add a ment  | 

8 Answers 8

Reset to default 1

Still need some addition, like adding z-index:1001 (or any value more than 1000 because you have class navbar-static-top in your nav - it have z-index:1000 - which overlap your #HeadBar) in #HeadBar

#HeadBar {
    background-color: #FFF;
    width: 100%;
    position: relative;
    display: block;
    height: 10%;
    z-index: 1001;
}

Add z-index: 9999; to the css.

Fiddle

Instead of using z-index, i would remend fixing your position issues which are the actual cause of the problem.

I would also remove the class .row from the #headBar div. .row is used for margins within a container and shouldn't be use on the parent container itself.

On .navbar, I have set the position back to initial as it was always fixing to the top of the parent instead of finding its place below the previous sibling.

/* GLOBAL STYLES
-------------------------------------------------- */

/* Padding below the footer and lighter body text */

body {
  margin: 0px;
  padding: 0px;
  padding-bottom: 40px;
  color: #5a5a5a;
}
/* CUSTOMIZE THE NAVBAR
-------------------------------------------------- */

/* Special class on .container surrounding .navbar, used for positioning it into place. */

.navbar-wrapper {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  z-index: 20;
}
/* Flip around the padding for proper display in narrow viewports */

.navbar-wrapper > .container {
  padding-right: 0;
  padding-left: 0;
}
.navbar-wrapper .navbar {
  padding-right: 15px;
  padding-left: 15px;
  position: initial;
}
.navbar-wrapper .navbar .container {
  width: auto;
}
/* CUSTOMIZE THE CAROUSEL
-------------------------------------------------- */

/* Carousel base class */

.carousel {
  height: 500px;
  margin-bottom: 60px;
}
/* Since positioning the image, we need to help out the caption */

.carousel-caption {
  z-index: 10;
}
/* Declare heights because of positioning of img element */

.carousel .item {
  height: 500px;
  background-color: #777;
}
.carousel-inner > .item > img {
  position: absolute;
  top: 0;
  left: 0;
  min-width: 100%;
  height: 500px;
}
/* MARKETING CONTENT
-------------------------------------------------- */

/* Center align the text within the three columns below the carousel */

.marketing .col-lg-4 {
  margin-bottom: 20px;
  text-align: center;
}
.marketing h2 {
  font-weight: normal;
}
.marketing .col-lg-4 p {
  margin-right: 10px;
  margin-left: 10px;
}
/* Featurettes
------------------------- */

.featurette-divider {
  margin: 80px 0;
  /* Space out the Bootstrap <hr> more */
}
/* Thin out the marketing headings */

.featurette-heading {
  font-weight: 300;
  line-height: 1;
  letter-spacing: -1px;
}
/* RESPONSIVE CSS
-------------------------------------------------- */

@media (min-width: 768px) {
  /* Navbar positioning foo */
  .navbar-wrapper {
    margin-top: 0px;
  }
  .navbar-wrapper .container {
    padding-right: 15px;
    padding-left: 15px;
  }
  .navbar-wrapper .navbar {
    padding-right: 0;
    padding-left: 0;
  }
  /* The navbar bees detached from the top, so we round the corners */
  .navbar-wrapper .navbar {
    border-radius: 4px;
  }
  /* Bump up size of carousel content */
  .carousel-caption p {
    margin-bottom: 20px;
    font-size: 21px;
    line-height: 1.4;
  }
  .featurette-heading {
    font-size: 50px;
  }
}
@media (min-width: 992px) {
  .featurette-heading {
    margin-top: 120px;
  }
}
#HeadBar {
  background-color: #ffffff;
  height: 10%;
  width: 100%;
  position: relative;
  display: block;
}
#HeadBar h1 {
  margin: 0px;
  padding: 10px;
}
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn./bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn./bootstrap/3.3.5/css/bootstrap-theme.min.css">
<script type="text/javascript" src="https://maxcdn.bootstrapcdn./bootstrap/3.3.5/js/bootstrap.min.js"></script>
<div class="navbar-wrapper">
  <div class="container">
    <div class="col-xs-12 col-md-6 border1" id="HeadBar">
      This is not showing up
    </div>
    <nav class="navbar navbar-inverse navbar-static-top">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <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="#">Project name</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
          <ul class="nav navbar-nav">
            <li class="active"><a href="#">Home</a>
            </li>
            <li><a href="#about">About</a>
            </li>
            <li><a href="#contact">Contact</a>
            </li>
          </ul>
        </div>
      </div>
    </nav>
  </div>
</div>

  • JSFiddle

With bootstrap, you have to separate row DIVs with col-... ones, like this:

 <div class="row" id="HeadBar">
     <div class="col-xs-12 col-md-6 border1">
       Something to show
     </div>
</div>

Because col-... divs use float system, and row allows to clear your DOM. By the way, using % for height with a static or relative position does not work. You have to use pixels, em or what you want.

#HeadBar {
   background-color: #ffffff;
   min-height: 50px; // example
   width: 100%;
   position: relative;
   display: block;
}

or simply use fixed or absolute property to set a pourcentage value:

 #HeadBar {
   background-color: #ffffff;
   height: 10%;
   width: 100%;
   position: fixed;
   left: 0;
   top: 0;
   display: block;
}

Hope it will help !

CSS

Change Add the property in class .navbar-wrapper .navbar

 float:left;
 width:100%

See the fiddle https://jsfiddle/zb50wgve/4/

OR

Structural changes

Add wrap up of .row for #HeadBar. and remove the class row from #HeadBar

Code:

<div class="row">
    <div class=" col-xs-12 col-md-6 border1" id="HeadBar">
          This is not showing up
    </div>
</div>

See fiddle : https://jsfiddle/zb50wgve/5/

First, question to solve this is what are you trying to achieve? this element with text should be fixed? static?

Second, the element with class row must wrap the elements with col-something-number

Thrid, If the nav is static don't break the nav ponent just add a div on top, see this fiddle https://jsfiddle/6evtc3ry/

Simply use a div instead of applying all kind of classes just use #headbar as you are using

<div id="HeadBar" class="">
                This is not showing up
            </div>

This will work well

You can use this,

#HeadBar 
{
  display:inline-flex;
  height:10%;
  width:100%;
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744255313a4565368.html

相关推荐

  • javascript - HTML CSS, Bootstrap responsive DIV height - Stack Overflow

    Good day,I am trying to make my first responsive layout with the help of the Bootstrap Framework.As a b

    8天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信