简体   繁体   English

如何使用 CSS 在图像下方放置文本?

[英]How do I place text underneath an image with CSS?

I want to place text underneath an image.我想在图像下方放置文本。 I want to do this for 4 images that are placed in a row.我想对连续放置的 4 张图像执行此操作。

I've tried implementing a solution, here's the code I've written: http://pastebin.com/3rgYXKFL我试过实现一个解决方案,这是我写的代码: http : //pastebin.com/3rgYXKFL

Here's what this code produces: http://i.imgur.com/hWwWMlL.png这是此代码产生的内容: http : //i.imgur.com/hWwWMlL.png

Even though this is a step in the right direction, I'm still not able to figure out exactly how to get the text below the image and place 4 images in a row (each having text below the image).即使这是朝着正确方向迈出的一步,我仍然无法确切地弄清楚如何在图像下方获取文本并将 4 个图像连续放置(每个图像下方都有文本)。 Any suggestions on how to solve this?有关如何解决此问题的任何建议?

Height and weight are better as CSS attributes,I would define them in a style="" .高度和重量作为 CSS 属性更好,我会在style=""定义它们。 So height="176" and weight="201" should become style="height: 176px; width:201px" .所以height="176"weight="201"应该变成style="height: 176px; width:201px"

Unless there's a specific reason for using inline styles, I'd also suggest you put all your styles in a CSS file.除非有使用内联样式的特定原因,否则我还建议您将所有样式放在一个 CSS 文件中。

You could make all your images <img src="url" class="icon"> and then in CSS:你可以让你的所有图像<img src="url" class="icon">然后在 CSS 中:

.icon {
  height: 176px;
  width: 201px;
}

This way the only part you're repeating is the class bit, rather than having to set the style every time.这样,您唯一要重复的部分就是类位,而不必每次都设置样式。 If you want to change something, it makes it a lot simpler to make the change in one spot rather than every time for all 4 images.如果您想更改某些内容,只需在一个位置进行更改,而不是每次对所有 4 个图像进行更改,这会变得更加简单。

Your question wasn't clear so this is the best answer I can give you at this moment.你的问题不清楚,所以这是我目前能给你的最好的答案。 Use this code and it might be what you want.使用此代码,它可能就是您想要的。

<img src="images/modules/Logomakr_1dOe2g.png" width="201px" height="198px"/>
<br />
<p style="font-size:36px; margin-left:2.5%; margin-top:0; margin-bottom:0;">Engineering</p>
<p style="font-size:24px; margin-top:0;">Text Goes Here</p>
<br />
<br />
<img src="images/modules/Logomakr_2VsRmD.png" width="201px" height="198px"/>
<p style="font-size:36px; margin-left:2.5%; margin-top:0; margin-bottom:0;">Buisness</p>
<p style="font-size:24px; margin-top:0;">Text Goes Here</p>

A suggestion would be to please learn your HTML coding before asking questions like this question because your code contained many severe errors and seemed like you are almost completely new to HTML and didn't know what you were doing.一个建议是在问这样的问题之前请先学习您的 HTML 编码,因为您的代码包含许多严重错误,而且您似乎对 HTML 几乎完全陌生并且不知道自己在做什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM