我应该在图像周围放置段落标签吗?
我有一个网页,其中有文本和图像。我写一些文字(在一个段落中),然后放置图像,然后放置另一个段落。
我应该在图像周围放置 p 标签,还是应该将其与 img 标签放在中间?
我问这个问题的原因是因为到目前为止我只是在段落之间放置图像,但现在如果我想添加多个图像或添加图像和锚点,那么它们就不能正确地放在一起。我尝试的另一件事是
<p></p>
在两个图像之间添加,但我觉得这是错误的:P
I have a web page where I have text with images. I write some text (in a paragraph) then put an image, then another paragraph.
Should I put p tags around the image too, or should I just leave it in between with just the img tag?
The reason I ask this is because up until now I was just plopping images in between paragraphs, but now if I want to add more than one image or add an image and an anchor then the don't sit together right. The other thing I tried was adding
<p></p>
in between two images but I feel like that is wrong :P
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用 CSS 使图像充当块而不是内联块:
将以下内容放入 CSS 中的某处:
或者如果您想要内联显示一些图像,则添加
class="block"< /code> 到你的 img 标签,并将 css 更改为:
You could use CSS to make the images act as blocks rather than as inline-blocks:
Put the following in your CSS somewhere:
Or if you have some images that you want to display inline, then add
class="block"
to your img tags, and change the css to this:将图像样式设置为块元素是部分解决方案。 HTML 应该被设计为在没有样式的情况下也能“工作”。如果盒模型要求块元素仅包含块或内联元素(而不是混合),那么我们应该在尽可能低的级别上这样做。这就是菜单被创建为列表而不是链接集的原因。这称为优雅降级。
所以恕我直言,
如果图像旁边的节点是块元素,则应在图像周围添加标签。
Styling an image as a block element is a partial solution. HTML should be designed to "work" without styles also. If the box model requires that a block element contains only block or inline elements - not mixed - than we should do so on the lowest possible level. This is why menus are created as lists not sets of links. This is called graceful degradation.
So IMHO the <p> tag around the image should be added if the nodes next to it are block elements.
如果您希望这样布局,我想不出您不使用
的任何理由。这样标记就可以清楚地描述布局。
它肯定比更改所有图像的显示类型更清晰。最好的选择是创建一个 css 类
img.block {display:block;}
+I can't think of any reason why you wouldn't use
<p><img/></p>
if that's how you want it laid out. that way the mark up clearly describes the layout.it is certainly more legible than changing the display type for all images. the best alternative would be to create a css class
img.block {display:block;}
+<img class="block"/>
带或不带
的图像都没有问题。您应该记住的唯一事情是:
的 CSS 可能会以您不希望的方式影响图像的填充、边距或宽度。
将使图像显示为块。
img {display: block;}
包含在 CSS 中,并让显示时不显示
img {display: block;}
和img {display: inline;}
There's nothing wrong in having the images with or without
<p></p>
. The only things you should keep in mind are:<p>
might affect the padding, margin or width of the image in a way that you don't want it to.<p>
will make the image display as block.img {display: block;}
and leave your<img>
appear without<p></p>
img {display: block;}
andimg {display: inline;}