css布局学习笔记之max-width_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 12:07:54
Original
1829 people have browsed it

设置块级元素的 width 可以阻止它从左到右撑满容器。然后你就可以设置左右外边距为 auto 来使其水平居中。元素会占据你所指定的宽度,然后剩余的宽度会一分为二成为左右外边距。

div{  width: 600px;  margin: 0 auto; }
Copy after login

唯一的问题是,当浏览器窗口比元素的宽度还要窄时,浏览器会显示一个水平滚动条来容纳页面。

在这种情况下使用 max-width 替代 width 可以使浏览器更好地处理小窗口的情况。

div {  max-width: 600px;  margin: 0 auto; }
Copy after login

 

这个知识点很简单,但是我觉得它很重要,于是也记录下来吧~

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!