我想将这两张图片对齐在此网站的顶部http://paulcwebster.com 旁边的文字。
到目前为止,我能够将两个图像彼此对齐,但我遇到的问题是:
1)图像之间没有任何空格。
2)文本对于不同浏览器上的图像来说太短或太长。
3)没有文字大小与图片的网站相匹配
4)之后无法将“最近出版物”文本移到左侧(我已经将对齐=“左”并将其放入其自己的div中)
这是我的代码:
<div >
<img src="gfx/FrontImage1.jpg" width="180" height="180" alt="Image1" style="float:left">
<img src="gfx/FrontImage3.jpg" width="180" height="180" alt="Image2" style="float:left">
<span ><p>Paul Christopher Webster is a freelance writer and documentary film director based in Toronto, Canada. He has reported from 20 countries since 1992.</p>
Paul's work in film has appeared on the Arte, BBC, CBC, Deutsche Welle, Discovery, National Geographic, Slice, SWR and Vision Television networks. His work as a writer has been published in dozens of magazines, journals and newspapers across Canada, the U.S, and Europe. </p>
<p>He has won four national magazine awards for his writing, and Tier One Journalism Award from the Canadian Institutes of Health Research. His work on documentary films has garnered awards from the Canadian Association of Journalists, Hot Docs, the Canadian Academy of Film and Television, and PARISCIENCE, the international festival of scientific films.
<p>Paul’s work focuses on themes in business, science, and politics. For samples of his work in these categories, please click on the links to articles below.
</span>
</div>
答案 0 :(得分:2)
首先,我建议重构HTML标记。在要控制的每个元素周围放置<div>
或其他块级元素。像这样:
<div class="container">
<div class="photos">
<img src="gfx/FrontImage1.jpg" width="180" height="180" alt="Image1">
<img src="gfx/FrontImage3.jpg" width="180" height="180" alt="Image2">
</div>
<div class="text">
Your text goes here...
</div>
</div>
然后,编写一些CSS来按照你想要的方式控制这些元素:
.container {
overflow:hidden; // this keeps the floated objects inside the container
padding:5px;
border:solid 1px black;
}
.container .photos {
float:left;
margin-right:10px; // this puts some padding to the right of the photos
}
我假设您知道如何包含样式表以将上述CSS应用于您的页面。这应该解决问题1)和4)。确实没有任何方法可以确保文本的大小始终与图像的高度相匹配,因为它可以流动和更改,具体取决于浏览器的宽度和查看器使用的字体大小,所以我没有办法解决问题2)和3)。
注意:我发现您使用<span>
元素来包含<p>
个元素。这是无效标记,因为<span>
是内联元素,而<p>
是块级元素。内联元素不能包含块级元素。