Floating li left and the background image vanishes

Associate
Joined
19 Jul 2006
Posts
1,847
Bit of a odd one I have started pulling in images from facebook :) as a li they display fine down the page however if i float them left the background colour of the containing div disappears ??

PHP:
 <div id="page">
            <div class="content">
                <div id="pagetitle">Gallery</div>
                <div class="left">
                    <div id="mainContentgallery">
                         <?php

		//Set the page name or ID
		$FBid = '##############';
			//Get the contents of a Facebook page
		$FBpage = file_get_contents('https://graph.facebook.com/'.$FBid.'/photos');
		
		//Interpret data with JSON
		$photoData = json_decode($FBpage);
				
			foreach ( $photoData->data as $data )
		{
		echo '<li><img src="https://graph.facebook.com/'.$data->id.'/picture/"  />';
		echo '<br />'.$data->name.'</li>';
		}

	?> 
                    </div>
                   
                </div>
                <div class="right">
                    <div id="twitter"></div>
                    <!--<div id="advert"></div>-->
                </div>
                <div class="clear"></div>
            </div>
        </div>

CSS
Code:
/**gallery only**/
div.left div#mainContentgallery {
   font-family: 'Crafty Girls', cursive;
	font-weight: normal;
      font-size: 10px;
   width:650px;
   background-color:#FCF5D7;
   margin:20px;
   margin-right:0;
   
}

div.left div#mainContentgallery img {
 
 height:150px;
 width:150px;
}

div.left div#mainContentgallery li {
float:left; /** This loses the background colour from maincontentgallery div**/
padding:20px;
 padding-right:20px;
 list-style: none;
 width:150px;
}

any ideas?
 
Code:
/**gallery only**/
div.left div#mainContentgallery {
   font-family: 'Crafty Girls', cursive;
	font-weight: normal;
      font-size: 12px;
   width:650px;
   background-color:#FCF5D7;
   margin:20px;
   margin-right:0;
   padding-bottom:20px;
}

div.left div#mainContentgallery img {
 
 height:295px;
 width:295px;
}

div.left div#mainContentgallery li {
 display: inline-block;
 padding:20px;
 padding-right:0px;
 list-style: none;
 width:295px;
 height:295px;
}

Trip where would i display block and float left? I have tried it in the li section and it breaks it again??
 
Where is the ul tag to wrap the li elements in that code btw?

A useful trick when floating elements is to set overflow: auto; to the containing element (in this case a ul) and it will ensure that the containing element wraps the floated element. If you don't, you will have the floated elements within a containing div which is 0px high.
 
Trip where would i display block and float left? I have tried it in the li section and it breaks it again??

I'll do you one better and show you how to make a proper nav. (provided you aren't using html5)

http://jsfiddle.net/De8zV/

edit: I should add that the css I've put on jsfiddle doesn't include any resets for browser defaults such as padding or margin.
 
Last edited:
No worries got this now which looks to do the job
PHP:
/**gallery only**/
div.left div#mainContentgallery {
   font-family: 'Crafty Girls', cursive;
	font-weight: normal;
      font-size: 12px;
   width:650px;
   background-color:#FCF5D7;
   margin:20px;
   margin-right:0;
   padding-bottom:20px;
}

div.left div#mainContentgallery ul{
list-style: none;
overflow: hidden;
}

div.left div#mainContentgallery li {
 display:block;
 float:left;
 padding:20px;
 padding-bottom:40px;
 padding-right:0px;
 
 width:295px;
 height:295px;
}

div.left div#mainContentgallery img {
 
 height:295px;
 width:295px;
}
 
Back
Top Bottom