page contents

html图片居中代码怎么写

html文字居中和html图片居中方法代码,通过在html中实现文字居中图片居中篇在html中实现文字图片内容居中有两种方法,使用CSS样式实现。

attachments-2021-08-GSXuxsh761171a2e29ca2.jpg

html文字居中和html图片居中方法代码,通过在html中实现文字居中图片居中篇在html中实现文字图片内容居中有两种方法,使用CSS样式实现。

一、对body加CSS居中样式

我们直接对body 设置CSS样式:text-align:center

1、完整HTML实例代码:

<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
  <head> 
    <meta charset="gb2312" /> 
    <title>W3Cschool居中实例</title> 
    <style> 
      body{text-align:center} 
    </style> 
  </head> 
  <body> 
    W3Cschool会被居中 
  </body> 
</html>

2、居中实例截图

attachments-2021-08-Y5DUpkau611719e007175.jpg

二、对文字外层对象加css居中样式

首先我们CSS命名选择器 为“.w3cschool”,对此选择器内加居中样式。我们实例演示2个DIV对象,一个放文字一个放图片。

1、对应CSS代码如下:

.w3cschool{text-align:center}

2、完整HTML+DIV+CSS代码如下:

<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
  <head> 
    <meta charset="gb2312" /> 
    <title>W3Cschool居中实例</title> 
    <style> 
      .w3cschool{text-align:center} 
    </style> 
  </head> 
  <body> 
    <div class="w3cschool">W3Cschool会被居中</div> 
    <div class="w3cschool">
      ![](//upload-images.jianshu.io/upload_images/2642238-eba477a8a75edf90.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
    </div> 
  </body> 
</html>

3、CSS实现对象内图片和文字居中效果截图

attachments-2021-08-d1DzvGlQ611719ce724e9.jpg

更多相关技术内容咨询欢迎前往并持续关注六星社区了解详情。

程序员编程交流QQ群:805358732


你可能感兴趣的文章

相关问题

0 条评论

请先 登录 后评论
轩辕小不懂
轩辕小不懂

2403 篇文章

作家榜 »

  1. 轩辕小不懂 2403 文章
  2. Pack 1131 文章
  3. 小柒 1038 文章
  4. Nen 576 文章
  5. 王昭君 209 文章
  6. 文双 71 文章
  7. 小威 64 文章
  8. Cara 36 文章