2014-09-12 58 views
-6

我在互聯網上嘗試了幾個不同的來源。我沒有使用bootstrap;我喜歡從頭開始做我的網站。它幫助我編程。自動調整網頁到屏幕大小(HTML)

我無法讓我的網頁自動適應屏幕尺寸。例如,如果您使瀏覽器更小,頁面摺疊很好,整潔。

我想這些代碼從這裏:http://www.gonzoblog.nl/2013/01/16/11-useful-css-code-snippets-for-responsive-web-design/

但我的網頁崩潰像例子。

<!-- 
<meta name="viewport" content="width=device-width, initial-scale=1.0"> 
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
<meta name="HandheldFriendly" content="true"> 

    --> 




<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<link rel="stylesheet" type="text/css" href="sunpacking.css"> 
<title>Sun Packing WebSite</title> 
<link href="../../Documents/Sun Packing/sun.css" rel="stylesheet" type="text/css" /> 
<style type="text/css"> 
.div1 { 
    margin: 20px; 
} 
</style> 
</head> 
<body> 


<div style="width:800px; margin:0 auto;"> 


<div id="container"> 
data 
</div> 



/*Sun Packing CSS */ 

    /* 
body{ 

padding:0px; 
margin:0px; 
width:100%; 
height:100%; 

} 

*/ 




#container { 
    float: none; 
    border-style: dashed; 
    border-color: red; 
    width: 100%; /* 95px*/ 

    height: 100%; /*1400px*/ 
    color: red; 
} 
+7

編碼是不是從網上覆制粘貼隨機的例子。這是關於*理解*這些例子如何工作,*從他們那裏學習*,以便您可以*將這些概念*應用到您自己的代碼中。 – 2014-09-12 22:11:54

+0

我明白這一點,但它不是像我無法在一秒鐘內想出來的,我現在一直在嘗試。 – user3416090 2014-09-12 22:14:12

+2

你真的應該標題你的問題有用,而不是多麼絕望你的幫助。 – 2014-09-12 22:19:02

回答

0

你可以從關閉你的HTML容器開始,給出一個很好的例子。

如果你設置一個明確的寬度,width: 800px;,這就是它將被渲染的寬度。

嘗試設置容器的max-width對於這一點,設置寬度擴大到

,我通常做的方式:

.container { 
    max-width: 800px; 
    width: 100%; 
} 
相關問題