Div标签高度问题

时间:2015-09-01 07:16:47

标签: html css

我有以下div标签:(更多html的容器)

这是最外层的div标签。

<div id="top">
    <h1 style="float:left;margin:0;font-family:Impact;color:#9A3334;border:0px;padding:0px;">EasyCounter</h1>
    <label style="float:left;margin-left:10px;">
        <meteor-include src="loginButtons" style="color:black;font-size:14pt;"></meteor-include>
    </label>
</div>
<div id="main-content">

    <div id="left">
        <button id="meal-button" data-toggle="modal" data-target="#myModal" data-backdrop="static">Add Meal</button>

        <!-- Modal -->
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <!--1-->
            <div class="modal-dialog" role="document"> <!--2-->
                <div class="modal-content" ng-controller="formCtrl"> <!--3-->
                    <div class="modal-header"> <!--4-->
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close" ng-click="clear()"><span aria-hidden="true">&times;</span></button>
                        <h2 class="modal-title" id="myModalLabel">Meal</h2>
                    </div> <!--/4-->

                    <div class="modal-body"> <!--5-->
                        <label>Description :
                            <input type="text" ng-model="meal.description">
                        </label>
                        <div ng-repeat="item in meal.items"> <!--6-->
                            <label>Item {{$index+1}} :
                                <input type="text" class="item" ng-model="item.name"><br>
                            </label>
                            <label>Calories :
                                <input type="number" class="calories" ng-model="item.cal"><br>
                            </label>
                            <br>
                        </div> <!--/6-->

                    <div class="modal-footer"> <!--7-->
                        <button ng-click="clear()" style="box-shadow:none;outline:none;" class="btn btn-default" data-dismiss="modal">Close</button>
                        <button ng-click="submit()" class="btn btn-primary" id="submit">Submit</button>
                        <button ng-click="addItem()" class="btn btn-primary">+Item</button>
                    </div> <!--/7-->

                </div> <!--/5-->
             </div> <!--/3-->
          </div> <!--/2-->
        </div><!--/1-->
        <!--/Modal-->

    </div> <!--/left-->

    <div id="right" ng-controller="resultCtrl">
        <label id="date">
            Today's Date : {{todayDate}}
        </label>
    </div>

</div><!--/main-content-->

这是我的CSS:

html,body {
 font-family: "garamond";
 height: 100%;
}

#top {
  width: 100%;
  height: 50px;
  background-color: #3399FF;
}

#main-content {
  width: 100%;
  height: 100%;
  background-color: #F3EFE0;
  border: 5px white solid;
}

#left {
  margin-top:100px;
  margin-left: 170px;
  height: 100%;
  width: 150px;
  text-align: center;
}

#right {
  margin-top: -50px;
  margin-left: 650px;
  height: 100%;
  width: 550px;
}

#meal-button {
  width: 250px;
  height: 50px;
  background-color: #217C7E;
  border-color:transparent;
  font-size: 25px;
  border-radius: 5px;
  font-family: "garamond";
  font-weight: bold;
  box-shadow: none;
  display: inline;
  color: white;
}

#date {
  text-align:center;
  font-family:garamond;
  font-size:25pt;
  color:white;
  height:50px;
  width:550px;
  border-radius: 5px;
  background-color: #9A3334;
}

我的应用程序基本上将包含一个表,当用户向其添加数据时,该表将变得越来越长。我认为以下的CSS可以工作,我为了测试而设置了一个仅用于视觉加的边框,出于某种原因,它没有覆盖整个页面。只有在主要内容容器中的HTML元素结束之前。为什么会这样?

我希望背景能够覆盖整个页面。这就是目前正在发生的事情: enter image description here

2 个答案:

答案 0 :(得分:1)

正如上面的Deepak和timo已经提出的那样,这应该有效:

html, body{
    height:100%;
}
#main-content {
  width: 100%;
  height: 100%;
  background-color: #F3EFE0;
  border: 1px black solid;
}

Here is the JSFiddle demo

答案 1 :(得分:0)

尝试在您的body标记结束之前在html页面的引导中添加此内容 -

<script>    
    var canvasHeight = $(window).height();    
    $(document).ready(function (){    
        $('#main-content').css('min-height', canvasHeight)    
    });    
</script>