How to center css images

php中世界最好的语言
Release: 2018-05-15 14:43:37
Original
8095 people have browsed it

We often encounter this situation in projects. There are many ways to make the picture appear in the center, but the most recommended one is to use CSS to operate DIV, so I will introduce it to you below. Two methods, use CSS operations to center the image.

First, let the DIV object box in the picture be horizontally centered, which is the same as the CSS of making the text font horizontally centered in the DIV box.

The CSS style word to center the object content is:

text-align
:center
Copy after login

text-align is the position of the content in the objectAttribute

center value is centered

1. The traditional HTML method to center the image horizontally and horizontally is to directly add "align="center"" to the label object to display the image in the object horizontally and horizontally centered.

Add "align="center"" directly into the label object to display the image in the object horizontally and centered.

align="center"使用方法:
<p align="center"></p>
align="center"居中图片DIV+CSS实例代码:
<!DOCTYPE > 
<html xmlns="//m.sbmmt.com"> 
<head> 
<meta charset="utf-8" /> 
<title>图片横向居中</title> 
</head> 
<body> 
<p align="center"><img src="//m.sbmmt.com" /></p> 
</body> 
</html>
Copy after login

CSS to center the DIV object in the image horizontally

2. Use CSS styles to center the image in the DIV (horizontally centered)

HTML+CSS complete code As follows:

<!DOCTYPE > 
<html xmlns="//m.sbmmt.com"> 
<head> 
<meta charset="utf-8" /> 
<title>图片横向居中</title> 
<style> 
.pcss5{text-align:center} 
</style> 
</head> 
<body> 
<p class="pcss5"><img src="//m.sbmmt.com" /></p> 
</body> 
</html>
Copy after login

We can use the above two methods to achieve the centering of text, images, etc. It is generally recommended to use CSS, but often on web pages, we only need to modify the corresponding selection in the CSS file. You can modify the content center, left, or right using the container style.

Recommended reading:

Use css to implement circular progress bar

css ripple animation

What should I do if the web page is iframed?

The above is the detailed content of How to center css images. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template