Home > Backend Development > PHP Tutorial > 页面缩小,如何让内容全部居中?

页面缩小,如何让内容全部居中?

WBOY
Release: 2016-06-23 13:50:05
Original
1946 people have browsed it

网络上大部分的网站,都可以实现页面缩小之后内容居中。例如csdn也可以。
我希望我自己的站也可以啊 我自己开发的站,缩小之后,内容全部往左上角靠拢,好纠结,我要跟主流一样啊。请问CSS该如何设计?或者哪个CSs标签可以实现?或者什么方法可以实现跟csdn这个功能,请各位指点。~~


回复讨论(解决方案)

那是因为你的页面默认是居左的,与缩小没关。
参考下:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <meta http-equiv="content-type" content="text/html; charset=utf-8">  <title> New Document </title>  <style type="text/css">  body{	text-align:center;  }  .main{	width:1024px;	height:1024px;	background:#FF0000;	margin:0px auto 0px auto;  }  </style> </head> <body>  <div class="main"></div> </body></html>
Copy after login

定义margin:0 auto;可以实现左右居中

楼上正解 将div设置margin:0 auto;

Related labels:
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