【发布时间】:2026-01-05 02:55:01
【问题描述】:
我正在学习初学者 html 和 css 课程,我们正在创建一个单页简历。它有一些带有照片等的标题,然后是一些中间有照片的文本。
html 说:
<body>
<header>
<h1>Name Surname</h1>
<h2>Blogger</h2>
<p>
<a href="http://facebook.com"><img src="http://bit.ly/1Waz24Q" alt="Facebook Icon" /></a>
<a href="http://twitter.com"><img src="http://bit.ly/1Waz2BY" alt="Twitter Icon" /></a>
<a href="https://plus.google.com"><img src="http://bit.ly/1Waz6lg" alt="Google Plus Icon" /></a>
<a href="http://pinterest.com"><img src="http://bit.ly/1Waz9NH" alt="Pinterest Icon" /></a>
</p>
</header>
<main>
<h3>Background</h3>
<p>I've been rolling solo since 2014, but previously jammed with a bunch of tech startups like Dropbox, Codecademy, and Treehouse. My recent work is a departure from my product-centric past, focusing on 3D illustration, animation, and motion design.</p>
<p><img src="http://los40tuxtla.com/wp-content/uploads/2015/05/nrm_1410437342-blake-lively-gucci-hp.jpg" alt="Foto Blanca"/></p>
<p>That's kind of what it's all about, y'know? Feeling out our path, taking creative risks, and knocking it out of the park without taking it too seriously. I get into specific tactics and proven strategies, but it's also an ongoing conversation about growth, meaning, and happiness.</p>
<p>I've met lots of creative and curious people through my newsletter, where we talk shop and share experiences. I'd love to meet you, too!</p>
<h3>Filosofia</h3>
<p>I'm a lifelong learner and love to gather new skills and study extraordinary people. I believe 1) being exceptional is often just putting in more effort than anyone expects, 2) releasing our ego is a prerequisite for growth, and 3) life is too important to take seriously. Party on!</p>
</main>
</body>
我想使图像居中。
老师/课上说,因为图片在段落之间,我们可以在css中添加:
p {
margin-left: auto;
margin-right: auto;
}
这似乎在她的工作:http://i.stack.imgur.com/mmh7J.png
但我猜这只是因为她的照片更小。在我的它根本不起作用!看:
http://i.stack.imgur.com/16Wvg.png
我已经尝试过以任何我能想到的方式将其居中:直接在 css 中添加 img margin right auto 和 margin left auto ,还有 img text-align center 等。但没有任何效果
但是,最重要的是,我想知道为什么她所说的不起作用。我想学习这两件事:为什么这不起作用以及如何使我的图像居中
谢谢!
【问题讨论】:
-
我已经更新了我的答案...更正了一个错字。