为了账号安全,请及时绑定邮箱和手机立即绑定

怎样用CSS3把图片居中?

怎样用CSS3把图片居中?

Goraidh 2017-06-29 09:34:05
查看完整描述

5 回答

已采纳
?
阳光暖暖的时光慢慢的

TA贡献3条经验 获得超2个赞

<html>
<head>
    <title>div居中</title>
</head>
<body>
   <img src="1.jpg" style="width:100px;height:100px;position:absolute; top:0;bottom:0;left:0;right:0;margin:auto;">
</body>
</html>


查看完整回答
2 反对 回复 2017-06-29
?
qq_哪嬡芣侢秇着_0

TA贡献4条经验 获得超1个赞

直接把IMG转成块元素就行了,比如

img{

    display:block;

    width:300px;

    height:300px;

    margin:auto;

}

查看完整回答
1 反对 回复 2017-09-22
?
谢凌

TA贡献41条经验 获得超14个赞

margin:0 auto;

查看完整回答
1 反对 回复 2017-06-29
?
weibo_正在输入

TA贡献2条经验 获得超1个赞

昨天刚刚给朋友写的如何居中的代码,你可以看一下效果

<html>
<head>
	<title>div居中</title>
</head>
<body style="background:blue; width:100%; height:100%">


<div style="background:red; width:400px; height:200px;margin:auto; ">
方式一
1. 设置宽高 width:400px; height:400px;<br>
2. 设置外边距 margin:0 auto;
</div>


<div style="background:yellow;width:400px; height:200px; position:absolute; left:45%; top:45%">
方式二
1. 设置定位方式为绝对定位  position:absolute;
2. 设置该div距离父元素的左边距和上边距为 40%,40%  left:45%; top:45% ;
</div>
</body>
</html>


查看完整回答
1 反对 回复 2017-06-29
?
李晓健

TA贡献1036条经验 获得超461个赞

居中的方式有很多,主要看你页面的布局了。

查看完整回答
反对 回复 2017-06-29
  • Goraidh
    Goraidh
    我试了两种方法,都不能!刚刚接触不太懂
  • 李晓健
    李晓健
    你可以把你的代码帖出来,帮你看看是什么问题
  • 5 回答
  • 0 关注
  • 5697 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信