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

2017-08-14 16:34:23 +08:00
 gdtv

请问如何让 .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/logo@2x.png?m=1346064962">
</div>

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

2689 次点击
所在节点    CSS
1 条回复
66beta
2017-08-14 16:45:48 +08:00
.inner{margin:0 auto}

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/382842

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX