我不明白为什么我会得到不受欢迎的空间,我希望clubs
和events
div在同一高度但在header
div下。
html:
<!DOCTYPE html>
<html>
<head>
<title>Metzo</title>
<link rel="stylesheet" type="text/css" href="index.css">
</head>
<body>
<div class="metzo">
<div class="header">
</div>
<!-- Getting a huge space here in the y-axis -->
<div class="clubs">
hello
</div>
<div id="space1"> </div>
<div class="events">
hello
<?php
//include("event.php");
//include("event.php");
//include("event.php");
?>
</div>
</div>
</body>
</html>
css:
html {background-color:black;}
html, body { height: 100%; width: 100%; margin-top: 1%; color:white;}
.metzo
{
width:80%;
height: 80%;
padding:0px;
margin-left:10%;
margin-right:10%;
/*margin-bottom:5%;*/
text-align:center;
}
.header
{
width:100%;
height:10%;
border:solid thick white;
}
.clubs
{
display:inline-block;
width:45%;
height:100%;
border:solid thick white;
margin-top:0px;
}
#space1 {
display:inline-block;
width:3%;
height:100%;
float:top;
/*border:solid thick white;*/
}
.events
{
display:inline-block;
width:45%;
height:100%;
border:solid thick white;
text-align:center;
}
答案 0 :(得分:3)
小提琴:http://jsfiddle.net/UC7GE/
#space1
到底是什么意思?我的解决方案在元素上使用box-sizing
来指定流体宽度和固定边框宽度:
.clubs,
.events {
box-sizing: border-box;
width: 46.5%;
margin: 0
}
.events {
margin-left: 3%; // instead of #space1
}
编辑:我意识到#space1
是.clubs
和.events
之间的空格,但将空元素简单地用作间隔。没有它,这个解决方案很好!
答案 1 :(得分:2)
对.metzo类使用height auto
.metzo {
width:80%;
height: auto;
padding:0px;
margin-left:10%;
margin-right:10%;
/*margin-bottom:5%;*/
text-align:center;
}
答案 2 :(得分:2)
#space1 {
display:inline-block;
width:3%;
height:10%; /*Change the height*/
float:top;
}
您正在定义相对于父元素的高度,在本例中为metzo
答案 3 :(得分:2)
改变CSS metzo身高:自动;
.metzo {
height: auto;
margin-left: 10%;
margin-right: 10%;
padding: 0;
text-align: center
width: 80%;
}
答案 4 :(得分:1)
.metzo height弥补差距
.metzo
{
width:80%;
/*height: 80%;*/
padding:0px;
margin-left:10%;
margin-right:10%;
/*margin-bottom:5%;*/
text-align:center;
}