gdtv
V2EX  ›  CSS

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

  •  
  •   gdtv · Aug 14, 2017 · 3245 views
    This topic created in 3197 days ago, the information mentioned may be changed or developed.

    请问如何让 .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 replies    2017-08-14 16:45:48 +08:00
    66beta
        1
    66beta  
       Aug 14, 2017   ❤️ 1
    .inner{margin:0 auto}
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2958 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 02:37 · PVG 10:37 · LAX 19:37 · JFK 22:37
    ♥ Do have faith in what you're doing.