Solved

CSS 3 Column Layout - "Sidebars that HIDE with more/less content"

Posted on 2008-10-02
4
902 Views
Last Modified: 2012-05-05
I'm making a switch from tables to CSS, and am having issues with a certain effect.

I have a 3 column liquid layout, and I'm trying to get the left and right "sidebars" (the red & photo blocks) to HIDE when the content in the middle is more or less lengthy.  Ideally, the photo bar would show less or more photos in accordance with the middle content.

http://www.mylifeart.org/test.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title>Untitled Document</title>

<style type="text/css"> 

<!-- 

body  {

	margin: 0; /* it's good practice to zero the margin and padding of the body element to account for differing browser defaults */

	padding: 0;

	text-align: center; /* this centers the container in IE 5* browsers. The text is then set to the left aligned default in the #container selector */

	color: #000000;

	background-color: #F5E8AA;

	font-family: Verdana, Arial, Helvetica, sans-serif;

	font-size: 100%;

}
 

/* Tips for Elastic layouts 

1. Since the elastic layouts overall sizing is based on the user's default fonts size, they are more unpredictable. Used correctly, they are also more accessible for those that need larger fonts size since the line length remains proportionate.

2. Sizing of divs in this layout are based on the 100% font size in the body element. If you decrease the text size overall by using a font-size: 80% on the body element or the #container, remember that the entire layout will downsize proportionately. You may want to increase the widths of the various divs to compensate for this.

3. If font sizing is changed in differing amounts on each div instead of on the overall design (ie: #sidebar1 is given a 70% font size and #mainContent is given an 85% font size), this will proportionately change each of the divs overall size. You may want to adjust based on your final font sizing.

*/

.thrColElsHdr #container {

	width: 931px; /* the auto margins (in conjunction with a width) center the page */

	border: 1px solid #000000;

	text-align: left; /* this overrides the text-align: center on the body element. */

	vertical-align: top;

	margin-top: 0;

	margin-right: auto;

	margin-bottom: 0;

	margin-left: auto;

	background-color: #FFFCD9;

} 

.thrColElsHdr #header {

	background: #DDDDDD;  /* this padding matches the left alignment of the elements in the divs that appear beneath it. If an image is used in the #header instead of text, you may want to remove the padding. */

	padding-top: 0;

	padding-right: 0px;

	padding-bottom: 0;

	padding-left: 0px;

} 

.thrColElsHdr #header h1 {

	margin: 0; /* using padding instead of margin will allow you to keep the element away from the edges of the div */

	padding-top: 0px;

	padding-right: 0;

	padding-bottom: 0px;

	padding-left: 0;

}
 

/* Tips for sidebar1:

1. Be aware that if you set a font-size value on this div, the overall width of the div will be adjusted accordingly.

2. Since we are working in ems, it's best not to use padding on the sidebar itself. It will be added to the width for standards compliant browsers creating an unknown actual width. 

3. Space between the side of the div and the elements within it can be created by placing a left and right margin on those elements as seen in the ".thrColElsHdr #sidebar1 p" rule.

*/

.thrColElsHdr #sidebar1 {

	float: left;

	width: 50px; /* top and bottom padding create visual space within this div */

	padding-top: 0px;

	padding-right: 0;

	padding-bottom: 0px;

	padding-left: 0;

	background-color: #990000;

	height: 90em;

}

.thrColElsHdr #sidebar2 {

	float: right;

	width: 180px; /* since this element is floated, a width must be given */

	background: #EBEBEB; /* top and bottom padding create visual space within this div */

	padding-top: 0px;

	padding-right: 0;

	padding-bottom: 0px;

	padding-left: 0;

	height: 100%;

}

.thrColElsHdr #sidebar1 h3, .thrColElsHdr #sidebar1 p, .thrColElsHdr #sidebar2 p, .thrColElsHdr #sidebar2 h3 {

	margin-left: 10px; /* the left and right margin should be given to every element that will be placed in the side columns */

	margin-right: 10px;

}
 

/* Tips for mainContent:

1. If you give this #mainContent div a font-size value different than the #sidebar1 div, the margins of the #mainContent div will be based on its font-size and the width of the #sidebar1 div will be based on its font-size. You may wish to adjust the values of these divs.

2. The space between the mainContent and sidebar1 is created with the left margin on the mainContent div.  No matter how much content the sidebar1 div contains, the column space will remain. You can remove this left margin if you want the #mainContent div's text to fill the #sidebar1 space when the content in #sidebar1 ends.

3. To avoid float drop, you may need to test to determine the approximate maximum image/element size since this layout is based on the user's font sizing combined with the values you set. However, if the user has their browser font size set lower than normal, less space will be available in the #mainContent div than you may see on testing.

4. In the Internet Explorer Conditional Comment below, the zoom property is used to give the mainContent "hasLayout." This avoids several IE-specific bugs that may occur.

*/

.thrColElsHdr #mainContent {

	margin-top: 0;

	margin-right: 9em;

	margin-bottom: 0;

	margin-left: 5em;

} 

.thrColElsHdr #footer {

	padding: 0 10px;

	background-color: #000000;

} 

.thrColElsHdr #footer p {

	margin: 0; /* zeroing the margins of the first element in the footer will avoid the possibility of margin collapse - a space between divs */

	padding: 10px 0; /* padding on this element will create space, just as the the margin would have, without the margin collapse issue */

}
 

/* Miscellaneous classes for reuse */

.fltrt { /* this class can be used to float an element right in your page. The floated element must precede the element it should be next to on the page. */

	float: right;

	margin-left: 8px;

}

.fltlft { /* this class can be used to float an element left in your page */

	float: left;

	margin-right: 8px;

}

.clearfloat { /* this class should be placed on a div or break element and should be the final element before the close of a container that should fully contain a float */

	clear:both;

    height:0;

    font-size: 1px;

    line-height: 0px;

}

.style1 {

	font-size: 12px;

	color: #FFFFFF;

}

body,td,th {

	font-family: Verdana;

	font-size: 12px;

}

a:link {

	color: #666666;

	text-decoration: none;

}

a:visited {

	text-decoration: none;

	color: #666666;

}

a:hover {

	text-decoration: none;

	color: #990000;

}

a:active {

	text-decoration: none;

}

.style2 {	font-family: verdana;

	color: #CCCCCC;

	font-size: 10px;

}

.style3 {color: #000000}

--> 

</style>

<!--[if IE]>

<style type="text/css"> 

/* place css fixes for all versions of IE in this conditional comment */

.thrColElsHdr #sidebar1, .thrColElsHdr #sidebar2 { padding-top: 30px; }

.thrColElsHdr #mainContent { zoom: 1; padding-top: 15px; }

/* the above proprietary zoom property gives IE the hasLayout it needs to avoid several bugs */

</style>

<![endif]-->

<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>

</head>
 

<body class="thrColElsHdr">
 

<div id="container">

  <div id="header">

    <div id="sidebar1">

      <h3>&nbsp;</h3>

      <!-- end #sidebar1 -->

    </div>

    <div id="sidebar2">

    <!-- end #sidebar2 -->

    <a href="headshots_corrina2.html"><img src="images/headshots/corrina2_mini.jpg" width="90" height="90" border="0" /></a><img src="0blocks2/block_white.jpg" width="90" height="90" /><img src="0blocks/blackcolorblock.jpg" width="90" height="90" /><a href="comps_deborah4.html"><img src="images/compcardslifestyle/Deborah4_mini.jpg" width="90" height="90" border="0" /></a><a href="news.html"><img src="images/sidebar_news.jpg" width="90" height="90" border="0" /></a><a href="reels_innertwinkle.html"><img src="images/reel_innertwinkle.jpg" width="90" height="90" border="0" /></a><img src="0blocks2/grey_block.jpg" width="90" height="90" /><a href="thankyou1.html"><img src="images/thankyou1_small.jpg" width="90" height="90" border="0" /></a><a href="headshots_leah2.html"><img src="images/headshots/Leah2_mini.jpg" width="90" height="90" border="0" /></a><img src="0blocks2/dark_grey_block.jpg" width="90" height="90" /><a href="headshots_veronica.html"><img src="images/headshots/veronica_mini.jpg" width="90" height="90" border="0" /></a><a href="reels_suburbanhousewife.html"><img src="images/reels_downwardspiralsuburban.jpg" width="90" height="90" border="0" /></a><img src="0blocks2/block_white.jpg" width="90" height="90" /><a href="headshots_leah.html"><img src="images/headshots/leah_mini.jpg" width="90" height="90" border="0" /></a><a href="comps_deborah5.html"><img src="images/compcardslifestyle/Deborah5_mini.jpg" width="90" height="90" border="0" /></a><a href="classes.html"><img src="images/sidebar_workshops.jpg" width="90" height="90" border="0" /></a><a href="reels_cathy1.html"><img src="images/headshots/cathy2_mini.jpg" width="90" height="90" border="0" /></a><img src="0blocks/blackcolorblock.jpg" width="90" height="90" /><img src="0blocks2/grey_block.jpg" width="90" height="90" /><a href="headshots_fallinganvil.html"><img src="images/headshots/FallingAnvil_mini.jpg" width="90" height="90" border="0" /></a><a href="headshots_israel.html"><img src="images/headshots/israel_headshot_mini.jpg" width="90" height="90" border="0" /></a><img src="0blocks2/dark_grey_block.jpg" width="90" height="90" /><img src="0blocks2/block_white.jpg" width="90" height="90" /><a href="comps_deborah.html"><img src="images/compcardslifestyle/Deborah_mini.jpg" width="90" height="90" border="0" /></a><a href="comps_deborah2.html"><img src="images/compcardslifestyle/Deborah2_mini.jpg" width="90" height="90" border="0" /></a><img src="0blocks2/dark_grey_block.jpg" width="90" height="90" /><img src="0blocks2/block_white.jpg" width="90" height="90" /><img src="0blocks2/grey_block.jpg" width="90" height="90" /><a href="headshots_katherine2.html"><img src="images/headshots/katherine2_mini.jpg" width="90" height="90" border="0" /></a><img src="0blocks/blackcolorblock.jpg" width="90" height="90" /><img src="0blocks2/dark_grey_block.jpg" width="90" height="90" /><img src="0blocks2/block_white.jpg" width="90" height="90" /><img src="0blocks2/block_white.jpg" width="90" height="90" /><a href="headshots_deborah.html"><img src="images/headshots/Deborah_mini.jpg" width="90" height="90" border="0" /></a> </div>

    <h1>

      <script type="text/javascript">

AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','700','height','175','src','xmlmenu','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','xmlmenu' ); //end AC code

</script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="700" height="175">

        <param name="movie" value="xmlmenu.swf" />

        <param name="quality" value="high" />

        <embed src="xmlmenu.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="700" height="175"></embed>

      </object></noscript>

</h1>

  <!-- end #header --></div>

  <div id="mainContent">

    <p align="left" class="style5" style="font-size: 22px"><span class="style6" style="font-size: 20px; font-weight: bold; font-family: verdana; color: #181818">&quot;Discover Your Inner Twinkle.&quot;</span></p>

    <p align="right" class="style5"><span class="style2"><span class="style3" style="font-weight: bold">Life Art - 212.560.2518</span><br />

    </span></p>

    <h2 align="left" style="color: #990000"><img src="images/israelpoint.jpg" alt="" width="250" height="150" hspace="10" vspace="6" border="0" align="right" />LIFE ART'S MISSION</h2>

    <p align="left">Capturing the essence of who you are, whether on paper, in photographs, or on video, is what we are all about. We help you relax and open yourself to inspiration, moment to moment. The end result is a unique product that stands out in the pile and showcases you as <br />

      the star that you are.<br />

  <br />

    </p>

    <h2 align="left"><span style="color: #990000">NOW SHOWING</span><br />

    </h2>

    <table width="579" border="0" cellspacing="0" cellpadding="0">

      <tr>

        <td width="137"><div align="center"><a href="headshots_katherine.html"><img src="images/home_katherine.jpg" width="115" height="100" /></a></div></td>

        <td width="442"><strong>Headshot Package: </strong>Katherine O&rsquo;Keefe<br />

            <a href="headshots_cathy2.html" style="font-weight: bold">Click here</a> to view several of the photos taken during Katherine&rsquo;s session. Katherine is a writer/actress currently performing regularly at &ldquo;Gotham City Improv&rdquo; as a member of the long form ensemble, &ldquo;Falling Anvil.&rdquo; During her consultation she requested versatile headshots that could be used for the stage work as well as film and television auditions. <br />

            <br /></td>

      </tr>

      <tr>

        <td><div align="center"><a href="headshots_deborah1.html"><img src="images/home_deborahvideoclip.jpg" width="115" height="100" /></a></div></td>

        <td><strong><br />

          &quot;The Whole Shibang&quot; Package:</strong> Debora Richards<br />

          <a href="reels_suburbanhousewife.html"><span style="font-weight: bold">Click here</span></a> to view the headshots, lifestyle photos and original clips developed for Debora by Life Art. Like many performers, Debora had some clips of her work, but felt she hadn&rsquo;t had the opportunity to showcase her talents in a meaty, starring role. Deciding to make her own opportunities, Debora partnered with Life Art to determine her &ldquo;type,&rdquo; take new headshots/lifestyle photos and develop original clips for her reel.<br />

          <br /></td>

      </tr>

      <tr>

        <td><div align="center"><a href="reels_cathy1.html"><img src="images/home_cathyvideoclip2.jpg" width="115" height="100" /></a></div></td>

        <td><strong>Reel Development: </strong>Cathy Simpson<br />

            <a href="reels_cathy1.html"><span style="font-weight: bold">Click here</span></a> to view Cathy&rsquo;s reel, edited by Life Art. Cathy is a stage/film/tv actress who performs regularly with the dramatic improv. company, &ldquo;Epione.&rdquo; Together with Life Art, Cathy clarified her &ldquo;type&rdquo; and refined her goals for her reel. Focusing on Cathy&rsquo;s unique strengths, the reel combines clips from Cathy&rsquo;s illustrious body of work and includes supplemental lifestyle photos, headshots, and original clips developed by Life Art. <span style="font-weight: bold"><a href="reels_cathy2.html">Click here</a></span> to view the two original clips developed for Cathy in their entirety.</td>

      </tr>

    </table>

    <p align="left"><strong><br />

          <br />

      Featured Life Art Video Shorts</strong></p>

    <table width="565" border="0" align="center" cellpadding="2" cellspacing="10">

      <tr>

        <td width="275"><div align="center"><a href="reels_innertwinkle.html"><img src="images/home_innertwinkle.jpg" width="275" height="141" border="0" /></a></div></td>

        <td width="252"><div align="center"><a href="reels_suburbanhousewife.html"><img src="images/home_downwardspiral2.jpg" width="250" height="141" border="0" /></a></div></td>

      </tr>

      <tr>

        <td><div align="center" style="font-size: 11px">Click Here to View <br />

          &ldquo;Inner Twinkle.&rdquo; </div></td>

        <td><div align="center" style="font-size: 11px">Click Here to View <br />

          &ldquo;The Downward Spiral of the Suburban Homemaker.&rdquo; </div></td>

      </tr>

    </table>

    <p align="left"><span class="style4">All are video shorts created through Life Art Improvisations in collaboration with our clients.</span><br />

        <br />

    </p>

    <p align="left"><strong>Special Thanks To:</strong><br />

      Although none of the following companies are connected to Life Art directly or the creation of this site, we sure do enjoy their products. Thanks to <a href="http://www.bhphotovideo.com" target="_blank">B &amp; H Camera Supply</a> for all the equipment, <a href="http://www.staples.com" target="_blank">Staples</a> for more paper clips than we&rsquo;ll ever use, <a href="http://www.starbucks.com" target="_blank">Starbucks</a> for the occasional jolt, <a href="https://www.dunkindonuts.com/" target="_blank">Duncan Doughnuts</a> for the jolt on a budget, <a href="http://www.maccosmetics.com/home.tmpl?ngextredir=1" target="_blank">Mac Cosmetics</a> for the fantastic training you&rsquo;ve provided to some of our make up designers, <a href="http://www.apple.com/" target="_blank">Apple Computers</a> for helping me make the transition from PC, <a href="http://www.secondcity.com/" target="_blank">Second City</a>, <a href="http://www.gothamcityimprov.com/" target="_blank">Gotham City Improv</a>, <a href="http://www.groundlings.com/start.htm" target="_blank">The Groundlings</a> and <a href="http://www.thepit-nyc.com/" target="_blank">The Pit</a> for all the laughs, <a href="http://www.thelittlegym.com/" target="_blank">Little Gym</a> and <a href="http://www.musictogether.com/" target="_blank">Music Together</a> for entertaining the ones we love, <a href="http://www.finaldraft.com/" target="_blank">Final Draft</a>, <a href="http://www.apple.com/finalcutstudio/finalcutpro/" target="_blank">Final Cut Pro </a>and now for the final word, the grand finale &ndash; thanks to all of you for visiting our site!</p>

    <p align="left"><strong>Disclaimer:</strong><br />

      By choosing to be a Life Art client you're agreeing to the usage of your photographs, videos, reels and all other content and services created with us on the website and/or in other forms of marketing and advertising. </p>

    <h1>&nbsp;</h1>

  <!-- end #mainContent --></div>

 <!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats --><br class="clearfloat" />

   <div id="footer">

    <p align="center" class="style1"><span class="style2">© 2008 Life Art  212.560.2518<br />

Site Design by <a href="http://www.virtual-actor.com" target="_blank"><strong>Virtual-Actor.com</strong></a></span></p>

  <!-- end #footer --></div>

<!-- end #container --></div>

</body>

</html>

Open in new window

0
Comment
Question by:LyricalPink
  • 2
  • 2
4 Comments
 
LVL 14

Expert Comment

by:yessirnosir
ID: 22634530
One solution would be to go with a Javascript-based column layout, eg. you could modify this:
http://cross-browser.com/x/examples/layout3.html
such that your photo column height was set to match the maximum height of the other columns.  Not sure you'll be happy with the approach though, because you would end up with some of your photos being cut in two.  To demonstrate, I have attached a screen shot where I copied your photo table into a div that has it's height set = max height of the other columns, and overflow set to hidden.  This required some mods to the stylesheet and javascript, which I'd be happy to post if you are interested.  
javascript-column-height.jpg
0
 

Author Comment

by:LyricalPink
ID: 22635612
Yessirnosir,

Thanks again for your extremely helpful comments.  I think this might be the closest solution that I might be able to implement for now... would you mind posting the modified code?

Thanks again.

Best,
Ashley
0
 
LVL 14

Accepted Solution

by:
yessirnosir earned 500 total points
ID: 22636598
Ok, have attached a zip file that should be self-contained, i.e. if you unzip to a folder somewhere on your hard-drive, the references to the css and js files should work.  Unfortunately I had to rename each of the files with a .txt ending, because the EE system won't let html, css, or js files be uploaded.  So you'll have to remove the .txt from the end of each filename.

Relative to the original files the main changes are:
1.  I created a new style, #photoColumn, which is a modified version of the rightColumn style, with overflow:hidden and width changed to 185px (from 150)
2.  I inserted a bunch of your photos from a previous, table-based version of your page that was still on my hard drive.  I see you have changed that layout in your latest iteration.
2.  I modified layout3.js adding just the single line:    xHeight('photoColumn', maxHeight); which sets the new photoColumn height equal to the "maxHeight" variable.  I didn't bother deleting the references to "rightColumn" in the javascript, but you could if you wanted to because "rightColumn" is no longer used.

Hope that helps.
It occurred to me that if you wanted to prevent chopping photos in half, you could make the height setting a little more complicated by rounding it down to the next lower multiple of your photo size.  eg. if you used this code:
xHeight('photoColumn', Math.floor(maxHeight/95) * 95);
then the column height would be rounded down.  The "95" should be the sum of photo size plus any borders, padding and margin.   That may create another problem in that the photo column will no longer be the same length as the other two columns, but if you choose the same background colors for the photo div and the container div, no one will notice.
layout3.zip
0
 

Author Closing Comment

by:LyricalPink
ID: 31502611
Thanks again yessirnosir.  I wish there was an easier way to do this... but, alas, new territory.  Thanks much.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

As a result of several questions about how to use Bootstrap I thought it would be a good idea to write down the development aspect of creating a Bootstrapped website in as little time as possible. Part 1 of this article will only concentrate on g…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now