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

Mark Libario
Mark Libario
9,003 Points

My images with different sizes wont align properly with float and the <p> that i have under each image.

I used different photos of my own with different sizes and tried to use the float property. It appears that my photos do not align properly and the text under each photos are in different places. it looks like a mess..

<!Doctype html>

<html> <head> <meta charset="utf-8"> <title>Lovers in Paradise | Mark and Donzie</title> <link rel="stylesheet" href="css/normalize.css"> <link href="https://fonts.googleapis.com/css?family=Lobster|Oxygen" rel="stylesheet"> <link rel="stylesheet" href="css/main1.css"> </head>

<body> <header> <div id="header"> <a href="index.html" id="logo"> <h1>Practice Header</h1> </a>
<h2> Mark and Donzie</h2>

   </div>  
 </header>

<div id="page">
  <nav>
    <ul>
      <li><a href="index.html">Getaways</a></li>
      <li><a href="parties.html">Parties</a></li>
      <li><a href="anniversay.html">Anniversaries</a></li>
      <li><a href="family.html">Family</a></li>
    </ul>

  </nav>


<div id="wrapper"> 
  <section>
    <ul id="gallery">
      <li><a href="img/getaway1.jpg"><img src="img/getaway1.jpg" alt="big red square"></a></li>
      <p>The Big Red Square Totem Picture</p>
      <li><a href="img/getaway2.jpg"><img src="img/getaway2.jpg" alt="timesquare"></a></li>
      <p> A Quick Snap of Time Square, New York</p>
      <li><a href="img/getaway3.jpg"><img src="img/getaway3.jpg" alt="trump building"></a></li>
      <p>Being Creative with the Trump Building</p>
      <li><a href="img/getaway4.jpg"><img src="img/getaway4.jpg" alt="big red square2"></a></li>
      <p> The Big Red Square Totem Picture part 2</p>
    </ul>  
  </section>

  <footer>

    <a href="http://www.instagram.com/itzkelvz">
      <img src="img/instagram.png" alt="instagram logo" class="social-icon">
    </a>
    <a href="http://www.facebook.com/mkelvz">
      <img src="img/facebook-wrap.png" alt="facebook logo"class="social-icon">
    </a>
    <p> &copy; Mark Libario 2017.</p>

  </footer>
</div>


</div>

</body>

</html>

Mark Libario
Mark Libario
9,003 Points

a { color: #000; text-decoration: none; padding: 15px; }

a:hover{ color: red; font-family: 'Oxygen', cursive; text-decoration: underline;

}

img { max-width: 100%; }

body { text-align: center; }

page {

max-width: 940px; margin: auto; }

/HEADER/

header {

letter-spacing: 0.15em; text-align: center; } h1 { font-family: 'Lobster', sans-serif; border: 4px double #000; padding: 15px; color: #00f;

}

h2 { font-family: 'Oxygen', cursive; font-size: 16px;

}

/* NAVIGATION*/

a { font-weight: bold; }

ul { margin: 0px auto 0px auto; padding: 20px; text-align: center;

}

li { display: inline; margin: 0px 10px; }

page {

border-top: 2px solid; border-bottom: 2px solid; }

/BODY/

gallery li {

float:left; width: 45%; }

footer { clear: both; }

2 Answers

Cory Harkins
Cory Harkins
16,500 Points

It looks as though you are missing some syntax in a few areas.

gallery li (for example) in your HTML you have an ul with an id of gallery, yet your CSS is just gallery li {prop:value;}, the syntax should read #gallery li {prop:value;}

Also, it looks as though you have #page taking up your entire page. This (in my opinion) can lead to a lot of positional issues. I suggest re-writing your code to "wrap" contents within a div that pertain to the content and is named semantically; i.e,: "heading, main-nav, main-content" etc.

Resulting in:

<div id="main-nav">
  <ul>
    <li></li>
  </ul>
</div>
<div id="main-content">
  <h2></h2>
  <ul>
    <li>
      <a href="">
        <img src="" alt="" />
          <p>
          </p>
      </a>
    </li>
  </ul>
</div>
<div id=footer>
  <p></p>
</div>

As for the float, when given a height and width to the div containing the images, you can better float the images. Someone please correct me if I'm wrong, however, when floating an object, the top left corner of your element is placed at 0,0 (x,y) opposed to an inline-block element that will have a variable y, and an x dictated by width.

I hope that gives a little more insight.

Just a little helpful advice as well, there is a link to a "Markdown cheatsheet" that will give you documentation as to make your code more readable to others to help you. When you use the backtick ` three times to open your code, and 3 times to close your code, the markup will be more legible for everyone to help you :)

( ` * 3) remove the parenthesis and spaces. .paste { your: code; between: thebackticks; }

( ` * 3 ) remove the parenthesis and spaces.

:)

Mark Libario
Mark Libario
9,003 Points

Thank you, Ill try to re-write the code once again. I dont want to just follow the video example per example but rather try to create a new one based on what I understood. I guess Ill use more <divs> now. Ill let you know if there's any improvement.

The only problem and question i really had was the floating of images with different sizes (height and width). would it be better to do it first with empty boxes with border just to see how it all works?

specially having several <divs> and with a gallery in one of them with photos of different sizes, how would i know what width and height i would give it to make it float better?

Cory Harkins
Cory Harkins
16,500 Points

I think what you are referring to is tiled gallery, a mosaic of some form. Kind of like tumblr, or a pinterest board of div's/images. There are JavaScript functions that can dynamically scale images within a gallery, and then lightbox them.

My suggestion to you is to follow verbatim the lessons, then branch out by using borders for divs with no images. Play with these for a while and you will start to understand the behavior of CSS positioning.

<div id="parentA" class="box"> Parent A
  <div id="childA_1" class="box">Child 1</div>
  <div id="childA_2" class="box">Child 2</div>
</div>
<div id="parentB" class="box"> Parent B
  <div id="childB_1" class="box">Child 1</div>
  <div id="childB_2" class="box">Child 2</div>
</div>

These 2 divs and their children have helped me out SO MUCH. Make more and float them, etc.

You got this!

Mark Libario
Mark Libario
9,003 Points

Ok perfect! Ill try using this. I just tried putting solid borders in different sections/parts of the body just to see how how the css affects them specially the margins, paddings, line-height, etc. and then I delete those borders once I understood how it works and it gets affected. I just didn't want to just follow to the dot and not really understand why he is doing this or that on some sections :P