Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

CSS/HTML

When I add the "float: left;" declaration to the ".profile-photo" class in the about page, the header shrinks in width, shows a white patch and profile picture moves there. Index and contact pages are working fine. Could anyone please help?

main.css
/************************************
               General
*************************************/
body{
    font-family: 'Open Sans', sans-serif; 
}

#wrapper{
    max-width: 940px;
    margin: 0 auto;
    padding: 0 5%;  
}

a{
    text-decoration: none;

}
img{
    max-width: 100%;
}

h3{
    margin: 0 0 1em 0;
}



/************************************
               Heading
*************************************/
header{
    float:left;
    margin:0 0 30px 0;
    padding: 5px 0 0 0;
    width: 100%;
    text-align: center;

}


#logo{
    text-align: center;
    margin:0;
}
h1{
    font-family: 'Changa One',sans-serif;
    margin: 15px 0;
    font-size: 1.75em;
    font-weight: normal;
    line-height: 0.8em;
}

h2{
    font-size: 0.75em;
    margin: -5px 0 0;
    font-weight: normal;
}

/************************************
               Navigation
*************************************/

nav{
    text-align: center;
    padding: 10px 0;
    margin: 20px 0 0;
}
nav ul{
    list-style: none;
    margin:0 10px;
    padding: 0;
}
nav li{
    display: inline-block;
}

nav a{
    font-weight: 800;
    padding: 15px 10px;
}

/************************************
               Footer
*************************************/

footer{
    font-size: 0.75em;
    text-align: center;
    padding-top:50px;
    color: #ccc;
    clear:both;
}
.social-icon{
    width: 20px;
    height: 20px;
    margin: 0 5px;
}

/************************************
               Page: Portfolio
*************************************/
#gallery{
    list-style: none;
    padding: 0;
    margin: 0;
}
#gallery li{
    float: left;
    width:45%;
    margin:2.5%;
    background-color: #f5f5f5;
    color: #bdc3c7;
}

#gallery li a p{
    margin: 0;
    padding: 5%;
    font-size: 0.75em;
    color: #bdc3c7;

}


/************************************
               Page: About
*************************************/


.profile-photo{
    display: block;
    max-width: 150px;
    margin: 0 auto 30px;
    border-radius: 100%;

}


/************************************
               Page: Contact
*************************************/

.contact-info{
    list-style: none;
    padding: 0;
    margin: 0;
    font-size: 0.9em;
}
.contact-info a{
    display: block;
    min-height: 20px;
    background-repeat: no-repeat;
    background-size: 20px 20px;
    padding: 0 0 0 30px;
    margin: 0 0 10px;
}

.contact-info li.phone a{
    background-image:url('../img/phone.png');
}

.contact-info li.mail a{
    background-image: url('../img/mail.png');

}

.contact-info li.twitter a{
    background-image: url('../img/twitter.png');

}

/************************************
               Color
*************************************/


/* Site Body*/
body{
    background-color:#fff;
    color:#999;

}


/* Green Header*/
header{
    background-color: #6ab47b;
    border-color: #599a68;
}

/* Nav background on mobile devices */
nav{
    background-color: #599a68;
}

/* logo text*/

h1, h2{
    color: #fff;
}

/* Link color*/
a{
    color: #6ab47b;
}



/* nav link*/
nav a, nav a:visited{
    color:#fff;
}

/* Selected nav link color*/
nav a.selected, nav a:hover{
    color: #32673f;
}
responsive.css
/* for larger phones and small tablets*/
@media screen and (min-width: 480px){

  /* Two column layout */
  #primary{
    width:50%;
    float:left;
  }

  #secondary{
    width:40%;
    float:right;
  }

  /***********************************************************************
  margin :2.5% all sides
  for three elements: 3*5=15%
  total screen width 100%
  elements size = 100-15= 85%
  each element size for three column layout : 85/3 = 28.33333333
  /************************************************************************/
/**********************************************************
          Three column layout for  page: Portfolio;
***********************************************************/
  #gallery li{
    width: 28.33333%;

  }
  #gallery li:nth-child(4n){
    clear: left;
  }

/************************************
              Page: About;
************************************/
  #profile-photo{
    float:left;
    margin: 0 5% 80px 0;
    }
}
/* for larger tablets and desktop*/
@media screen and (min-width: 660px){
/**********************
     Header
***********************/
nav{
  background: none;
  float: right;
  font-size: 1.25em;
  margin-right: 5%;
  text-align: right;
  width: 45%;
}



    }

}

Screen Shot :[screenshot link]( http://i.imgur.com/UXXqNJq.png?1)

Can you post your HTML as well please.

2 Answers

Anitha Velayutham,

If I understand the issue correctly, that's expected behavior. Floats can be tricky to get your head around and some of the behavior is non intuitive. I'd recommend reading this article to get a better understanding.

The solution here would be to apply an explicit width/height to your header element so that its dimensions aren't effected by its contents.

Thanks Vishal. That was really helpful. Now I know what should I do, when I face problems with float element.

Can i ask why you are floating the header? That could be the reason why your header is shifting over. Try removing the header float and that should be all you need.

Hi Chyno, Thanks for your response. It was a silly mistake. I used ' # ' instead of '.' to select a profile-photo. Float is used to adjust the header width respect to the browser window size.