Heim  >  Artikel  >  Backend-Entwicklung  >  页面缩小,如何让内容全部居中?

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

WBOY
WBOYOriginal
2016-06-23 13:50:051906Durchsuche

网络上大部分的网站,都可以实现页面缩小之后内容居中。例如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>

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

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

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn