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

Samuel Albert
Samuel Albert
8,839 Points

Problems in Media Query and floats

The page I'm trying to make for a desktop screen should have 2 columns in the body with additional information below it. Col 1 should be a photo. Col 2 should be an h2 element with an ul below it.

I've been able to get the desired effect outside of a media query, but have been unable to copy the results inside the query.

This is the code for the main "mobile" layout of the page in question:

 .bios h2 {
  font-family: 'Candal', sans-serif;
  font-size: 100%;
  color: #999;
  margin: 0 auto 15px;
/*  float: right;*/
/*  margin-left: 50px;
  margin-bottom: -10px;*/
}

.bios ul {
  list-style: none;
  border: 2px solid;
  width: 45%;
  margin: 0 auto 15px;
/*  float: right;*/
/*  margin-left: 50px;*/
}

.charimg {
/*  float: left;*/
/*  display: inline-block;*/
  width: 45%;
  margin: 0 auto 15px;
}

This is what I am attempting to do in my Media Query:

@media screen and (min-width: 480px) {
  .charimg {
    width: 50%;
    float: left;
  }

  .bios,
  h2 {
    width: 45%;
    float: right;
  }
      /* Clearfix
  ================================ */
  .group::after {
    content: " ";
    display: table;
    clear: both;
  }
}

I am not sure what I am missing, on my screen, the .charimg has gone to the right, the h2 and .bio ul has gone to the middle and the text that is supposed to be below it acts like there is no clearfix.

Thank you for your help!

2 Answers

Could you supply the HTML?

Samuel Albert
Samuel Albert
8,839 Points

Here's the HTML

 <div class="charimg group">
          <img src="img/pangs.jpg" alt="">
        </div>
        <div  class="bios group">
          <h2>General Information</h2>
            <ul>
              <li>Name:  Alec Huber</li>
              <li>Alias&lpar;es&rpar;:  Pangs</li>
              <li>Age:  55</li>
              <li>Race:  Human, caucasian</li>
              <li>Hair Color:  Bald (brown)</li>
              <li>Eye Color:  Blue</li>
              <li>Birth Place:  Hamburg, Germany</li>
              <li>Powers:  Telekinesis, Mind Manipulation</li>
              <li>Skills and Talents</li>
            </ul>
        </div>
        <h2>At a Glance</h2>
          <p>
            Integer gravida enim turpis. Nulla eget tincidunt ante. Curabitur sollicitudin accumsan viverra. Nunc cursus, leo eget convallis                    semper, nunc mauris ultricies nisi, nec hendrerit nunc diam nec elit. Curabitur at felis velit. Sed quis est vulputate elit ultrices adipiscing. Duis accumsan purus eget magna scelerisque, in pulvinar tellus venenatis. Aenean ultricies eros eget felis molestie, eget dignissim tellus consectetur. Praesent fermentum risus felis, ac consectetur quam fermentum vitae. Nullam lobortis fermentum lectus, sed sagittis purus hendrerit ac. Quisque augue tortor, condimentum dapibus vulputate vitae, volutpat sed sapien. Proin ultrices massa vitae fermentum congue. Cras commodo et neque consequat tempus. Pellentesque ultricies at tellus in ultrices.
          </p>
        <h2>History</h2>
          <p>
            Nulla facilisi. Suspendisse potenti. Nam et mi blandit, porta purus eu, lobortis sapien. Proin tortor mauris, venenatis quis libero   tincidunt, mattis rutrum metus. Integer consectetur semper magna. Nam ullamcorper scelerisque aliquam. Phasellus sit amet felis vehicula, convallis tortor non, sodales ante. Suspendisse potenti. Pellentesque ut urna viverra, molestie ipsum a, aliquet ante. Donec id eros eu lectus euismod rutrum eu et erat. Donec posuere posuere porttitor.
          </p>
          <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris eu justo enim. Ut ut ligula ac mi fringilla sollicitudin. Sed neque leo, vestibulum vel bibendum quis, ultricies sit amet leo. Vivamus dolor dolor, convallis sed sagittis id, consectetur in arcu. Nulla sed tempus quam. Suspendisse potenti. Nam tristique convallis eros eu egestas. Integer gravida urna id nisi auctor, et venenatis lacus porttitor. Suspendisse sodales sem id tellus rhoncus dapibus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eleifend imperdiet convallis.

</p>
      </section>

Is this not the type of result you're looking for? http://jsbin.com/vovuxego/1/edit

Samuel Albert
Samuel Albert
8,839 Points

Yes, that's it! It's looking fine now, I think the problem was I updated the wrong css file for the media query so the second css file was overriding the first. Fixed now and it looks great! Thank you for the help.

Evans B. Ofori
PLUS
Evans B. Ofori
Courses Plus Student 13,720 Points

Hello Samuel, I have added example (below) the use of clearfix, have a look if it makes sense to you. The "clearfix" should be apply to the parent element.

<div class="wrapper group">
        <div class="col1">
            <img class="" src="">
        </div>
        <div class="col2">
           <h2></h2>
           <ul></ul>
        </div>
    </div><!-- end clearfix -->

@media screen and (min-width: 480px) {
.col1{
    width: 50%;
    float: left;
  }

  .col2{
    width: 45%;
    float: right;
  }
}

Good luck, and let me know if you need more help.

Samuel Albert
Samuel Albert
8,839 Points

That all makes sense, the problem seems to be the clearfix isn't working any longer. Perhaps I'm not putting that code in the right place? Right now it's in the media query under the .col1 and .col2 and I'm still having a problem with the floating being reversed. Col1 is showing up where col2 should be.

This is my updated HTML:

  <div class="group">
      <div class="charimg">
        <img src="img/pangs.jpg" alt=" ">
      </div>
      <div  class="bios">
        <h2>General Information</h2>
          <ul>
            <li>Name:  Alec Huber</li>
            <li>Alias&lpar;es&rpar;:  Pangs</li>
            <li>Age:  55</li>
            <li>Race:  Human, caucasian</li>
            <li>Hair Color:  Bald (brown)</li>
            <li>Eye Color:  Blue</li>
            <li>Birth Place:  Hamburg, Germany</li>
            <li>Powers:  Telekinesis, Mind Manipulation</li>
            <li>Skills and Talents</li>
          </ul>
      </div>
  </div><!-- end clearfix -->
Samuel Albert
Samuel Albert
8,839 Points

Okay, I fixed the problem and everything is looking good. It looks like I updated the wrong css file. Thanks for your response.