为什么我的Div中心不会在其父母身上呢?

时间:2013-08-01 16:19:28

标签: css html center

我正在为网站制作标题栏。此标题栏由3部分组成:后退按钮,学校信息和登录按钮。问题在于,学校信息中心部门不会居中。我已经尝试了所有我知道如何做的事,没有任何作用。

这是我的HTML和CSS:

/* -- Button Bar -- */

.buttonbarframe {
    width: 100%;
    background-color: #F1F1F1;
	border-bottom: 1px solid #D5D5D5;
	box-shadow: 1px 1px 2px #D5D5D5;
	position: fixed;
	left: 0;
	right: 0;
	top: 0;
	/*height: 65px;*/
	height: 45px;
	
    padding: 10px 0px 10px 0px;
}

/*#buttonbar {
    width: 100%;
	height: 45px;
	padding: 10px 0px 10px 0px;
}*/

.buttonbarspan {
    height: 100%;
}

.buttonbarspanindex {
    width: inherit;
    height: 100%;
	margin: 0px;
}

#buttonbarschoolimage {
    display: block;
    float: left;
	vertical-align: middle;
	height: 44px;
	border: 1px solid #D5D5D5;
}

#buttonbarschoolname {
    display: block;
	padding: 0px;
	margin-top: 4px;
	text-align: left;
	vertical-align: middle;
	float: left;
}

.buttonbarrightbutton {
    display: block;
    float: right;
}

.buttonbarsycamorelogo {
    margin: 0 auto;
    display: block;
	text-align: center;
	vertical-align: middle;
	height: 44px;
}

.schoolstuff {
    display: inline-block;		
    margin: 0 auto;
	text-align: center;
	vertical-align: middle;
	width: 341px;
}

.rightbutton {
    float: right;
}

.leftbutton {
    float: left;
}
<div class='buttonbarframe'>
    <div class='leftbutton buttonbarspan'>
        <a class='backbutton btn btn-large btn-danger' href=''><i class='icon-white icon-arrow-left'></i> Logout</a>
    </div>
    <div class='schoolstuff buttonbarspan'>
        <img id='buttonbarschoolimage' src='/Schools/$EntityValue/logo'>
        <h2 id='buttonbarschoolname'>Tri-County School</h2>
    </div>
    <div class='rightbutton buttonbarspan'>
        <input type='submit' class='buttonbarrightbutton btn btn-large btn-primary' href='parentcheckin.php' value='Login'>
    </div>
</div>

以下是问题的一个示例。

Image of the problem. http://www.overclock.net/image/id/6330507/width/900/height/900/flags/LL

2 个答案:

答案 0 :(得分:3)

text-align: center放在父div上将解决此问题。你现在拥有的内容将文本集中在应该已经居中的div中。

请参阅:http://jsfiddle.net/AJmSw/

内联块元素将根据父容器文本对齐进行定位。如果你的两个div都浮动,这将很好。

或者从中心div中删除display: inline-block规则,margin: 0 auto;也可以使div居中 见:http://jsfiddle.net/b4mWU/

答案 1 :(得分:0)

Bootstrap是愚蠢的。有一个CSS问题在我的雷达下飞行。谢谢你的帮助。