为什么每增加一个链接我的div会更高?

时间:2015-02-25 21:10:09

标签: html css

我在div#链接中添加的链接越多,它相对于其他div就越高。为什么呢?

http://jsfiddle.net/8n07eans/

<body>
    <div id="pageWrapper">
        <div id="plan">
            <div class="heading">
                Plan
            </div>
        </div>
        <div class="links">
            <div class="heading">
                Links 1
            </div>
            <a href="#">Link 1</a><br/>
            <a href="#">Link 2</a>
        </div>
        <div class="links">
            <div class="heading">
                Links 2
            </div>
        </div>
        <div class="links">
            <div class="heading">
                Links 3
            </div>
        </div>
        <div id="notes">
            <div class="heading">
                Notes
            </div>
        </div>
        <div class="links">
            <div class="heading">
                Links 3
            </div>
        </div>
        <div id="gallery">
            <div class="heading">
                Gallery
            </div>
        </div>
    </div><!--end pageWrapper-->
</body>
</html>



* {
    margin: 0px;
    padding: 0px;
    border: none;
}

body {
    background-color: rgb(30,30,30);
}

#pageWrapper {
    width: 1200px;
    height: 650px;
    background-color: rgb(30,30,30);
    color: rgb(230,230,230);
    margin: 10px auto 0px auto;;
    font-family: Tahoma, sans-serif;
    font-size: 18px;
    padding: 20px 0px;
}

a:link, a:visited {
    color: rgb(184,216,5);
    text-decoration: none;
}

a:hover, a:active {
    color: rgb(184,216,5);
    text-decoration: underline;
}

#plan , #notes, #gallery{
    border: 3px solid rgb(230,230,230);
    border-radius: 10px;
    width: 452px;
    height: 280px;
    display: inline-block;
    margin: 0px 5px 10px 5px;
}

.links {
    border: 3px solid rgb(230,230,230);
    border-radius: 10px;
    width: 215px;
    height: 280px;
    display: inline-block;
    margin: 0px 5px 10px 5px;
}

.heading {
    width: 150px;
    margin: 0px auto 5px auto;
    text-align: center;
    font-size: 0.8em;
}

.links a {
    margin-left: 30px;
}

2 个答案:

答案 0 :(得分:3)

vertical-align:top添加到.links课程。应该使所有div对齐。

答案 1 :(得分:0)

您需要使用以下属性:

    vertical-align: top;

因此,只需修改您的#plan, #notes, #gallerylinks课程,如下所示:

#plan, #notes, #gallery {
    border: 3px solid #E6E6E6;
    border-radius: 10px;
    width: 452px;
    height: 280px;
    display: inline-block;
    margin: 0px 5px 10px;
    vertical-align: top;
}

见以下工作:

&#13;
&#13;
* {
	margin: 0px;
	padding: 0px;
	border: none;
}

body {
	background-color: rgb(30,30,30);
}

#pageWrapper {
	width: 1200px;
	height: 650px;
	background-color: rgb(30,30,30);
	color: rgb(230,230,230);
	margin: 10px auto 0px auto;;
	font-family: Tahoma, sans-serif;
	font-size: 18px;
	padding: 20px 0px;
}

a:link, a:visited {
	color: rgb(184,216,5);
	text-decoration: none;
}

a:hover, a:active {
	color: rgb(184,216,5);
	text-decoration: underline;
}

#plan , #notes, #gallery{
	border: 3px solid rgb(230,230,230);
	border-radius: 10px;
	width: 452px;
	height: 280px;
	display: inline-block;
	margin: 0px 5px 10px 5px;
    vertical-align:top;
}

.links {
	border: 3px solid rgb(230,230,230);
	border-radius: 10px;
	width: 215px;
	height: 280px;
	display: inline-block;
	margin: 0px 5px 10px 5px;
    vertical-align:top;
}

.heading {
	width: 150px;
	margin: 0px auto 5px auto;
	text-align: center;
	font-size: 0.8em;
}

.links a {
	margin-left: 30px;
}
&#13;
<body>
	<div id="pageWrapper">
		<div id="plan">
			<div class="heading">
				Plan
			</div>
		</div>
		<div class="links">
			<div class="heading">
				Links 1
			</div>
			<a href="#">Link 1</a><br/>
			<a href="#">Link 2</a>
		</div>
		<div class="links">
			<div class="heading">
				Links 2
			</div>
		</div>
		<div class="links">
			<div class="heading">
				Links 3
			</div>
		</div>
		<div id="notes">
			<div class="heading">
				Notes
			</div>
		</div>
		<div class="links">
			<div class="heading">
				Links 3
			</div>
		</div>
		<div id="gallery">
			<div class="heading">
				Gallery
			</div>
		</div>
	</div><!--end pageWrapper-->
</body>
</html>
&#13;
&#13;
&#13;