jtbitt
jtbitt

Reputation: 581

Why does this div refuse to expand to 100% height?

I'm working on an Angular project. I have the skeleton up, and I'm trying to design the partials that get inserted by 'ng-view'. When I try to set the background-image on the about id (i switched to color for the question), it automatically sets that div to 0px, even though I set height at 100%. html/body height are set at 100%, yet it continues not to work. I've tried the answers to numerous similar questions but it still isn't working. Why is this? Btw, I'm using a section because I'm making a scrolling site. So when I say div, I mean section.

Note: If I set the height to 500px for example, it shows up. Percentages aren't working though.

Main page-

<body ng-app="jayPortfolio" ng-controller="mainController as main">

  <!-- NAVBAR -->
  <header id="main-header">
    <nav class="navbar navbar-inverse navbar-fixed-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="#">JAY</a>
        </div>

        <div id="navbar" class="navbar-collapse collapse">
          <ul class="nav navbar-nav navbar-right">
            <li><a href="#contact">About</a></li>
            <li><a href="#contact">Portfolio</a></li>
            <li><a href="#contact">Experience</a></li>
            <li><a href="#contact">Contact</a></li>
          </ul>
        </div>
      </div>
    </nav>
  </header>

  <!-- LOAD OTHER PAGES HERE -->
  <main id="main-pages">
   <div ng-view></div>
  </main>
</body>

Partial-

<section id="about">    
</section>

CSS-

html, body {
  height: 100%;
  width: 100%;
  margin: 0;
}

#about {
  height: 100%;
  width: 100%;
  /*background-image: url('../../images/jay-ocean.jpg');*/
  background-color: green;
  background-repeat: no-repeat;
  position: relative;
}

ANSWER-

Named div ng-view, #ng-view, than updated the CSS below. As seen in Alexei's answer.

html, body, main, #ng-view {
  height: 100%;
  width: 100%;
  margin: 0;
}

Upvotes: 0

Views: 1023

Answers (2)

Alexei Darmin
Alexei Darmin

Reputation: 2129

https://jsfiddle.net/4wovvt6p/1/

As I mentioned in my comment, you applied the height:100% to the body, and the section but did not apply it to the containing div. By default a div starts at 0px and expands based on content, if your content is 100% then it is 100% of 0px, thus still 0.

Upvotes: 1

Nikerym
Nikerym

Reputation: 515

it was my understanding you cannot set a height of a CSS object based on %, i'm relatively bad at CSS so I could be wrong, though I remember that being the outcome when I had the same issue a few months back.

Upvotes: 0

Related Questions