I have this code:
<div class="outer">
<ul class="list">
<li class="inner">
<div class="line">information1</div>
<div class="line">hyperlink1</div>
</li>
<li>
<div class="line">information2</div>
<div class="line">hyperlink2</div>
</li>
<li>
<div class="line">information3</div>
<div class="line">hyperlink3</div>
</li>
<li>
<div class="line">information4</div>
<div class="line">hyperlink4</div>
</li>
</ul>
<input type="submit" id="send" value="send" class="button"/>
</div>
and the css:
.outer
{
display: table;
border: 1px solid;
padding: 5px;
}
.list
{
list-style: none;
padding: 5px;
}
.inner
{
display: table-row;
padding: 5px;
}
.line
{
display: table-cell;
border: 1px solid;
border-radius: 5px;
}
.button
{
top:50%;
left:50%;
}
the output is: this
Now i want to place the button in the center of the 'outer' div no matter what is the width.
example: i want the button to be in center even for: this. without having to change the css each time the div size changes. Even if the 'outer' div is dynamic, the button should be in the center.
thank you.
We can align the buttons horizontally as well as vertically. We can center the button by using the following methods: text-align: center - By setting the value of text-align property of parent div tag to the center. margin: auto - By setting the value of margin property to auto.
You can center a block level element by setting margin-left and margin-right to auto . We can use the shorthand margin: 0 auto to do this. (This also sets margin-top and margin-bottom to zero.)
This achieves what you're looking for in a simple, succinct, way:
.button {
display:block;
margin: 0 auto;
}
You need to give the button a specific width and then you can use automatic margins
.button {
display: block;
margin: 0 auto;
}
http://fiddle.jshell.net/CrHyd/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With