140 likes | 321 Views
CS110: Computer Science and the Internet. Page Layout with CSS. The Flow. Block elements vertically Float Should give them a width Clear. Your mission, should you choose to accept it…. First sketch the layout. header. d iv id=“intro”. nav. d iv id=“read”. d iv class=“week”.
E N D
CS110: Computer Science and the Internet Page Layout with CSS
The Flow • Block elements vertically • Float • Should give them a width • Clear
First sketch the layout header div id=“intro” nav div id=“read” div class=“week” div class=“week” footer
Use Firebug to experiment with CSS Load the following page into Firefox and turn on Firebug: http://cs.wellesley.edu/~cs110/ellen/amLit/initPage.html
Starting from the top… HTML: <header> <imgsrc="images/banner.jpg" alt="banner"> <h1>American Poetry and Prose</h1> </header> CSS: header{ border-bottom: 4px double maroon; border-top: 4px double maroon; background-color: tan; padding: 10px; } We can use the new <header> tag in HTML5!
Use Firebug to “add” more CSS* * but not to the original source View the HTML code and initial CSS for the <nav> element and “intro” div How can we move the <nav> element to the far right? How can we get the intro text to wrap around the image? Use Firebug to add properties to the CSS for the <nav> tag and intro div Links have three states: (1) initial unvisited link (2) visited link (3) “hovered” link We can create a different style for each state with the selectors (1) a:link (2) a:visited (3) a:hover
Now let’s tackle the “week” div View the HTML code for the first “week” div and the “photo” div nested inside: <div class="week"> <div class="photo"> <imgsrc="images/poe.jpg" alt="Edgar Allen Poe" width="80"> <br>E. A. Poe </div> . . . </div> Add CSS code to the .photo class to create the new look
Layout • Frozen • Liquid • Jello
Back to the big picture… Q: Hmmm… How do we get those dark regions on the side, and the “wheat” background only in the middle? A: Create a “fixed layout” by setting the width of the “allcontent” div and center this div by setting the left and right margins to auto Suppose we’d like a two-column layout? Add CSS code to the “main” div to create this two-column layout … or suppose we want the width of the web page to change as we change the window size (a “liquid layout”)?
two-column fixedlayout <body> <div id=“allcontent”> <header> . . . </header> <nav> . . . </nav> <div id=“main”> <div id=“intro”> . . . </div> <div id=“read”> . . . </div> <div class=“week”> . . . </div> <div class=“week”> . . . </div> </div> <footer> . . . </footer> </div> </body> nav { width: 150px; float: right; . . . } #allcontent{ width: 800px; margin: 0 auto; . . . } #main { width: 600px; . . . } Key CSS:
Create a two-column liquid layout Load the following page into Firefox and turn on Firebug: http://cs.wellesley.edu/~cs110/ellen/amLit/fixedPage.html How does the page change as you shrink the window size? Using Firebug, edit the CSS rules to create a two-column liquid layoutthat spans the width of the window and has columns that change size as you shrink the window size Hint: the value of the width property can be specified as a percentage, e.g. width: 60%; Why use fixed vs. liquid layouts?
The display property: block vs. inline? Block elements can be displayed inline, and vice versa, using the display property: p { display: inline; } img { display: block; } Use this idea to create a horizontal navigation bar Hint: the CSS contains empty rules for p and h3 tags inside the nav element, which may come in handy
Server Side Includes (SSI) Suppose we have the same code on lots of web pages: <html> <head> . . . </head> <body> <nav> . . . lots of hyperlinks . . . </nav> . . . </body> </html> <html> <head> . . . </head> <body> <nav> . . . lots of hyperlinks . . . </nav> . . . </body> </html> <html> <head> . . . </head> <body> <nav> . . . lots of hyperlinks . . . </nav> . . . </body> </html> . . . home.htmlmission.htmlmembers.html (1) Place code in a new file (2) include the new file in the HTML code: <body> <!--#include nav.part --> . . . (3) change filename extensions to .shtml <nav> . . . lots of hyperlinks . . . </nav> nav.part