我建议把它拨回来一点,让自己脱离你的框架或你正在使用的任何东西。要水平居中,有两种方法。
您必须根据是否希望按钮定位:inline、inline-block 或 block 来决定。对于移动设备和手指以及所有这些东西(2014 年) - 我建议使用 inline-block 或 block。所以 -
如果它是内联块,那么您可以将其视为文本。将父级设置为text-align center;
如果它被阻止,那么您可以使用margin-right: auto; margin-left: auto;
但还有其他问题。就像所有其他人认为的那样,它需要适当地组织,这样它们就不会相互浮动并搞砸一切。我建议你这样做:jsfiddle
PS - 我们不需要在你的小提琴中看到这么多代码。只用最基本的必需品就更容易解决问题。祝你好运。
HTML
<aside class="service">
<header>
<h2 class="">Title of module thing</h2>
</header>
<div class="text-wrapper">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua Lorem ipsum dolor sit amet…</p>
<a href="#" class="button button-large"><i class="fa fa-credit-card" style="padding-right:10px;"></i> Learn More</a>
</div> <!-- .text-wrapper -->
</aside> <!-- .service -->
CSS
*, *:before, *:after {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
} /* start your projext off right */
.service {
border: 1px solid #2ecc71;
font-family: helvetica;
text-align: center;
}
.service header {
background-color: #2ecc71;
}
.service header h2 {
font-size: 1.3em;
font-weight: 400;
color: white;
/* text-align: center; */ /* the parent should have this - not the element */
/* width: 100%; */ /* this is already default because it is a block element */
margin: 0;
padding: .5em;
}
.service .text-wrapper {
padding: 1em;
}
.service p {
text-align: left;
font-size: .9em;
}
.button {
display: inline-block; /*so it's like... "inline" - and can be centered */
background-color: #2ecc71;
text-decoration: none;
color: white;
text-transform: uppercase;
padding: 1em 2em;
-webkit-border-radius: 5px;
border-radius: 5px;
}