2017-08-10 31 views
-1

正如我的標題所述,我有一個網站,我試圖將其劃分爲三欄。左邊的第一列將包含< nav>欄,最大的列將是包含段落,圖像等的中心內容區域...如何使<aside>作爲包含內容的列功能

然後,對於最右邊一列,我需要它是一個<預留「>與其他列高度相同的元素,其寬度與包含大部分內容的列的大約50%的nav38列相同。我的問題是我只是不知道如何配置邊距,填充等,以獲得這種類型的佈局。到目前爲止,我已經盡了最大的努力,但無法讓旁邊的元素顯示爲列。這是我的HTML:

<!DOCTYPE html> 
<html> 
    <head> 
    <title>Juniper Lane Swimming Club Inc., Bridgewater, NJ 08807</TITLE> 
    <meta charset="utf-8"> 
    <link href="style.css" rel="stylesheet" type="text/css"> 
    </head> 
<body> 

    <div id="wrapper"> 
     <header> 
      <img src="header.jpg" alt="header"> 

     </header> 


    <nav> 
     <ul> 

      <li><a href="http://www.jlsc.org">Home</a></li> 
      <li><a href="pool-info.htm">Pool Information</a></li> 
      <li><a href="news-events.htm">News &amp; Events</a></li> 
      <li><a href="swim-team.htm">Swim Team</a></li> 
      <li><a href="swim-lessons.htm">Swim Lessons</a></li> 
      <li><a href="jlsc-board.htm">JLSC Board </a></li> 
      <li><a href="photo-gallery.htm">Photo Galleries</a></li> 
      <li><a href="links-htm.htm">Useful Information</a></li> 
      </ul> 
     </nav> 
      <main> 
     <img src="hp-1.jpg" id="hp1" alt="pool" width="241" height="172"><h2 style="color: blue;">Welcome to Juniper Lane Swim Club!</h1> 
      <p>Juniper Lane is the neighborhood club where family fun is #1!</p> 
      <p>Whether you're looking for a place to take the kids, swim a few laps <br> 
      to stay in shape or just relax on a lounge chair with a good book - Juniper Lane is the place for you.<br> 
      </p> 
      <p>&nbsp;</p> 
      <img src="hp-3.jpg" id="hp3" alt="bench" width="237" height="172"> 


       <p class="greebtext">About Us - </p> 
        <p>The Juniper Lane Swim Club is a member owned non-profit, private swimming club located in Bridgewater, NJ.</p> 
        <p>The club was established in 1955 but the facility has been renovated and well-maintained over the years</p> 
        <img src="hp-2.jpg" id="hp2" alt="poolslide" width="237" height="172"><br> 
        <p>We maintain a membership of 180 families strong. Although we are currently at our maximum, we maintain a waiting list of families who are interested in joining the club. We are typically able to accomodate a number of new families each year through normal attrition. If you are interested in a JLSC membership or information please send an email to 
        <!-- Start email --> 
        <script type="text/javascript" 
src="http://www.jlsc.org/code/java/email/email.js"></script> 
        <!-- End email -->.</p> 
       <p>We are located on Juniper Lane in Bridgewater Township, just 
off Country Club Rd about 1mi north of Garretson Rd.</p> 



</main> 
<footer> 
<small><i>Copyright &copy; 2017 Juniper Lane Swim Club</i></small> 
    <small></a></small> 
</footer> 
</div> 
</body> 
</html> 

And Here is the CSS: 
    Body { 
    margin:auto; 
    padding:0px; 
    background-color:#59b3d2; 
    background-repeat: repeat; 
    background-position: top center; 
    font-family: Verdana, Geneva, sans-serif; 
    font-size:13px; 
    padding-left: 5px; 
    text-align: center; 
    background-image: url("pool-water.jpg"); 




} 





.redbtext { 
    color: #a90000; 
    font-weight:bold; 
} 

.greebtext { 
    color: #39780a; 
    font-weight:bold; 
    font-size:14px; 
} 

.greebbullet { 
    color: #39780a; 
    font-size:13px; 

} 
.bluetext { 
    color: #013370; 
    font-weight:bold; 
    font-size:15px; 
} 

nav {float: left; 
width: 190px; 
padding: 10px; 
background-color: #ffff80; 
} 

nav a {text-decoration: none; 
font-size: 1.5em;} 

nav a:link {color:#blue;} 

nav a:hover {color: orange;} 

nav a:visited {color:#002266;} 

li {list-style-type: none;} 


main {margin-left: 210px; 
background-color:#ffffcc; 
height: 100%; 
font-size: 1.1em; 
color: grey; 

padding-right: 200px; 
} 

#wrapper {width: 967px; 
margin-left: auto; 
margin-right: auto; 
background-color: #ffff80; 
overflow: hidden; 


} 

footer {text-align: center; 
padding: 20px; 
} 








#hp1, #hp2, #hp3 {border: 10px solid white; 
float:right;} 
+1

歡迎來到SO! [參觀](https://stackoverflow.com/tour),瞭解如何提出最有可能爲您提供幫助的問題。在你的情況下,我們需要查看你的style.css文件,看看你到目前爲止已經做了什麼,以及你可以改變什麼來解決你的問題。我們只需要與定義列相關的CSS,而不是您網站的所有樣式。 – cjl750

回答

1

如果您想在3個高度相同,你可以逃脫supporting IE 10+,Flexbox,就可以實現這一點:https://codepen.io/pixleight/pen/RZgxYP/

#wrapper { 
 
    display: -webkit-box; 
 
    display: -ms-flexbox; 
 
    display: flex; 
 
    -webkit-box-align: stretch; 
 
    -ms-flex-align: stretch; 
 
    align-items: stretch; 
 
    -ms-flex-pack: distribute; 
 
    justify-content: space-around; 
 
    -ms-flex-wrap: wrap; 
 
    flex-wrap: wrap; 
 
} 
 

 
header, 
 
nav, 
 
aside, 
 
main, 
 
footer { 
 
    margin: 16px; 
 
    padding: 16px; 
 
    /* outline just for visibility purposes */ 
 
    outline: 1px solid #F0F; 
 
} 
 

 
header, 
 
footer { 
 
    -webkit-box-flex: 100%; 
 
    -ms-flex: 100%; 
 
    flex: 100%; 
 
} 
 

 
nav, 
 
aside { 
 
    -webkit-box-flex: 1; 
 
    -ms-flex: 1; 
 
    flex: 1; 
 
} 
 

 
main { 
 
    -webkit-box-flex: 2; 
 
    -ms-flex: 2; 
 
    flex: 2; 
 
}
<div id="wrapper"> 
 
    <header> 
 
    <h1>Header</h1> 
 
    </header> 
 
    <nav> 
 
    <ul> 
 
     <li><a href="http://www.jlsc.org">Home</a></li> 
 
     <li><a href="pool-info.htm">Pool Information</a></li> 
 
     <li><a href="news-events.htm">News &amp; Events</a></li> 
 
     <li><a href="swim-team.htm">Swim Team</a></li> 
 
     <li><a href="swim-lessons.htm">Swim Lessons</a></li> 
 
     <li><a href="jlsc-board.htm">JLSC Board </a></li> 
 
     <li><a href="photo-gallery.htm">Photo Galleries</a></li> 
 
     <li><a href="links-htm.htm">Useful Information</a></li> 
 
    </ul> 
 
    </nav> 
 
    <main> 
 
    <h2>Welcome to Juniper Lane Swim Club!</h1> 
 
     <p>Juniper Lane is the neighborhood club where family fun is #1!</p> 
 
     <p>Whether you're looking for a place to take the kids, swim a few laps <br> to stay in shape or just relax on a lounge chair with a good book - Juniper Lane is the place for you.</p> 
 
     <!-- truncated for brevity --> 
 
    </main> 
 
    <aside> 
 
    <h3>Aside</h3> 
 
    </aside> 
 
    <footer> 
 
    <small><i>Copyright &copy; 2017 Juniper Lane Swim Club</i></small> 
 
    </footer> 
 
</div>

1

@pixleight的答案是我會採取的方法,但如果您不想使用flexbox,則可以簡單使用:

display: inline-block; 
width: 33%; 
vertical-align: top; 
box-sizing: border-box; /* where the magic happens, takes the paddings into account for the width size */ 
float: none; /* to reset the floats on your code */ 

您可以檢查它在這裏工作:https://jsfiddle.net/1jnnyb4d/

您的代碼,我注意到的幾個注意事項: 1)你已經失去的「H1」的主要元素結束標記(應該是H2,我認爲)和腳註上丟失的「a」結束標記; 2)顏色:#藍色;不是一個有效的CSS指令(要麼你只使用「藍色」或十六進制值)。