I’ve tried every way of centering elements in CSS that I know but I cannot get these form elements to center on the page.
My code: http://jsfiddle.net/VJLst/1/
<style>
#divQuizFillBlank {
margin-left: auto;
margin-right: auto;
}
#textQuizFillBlankUserAnswer {
border: 2px solid #000;
font-size: 16px;
font-weight: bold;
width: 80%;
height: 40px;
float: left;
box-sizing: border-box;
vertical-align: middle;
}
#buttonQuizFillBlankSubmit {
border: 2px solid #000;
font-size: 20px;
font-weight: bold;
width: 10%;
height: 40px;
float: left;
margin-left: 5px;
}
</style>
<div id="divQuizFillBlank">
<input type="text" id="textQuizFillBlankUserAnswer">
<input type="button" id="buttonQuizFillBlankSubmit" value=">">
</div>
You need to set the
widthfor#divQuizFillBlank.The rule
margin: auto;doesn’t work for elements without awidth. Moreover, it works only forblockelements and those elements take up full available width.Updated Fiddle: http://jsfiddle.net/praveenscience/VJLst/2/