Horizontally aligning button
button, css, html
Solution
Give the button a width. See this jsFiddle example.
.download-button {
padding: 10px 20px;
border-radius: 5px;
display: block;
width: 130px;
margin: 10px auto 0px auto;
}
Without a width, you're trying to center a block level element that is the full width of it's container. By explicitly setting a width (for example 130px on your button) the margin centering rule works.
Problem
I'm trying to horizontally align a button using CSS. Here's my markup: ``` <button type="button" class="primary-button download-button">Download</button> ``` And my relevant CSS: ``` .primary-button { font-family: Arial, sans-serif; font-size: 1.3em; color: #fff; border: 1px solid #004487; background-image: -webkit-gradient(linear, top, bottom, from(#5288bd), to(#2f659a)); background-image: -webkit-linear-gradient(top, #5288bd, #2f659a); box-shadow: inset 0px 1px 0px rgba(255, 255, 255, 0.4), inset 0px 0px 0px 1px rgba(255, 255, 255, 0.2), 0px 1px 0px rgba(255, 255, 255, .7); text-shadow: 0px -1px 0px black; cursor: pointer; } .download-button { padding: 10px 20px; border-radius: 5px; display: block; margin: 10px auto 0px auto; } ``` However, it's still aligned to the left. I thought setting `margin: 10px auto 0px auto;` would horizontally align it seen as it's now a block element but apparently not. I've also tried wrapping it in a div and using `text-align: center` but that doesn't work either.