gpt4 book ai didi

html - margin : 0px auto; will not center element

转载 作者:行者123 更新时间:2023-11-28 15:59:18 25 4
gpt4 key购买 nike

我正在尝试使用 margin: 0px auto; 将我的按钮“浏览器组合”居中; .请有人解释为什么使用下面的 html 和 CSS 不起作用?

<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>

最佳答案

使用 margin: auto 居中元素, 他们必须使用 display: block并且有明确的宽度。

将此类添加到您的 css 将使其工作:

.group3 a {
display: block;
width: 110px;
margin: 0 auto;
}

或者您可以使用 text-align: center正如其他答案所说。

在这里查看 JS Fiddle:http://jsfiddle.net/rbuzach0/

编辑:当您询问为什么某些属性没有从您包含的 <div> 继承时给你的<a> ,这是一个列表(来自 CSS2.1 规范,但这是我能以简明形式找到的所有内容)哪些属性将继承,哪些不会:http://www.w3.org/TR/CSS21/propidx.html

勾选“继承?”柱子。您会看到 Display 和 Margin 都没有继承。

关于html - margin : 0px auto; will not center element,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32024445/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com