我应该在图像周围放置段落标签吗?

发布于 2024-08-19 18:26:47 字数 260 浏览 9 评论 0原文

我有一个网页,其中有文本和图像。我写一些文字(在一个段落中),然后放置图像,然后放置另一个段落。

我应该在图像周围放置 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

十级心震 2024-08-26 18:26:47

您可以使用 CSS 使图像充当块而不是内联块:

将以下内容放入 CSS 中的某处:

img { display: block; }

或者如果您想要内联显示一些图像,则添加 class="block"< /code> 到你的 img 标签,并将 css 更改为:

img.block { display: block; }

You could use CSS to make the images act as blocks rather than as inline-blocks:

Put the following in your CSS somewhere:

img { display: block; }

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:

img.block { display: block; }
北风几吹夏 2024-08-26 18:26:47

将图像样式设置为块元素是部分解决方案。 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.

娜些时光,永不杰束 2024-08-26 18:26:47

如果您希望这样布局,我想不出您不使用

的任何理由。这样标记就可以清楚地描述布局。

它肯定比更改所有图像的显示类型更清晰。最好的选择是创建一个 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"/>

庆幸我还是我 2024-08-26 18:26:47

带或不带

的图像都没有问题。您应该记住的唯一事情是:

  1. 的 CSS 可能会以您不希望的方式影响图像的填充、边距或宽度。

  2. 将使图像显示为块。

  3. 如果这是您唯一的目的,我建议您将该规则作为 img {display: block;} 包含在 CSS 中,并让 显示时不显示

  4. 如果您网站上的图像是块元素和内联元素的混合,我建议为每个元素创建一个类并指定 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:

  1. The CSS for <p> might affect the padding, margin or width of the image in a way that you don't want it to.
  2. <p> will make the image display as block.
  3. If that's your only purpose, I would suggest that you include that rule in your CSS as img {display: block;} and leave your <img> appear without <p></p>
  4. If images on your site will be a mix of block elements and inline elements, I would recommend creating a class for each and specify img {display: block;} and img {display: inline;}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文