2017-06-23 60 views
-2

我的模板看起來很像我的桌面上的方式,但是當我在任一視圖中將其加載到手機上時,左側的導航不會調整大小以適合其餘部分頁面沒有。您可以在http://www.mytournamentonline.com/work/template3.php查看佈局。CSS佈局不適用於移動設備

我將不勝感激任何幫助。一些CSS項目可能是多餘的,但我雖然山雀工作,然後意識到它沒有正確顯示在我的手機上,所以我嘗試了各種更新,以使其工作。

<style> 
    body { 
    background-color: #666; 
    font-family: Geneva, Arial, Helvetica, sans-serif; 
    font-size: 12px; 
    color: #000000; 
} 

#container { 
    width: 80%; 
    margin: 0 auto; 
    background-color:#12295d; 
    border:5px solid #a6c250; 
} 

#header img { 
    width:100%; 
    margin:auto; 
    height: auto; 
} 

#content { 
    float:right; 
    width:81%; 
    background-color:#FFFFFF; 
    border-left:5px solid #a6c250; 
    min-height:350px; 
} 

#sidebar { 
    float:left; 
    width:18%; 
} 

#primary { 
    float: left; 
    width: 98%; 
    background-color:#245192; 
    border-top: 0; 
} 

/* nav */ 
nav { 
    background-color:#245192; 
    width:100%; 
    float:left; 
    height:inherit; 
} 

/* navigation button styles */ 
a.btn { 
    display: block; 
    width: 100%; 
    padding: 10px 0px 10px 10px; 
    font-family: Arial; 
    font-size: 16px; 
    text-decoration: none; 
    color: #ffffff; 
    text-shadow: -1px -1px 2px #618926; 
    background: -moz-linear-gradient(#98ba40, #a6c250 35%, #618926); 
    background: -webkit-gradient(linear,left top,left bottom,color-stop(0, #98ba40),color-stop(.35, #a6c250),color-stop(1, #618926)); 
    border: 1px solid #618926; 
    border-radius: 3px; 
    -moz-border-radius: 3px; 
    -webkit-border-radius: 3px; 
} 

a.btn:hover { 
    text-shadow: -1px -1px 2px #465f97; 
    background: -moz-linear-gradient(#245192, #1e3b73 75%, #12295d); 
    background: -webkit-gradient(linear,left top,left bottom,color-stop(0, #245192),color-stop(.75, #1e3b73),color-stop(1, #12295d)); 
    border: 1px solid #0f2557; 
} 

.currentpage { 
    display: block; 
    width: 100%; 
    padding: 10px 0px 10px 10px; 
    font-family: Arial; 
    font-size: 1.5em; 
    text-decoration: none; 
    color: #ffffff; 
    text-shadow: -1px -1px 2px #465f97; 
    background: -moz-linear-gradient(#245192, #1e3b73 75%, #12295d); 
    background: -webkit-gradient(linear,left top,left bottom,color-stop(0, #245192),color-stop(.75, #1e3b73),color-stop(1, #12295d)); 
    border: 1px solid #0f2557; 
} 
#footer { 
    clear:both; 
    clear: both; 
    text-align:center; 
    width:100$; 
    font-family: Geneva, Arial, Helvetica, sans-serif; 
    font-size: 10px; 
    font-weight: bold; 
    color: #DCF414; 
    border-top: 5px solid #a6c250; 
    background-color: #12295d; 
} 
</style> 

<body> 
<div id="container"> 
<div id="header"> 
    <img src="images/New_header_700_150.jpg" alt="My Tournamentonline Header" /> 
</div> 

<div id="content"> 
    <div style="padding:10px;"> 
     <p>Main content</p> 
    </div> 
</div> 

<div id="sidebar"> 
    <div id="primary"> 
      <nav> 
       <?php 
        function curPageName() { 
         return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1); 
        } 
       ?> 
       <a href="index.php" class=<?php if (curPageName() == 'index.php') { ?> "currentpage" <?php } ELSE { ?> "btn" <?php } ?>>Home</a> 
       <a href="tournaments.php" class=<?php if (curPageName() == 'tournaments.php') { ?> "currentpage" <?php } ELSE { ?> "btn" <?php } ?>>Active Tournaments</a> 
       <a href="club_reg.php" class=<?php if (curPageName() == 'club_reg.php') { ?> "currentpage" <?php } ELSE { ?> "btn" <?php } ?>>Club Registration</a> 
       <a href="login.php" class=<?php if (curPageName() == 'login.php') { ?> "currentpage" <?php } ELSE { ?> "btn" <?php } ?>>Member Login</a> 
       <a href="contactUs.php" class=<?php if (curPageName() == 'contactUs.php') { ?> "currentpage" <?php } ELSE { ?> "btn" <?php } ?>>Contact Us</a>  
      </nav> 
      </div> 
</div> 

<div id="footer"> 
    <p>Footer</p> 
</div> 
</div> 
</body> 
+3

歡迎來到StackOverflow!解決方案完全取決於您希望**邊欄對手機調整大小的方式。你想把它粘在左邊嗎?低於?你可以請更具體一點嗎?由於沒有足夠的寬度可以放在左側,因此您的側邊欄目前正在放在主要內容的下方。這是由於你爲兩列使用基於百分比的'widths',而基於像素的'padding'。您可能希望查看像[** BootStrap **](http://getbootstrap.com)這樣的框架,以自動將相關列堆棧放置在某個斷點:) –

+0

添加一個父類以將滑塊和主要內容以及在其上寫入樣式..'

slider content here
main content here ..
'和css像'.main {0}顯示:flex; }' – bhv

+0

還有一件事您必須使用媒體查詢進行響應式設計 – bhv

回答

0

使用媒體查詢來控制移動視圖。從#container集合width:100%開始。並在您的Html我會建議移動sidebar div以上的content div然後交換浮游物。

此外,我會建議設置width:100%在所有#container > div

查找到引導link here

0

您可以使用媒體查詢您的要求。您還可以更改一些佈局以填充移動設備。

嘗試下面的代碼。

<!DOCTYPE html> 
 
<html> 
 
<head> 
 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
 
    <style> 
 
    body { 
 
    background-color: #666; 
 
    font-family: Geneva, Arial, Helvetica, sans-serif; 
 
    font-size: 12px; 
 
    color: #000000; 
 
} 
 

 
#container { 
 
    width: 80%; 
 
    margin: 0 auto; 
 
    background-color:#12295d; 
 
    border:5px solid #a6c250; 
 
} 
 

 
#header img { 
 
    width:100%; 
 
    margin:auto; 
 
    height: auto; 
 
} 
 

 
#content { 
 
    float:right; 
 
    width:81%; 
 
    background-color:#FFFFFF; 
 
    border-left:5px solid #a6c250; 
 
    min-height:350px; 
 
} 
 

 
#sidebar { 
 
    float:left; 
 
    width:18%; 
 
} 
 

 
#primary { 
 
    float: left; 
 
    width: 98%; 
 
    background-color:#245192; 
 
    border-top: 0; 
 
} 
 

 
/* nav */ 
 
nav { 
 
    background-color:#245192; 
 
    width:100%; 
 
    float:left; 
 
    height:inherit; 
 
} 
 

 
/* navigation button styles */ 
 
a.btn { 
 
    display: block; 
 
    width: 100%; 
 
    padding: 10px 0px 10px 10px; 
 
    font-family: Arial; 
 
    font-size: 16px; 
 
    text-decoration: none; 
 
    color: #ffffff; 
 
    text-shadow: -1px -1px 2px #618926; 
 
    background: -moz-linear-gradient(#98ba40, #a6c250 35%, #618926); 
 
    background: -webkit-gradient(linear,left top,left bottom,color-stop(0, #98ba40),color-stop(.35, #a6c250),color-stop(1, #618926)); 
 
    border: 1px solid #618926; 
 
    border-radius: 3px; 
 
    -moz-border-radius: 3px; 
 
    -webkit-border-radius: 3px; 
 
} 
 

 
a.btn:hover { 
 
    text-shadow: -1px -1px 2px #465f97; 
 
    background: -moz-linear-gradient(#245192, #1e3b73 75%, #12295d); 
 
    background: -webkit-gradient(linear,left top,left bottom,color-stop(0, #245192),color-stop(.75, #1e3b73),color-stop(1, #12295d)); 
 
    border: 1px solid #0f2557; 
 
} 
 

 
.currentpage { 
 
    display: block; 
 
    width: 100%; 
 
    padding: 10px 0px 10px 10px; 
 
    font-family: Arial; 
 
    font-size: 1.5em; 
 
    text-decoration: none; 
 
    color: #ffffff; 
 
    text-shadow: -1px -1px 2px #465f97; 
 
    background: -moz-linear-gradient(#245192, #1e3b73 75%, #12295d); 
 
    background: -webkit-gradient(linear,left top,left bottom,color-stop(0, #245192),color-stop(.75, #1e3b73),color-stop(1, #12295d)); 
 
    border: 1px solid #0f2557; 
 
} 
 
#footer { 
 
    clear:both; 
 
    clear: both; 
 
    text-align:center; 
 
    width:100$; 
 
    font-family: Geneva, Arial, Helvetica, sans-serif; 
 
    font-size: 10px; 
 
    font-weight: bold; 
 
    color: #DCF414; 
 
    border-top: 5px solid #a6c250; 
 
    background-color: #12295d; 
 
} 
 
\t 
 
\t @media screen and (max-width:680px) { 
 
\t \t #sidebar { 
 
    float:none; 
 
    width:100%;display: block; 
 
\t } 
 
\t \t #content { 
 
    float:none; 
 
    width:100%; 
 
\t } 
 

 
\t } 
 
</style> 
 
</head> 
 
<body> 
 
<div id="container"> 
 
<div id="header"> 
 
    <img src="http://www.mytournamentonline.com/work/images/New_header_700_150.jpg" alt="My Tournamentonline Header" /> 
 
</div> 
 

 
<div id="content"> 
 
    <div style="padding:10px;"> 
 
     <p>Main content</p> 
 
    </div> 
 
</div> 
 

 
<div id="sidebar"> 
 
    <div id="primary"> 
 
      <nav> 
 
       <?php 
 
        function curPageName() { 
 
         return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1); 
 
        } 
 
       ?> 
 
       <a href="index.php" class=<?php if (curPageName() == 'index.php') { ?> "currentpage" <?php } ELSE { ?> "btn" <?php } ?>>Home</a> 
 
       <a href="tournaments.php" class=<?php if (curPageName() == 'tournaments.php') { ?> "currentpage" <?php } ELSE { ?> "btn" <?php } ?>>Active Tournaments</a> 
 
       <a href="club_reg.php" class=<?php if (curPageName() == 'club_reg.php') { ?> "currentpage" <?php } ELSE { ?> "btn" <?php } ?>>Club Registration</a> 
 
       <a href="login.php" class=<?php if (curPageName() == 'login.php') { ?> "currentpage" <?php } ELSE { ?> "btn" <?php } ?>>Member Login</a> 
 
       <a href="contactUs.php" class=<?php if (curPageName() == 'contactUs.php') { ?> "currentpage" <?php } ELSE { ?> "btn" <?php } ?>>Contact Us</a>  
 
      </nav> 
 
      </div> 
 
</div> 
 

 
<div id="footer"> 
 
    <p>Footer</p> 
 
</div> 
 
</div> 
 
</body></html>

0

您可以使用媒體查詢像下面

@media only screen and (max-width: 768px) { 
/* For mobile phones: */ 
body { 
width: 100%; 
} 
/* customize the tag, class, id's according to your requirement */ 
.class{ 
} 
<tag>{ 
} 
#id's{ 
} 

如果寬度小於768px,那麼你可以使用以上媒體查詢。

相關問題