Home>Article>Web Front-end> How to add text to pictures in html

How to add text to pictures in html

WBOY
WBOY Original
2021-11-09 16:15:08 66887browse

Adding method: 1. Use the position attribute to add a relative positioning style to the container element div containing pictures and text; 2. Use the position attribute to add an absolute positioning style to the text element; 3. Use the left and top attributes to set the text The position of the element on the picture, just position the text on the picture.

How to add text to pictures in html

The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.

How to add text to html pictures:

1. Create a new html file named test.html for Explain how to add text to images using html css.

How to add text to pictures in html

2. In the test.html file, use the div tag to create a module, and within the div, use the img tag to create an image.

How to add text to pictures in html

3. In the test.html file, within the div tag, use the p tag to create a piece of text. Next, the text will be added to the image through css.

How to add text to pictures in html

4. In the test.html file, in the css tag, use "*" to initialize the inner and outer margins of all elements on the page to 0 to avoid affecting the following css style definition. .

How to add text to pictures in html

5. In the css tag, set the style of the div element and define its position attribute as relative positioning (relative).

How to add text to pictures in html

6. In the css tag, set the style of the p element within the div, and define its position attribute position as absolute positioning (absolute). This absolute positioning is relative to It depends on the position of the image. Let the text be 10px from the left edge of the image and 10px from the top edge of the image, and set the text color to red.

How to add text to pictures in html

7. Open the test.html file in the browser to check the effect.

How to add text to pictures in html

For more programming related knowledge, please visit:Programming Video! !

The above is the detailed content of How to add text to pictures in html. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn