我想中心我的按鈕'瀏覽器投資組合'使用margin:0px auto; 。請有人可以善意解釋爲什麼這不工作使用下面的HTML和CSS?保證金:0px auto;不會中心元素
<div class="portfolio">
<div class="container">
<h3>Portfolio</h3>
<div class="group1">
<img src="http:....." style="height: 506px; width: 675px">
<div class="group2">
<h3>Client</h3>
<h4>JPMorgan</h4>
<h3>Role in Project</h3>
<h4>Project Lead</h4>
<h3>Project Included</h3>
<h4>Mobile and Web Interface</h4>
<a href="#">Browser</a>
</div>
</div>
<div class="group3">
<a href="#">Browser Portfolio</a>
</div>
</div>
</div>
<style>
.portfolio .group3 {
font-size: 0.9em;
padding: 0.7em 1.5em;
color: #5EC7E5;
border-radius: 5px;
font-weight: 600;
border: 1px solid red;
position: relative;
margin: 0px auto;
display: inline-block;
width: 100%;
}
</style>
'.group3 {text-align:center; }' – Turnip
謝謝。該解決方案有效。但是,對於我自己的發展和學習,我不明白爲什麼。是否有使用邊距的某些先決條件:0px auto; ? –
@mugman是的 - 顯示:塊和明確的寬度。請看我的答案。 – beercohol