V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Can I use?
http://caniuse.com/
Less
http://lesscss.org
Cool Libraries
Bootstrap from Twitter
Jetstrap
gdtv
V2EX  ›  CSS

请问如何让 DIV 里的指定元素水平居中而其他元素不变?

  •  
  •   gdtv · 2017-08-14 16:34:23 +08:00 · 2685 次点击
    这是一个创建于 2445 天前的主题,其中的信息可能已经有所发展或是发生改变。

    请问如何让 .inner 在 .outer 里面水平居中但.outer 里的其他元素(例如 P 和 IMG 的居中方式保持原来的不变)?

    <style>
    .inner{background-color:#fabb00;width:200px;height:200px;}
    </style>
    <div class="outer">
    	<div class="inner">
    	</div>
    	<p>
    		我是文字我是文字我是文字
    	</p>
    	<img src="https://v2ex.assets.uxengine.net/site/[email protected]?m=1346064962">
    </div>
    

    代码:
    http://runjs.cn/code/xfvfnu3t

    1 条回复    2017-08-14 16:45:48 +08:00
    66beta
        1
    66beta  
       2017-08-14 16:45:48 +08:00   ❤️ 1
    .inner{margin:0 auto}
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5203 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 03:48 · PVG 11:48 · LAX 20:48 · JFK 23:48
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.