如何对齐 <div>到页面的中间(水平/宽度) [英] How to align a <div> to the middle (horizontally/width) of the page

查看:25
本文介绍了如何对齐 <div>到页面的中间(水平/宽度)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 div 标签,width 设置为 800 像素.当浏览器宽度大于800像素时,不应拉伸div,而应将其拉到页面中间.

解决方案

<div style="width:800px; margin:0 auto;">以内容为中心

I have a div tag with width set to 800 pixels. When the browser width is greater than 800 pixels, it shouldn't stretch the div, but it should bring it to the middle of the page.

解决方案

<body>
    <div style="width:800px; margin:0 auto;">
        centered content
    </div>
</body>

这篇关于如何对齐 &lt;div&gt;到页面的中间(水平/宽度)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆