简体   繁体   English

html div不能完全显示

[英]html div is not taking full height

Hi below is my css & html,i'm trying to align two div in a webpage with full height(100%) but is not working 您好,下面是我的CSS和html,我正在尝试将网页中的两个div对齐为全高(100%),但无法正常工作

.left_menu
 {
   height:100% !important;
   width:30%;
   border:1px solid grey;
   float:left;
 }

.right_menu
{
  height:100% !important;
  width:70%;
  border:1px solid grey;
  float:right;
}

and this is my html 这是我的HTML

<div class="left_menu">
</div>
<div class="right_menu">
</div>

this code is not taking full height,please help 此代码未完全显示,请帮助

set html,body min-height to 100% 设置html,body最小高度为100%

Child occupies the height of parent so 100% height of parent will give 100% height to child 孩子占据父母的身高,所以父母100%的身高将给孩子100%的身高

Considering that you div is direct child of html,body(if not then you need to maintain the height ratio with its parent) 考虑到div是html,body的直接子代(如果不是,则需要与其父代保持高度比)

html,body{
height:100%;
 min-height:100%; 
}

I think that problem is in your border properties as they are adding extra space. 我认为问题出在您的border属性上,因为它们增加了额外的空间。 So, I am not sure if this fit best your needs, but I would do something like this: 因此,我不确定这是否最适合您的需求,但是我会这样做:

.left_menu
 {
   height:100% !important;
   width:29%;
   border:1px solid grey;
   float:left;
 }

.right_menu
{
  height:100% !important;
  width:69%;
  border:1px solid grey;
  float:left;
}

EDIT: This might be better solution, because previous one will work different for devices with different width(for small device right_menu goes under left_menu ). 编辑:这可能是更好的解决方案,因为对于宽度不同的设备(对于小型设备, right_menuleft_menu下),上一个版本将工作不同。 Here I just specify width for left_menu . 在这里,我只为left_menu指定width

 .left_menu
 {
  height:100% !important;
  width:30%;
  border:1px solid grey;
  float:left;
 }

 .right_menu
{
  height:100% !important;
  border:1px solid grey;
}

You set the height of the div to 100% but 100% of what? 您将div的高度设置为100%,但是100%是什么? It's always 100% of the parent element but what is the parent element of the div set to? 它始终是父元素的100%,但是div的父元素设置为什么? My bet is you don't have it set to anything and the browser has no way of calculating what 100% of nothing is. 我敢打赌,您没有将其设置为任何值,并且浏览器无法计算出100%为零。

Just add display: inline-block; 只需添加display: inline-block; and it should solve the problem (did for me) 它应该可以解决问题了(对我而言)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM