Home>Article>Web Front-end> How to center css images

How to center css images

php中世界最好的语言
php中世界最好的语言 Original
2018-05-15 14:43:37 8007browse

We often encounter this situation in projects. There are many ways to make thepictureappear 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 DIVobjectbox 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

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"使用方法: 

align="center"居中图片DIV+CSS实例代码: 图片横向居中

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:

    图片横向居中  
  

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!

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