如何让img在div中直接居右?不是用margin-left:auto吗?

Henery_002 2016-03-12 03:47:11
如何让img在div中直接居右?不是用margin-left:auto吗?在线等
...全文
1073 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
u011151921 2016-04-15
  • 打赏
  • 举报
回复
<div style='background-color:red'> <img src='http://avatar.csdn.net/0/A/8/1_henery_002.jpg' > </div> margin:auto;和text-align:center; 都能实现居中的效果,但是在不同情况用的。。 你上面说的“margin-left:auto”这个应该是margin-left:auto;和margin-right:auto;都设置为auto,相当于margin:0 auto;这样的。 像我上面写的两种。。text-align:center;居中要求子级是要display:inline-block或inline才行的。 而margin:auto;居中是本身的居中,但类型必须为display:block; 根据情况正常margin:auto;用在框架居中。。而text-align:center;用在内容居中。
def123321123 2016-04-15
  • 打赏
  • 举报
回复
<div></div> *{margin:0; padding:0;} div{ width:600px; height:600px; background:url('../img/img1.jpg') no-repeat green right top; //图片定位在右上角。 }
usecf 2016-03-24
  • 打赏
  • 举报
回复
div 设置text-align:right; 或者直接写align:center试试
反重力落叶 2016-03-21
  • 打赏
  • 举报
回复
你给div设置text-align:right;这样会达到你说的效果
zhituji 2016-03-15
  • 打赏
  • 举报
回复
给包含图片的div设置{ text-align:center;}就是div内容全部居中显示
Zangxjun 2016-03-12
  • 打赏
  • 举报
回复
float:right
xuzuning 2016-03-12
  • 打赏
  • 举报
回复
<div style='background-color:red'>
<img src='http://avatar.csdn.net/0/A/8/1_henery_002.jpg' style='margin-left:80%'>
</div>

61,112

社区成员

发帖
与我相关
我的任务
社区描述
层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言。
社区管理员
  • HTML(CSS)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧