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

Setting elements to %

Okay so I have set a div to a width of 90%. Inside the div I have set the elements h4 and p to 70%. When the browser is resized the h4 and p fall beneath the image which is fine. However, when they fall beaneath the image the are pinned to the left of the screen and the h4 and p elements are no longer centered because of the %. Is the only way to fix this to use a media query at that browser width and then change some of the declarations? Whats the best way going about this?

Thanks! Below is the code.

/******** CSS ********/

  • { border: 1px solid black; } body { margin: 70px 0 0; background: #e1e1dd; color: #8A8A8A; font: normal 62.5%/1.3 "Helvetica Neue",Helvetica,Arial,sans-serif; }

div { margin: 0 auto; padding: 25px 0px; width: 90%; border-radius: 5px; background: #FFF; }

h4 { margin: 0 0 12px 0; color: #33383D; font-size: 1.8em; width: 70%; float: left; }

p { margin: 0; font-size: 1.5em; width: 70%; float: left; }

img { float: left; margin: 0 25px; }

.group:before, .group:after { content: ""; display: table; } .group:after { clear: both; } .group { *zoom: 1; }

/******** HTML ********/

<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <title>Floats</title> <link rel="stylesheet" href="style.css"> </head> <body> <div class="group"> <img src="flag.png"> <h4>Build a Simple Website</h4> <p>Smells Like Bakin' is a cupcake company in need of a website. This project will walk us through the basics of HTML and CSS from the very beginning. HTML and CSS are the structural and presentational building blocks of every website and will serve as the foundation for any web project. The Smells Like Bakin' cupcake company needs their website to work on tablets and phones. We will modify the code of their pre-existing website so that it is flexible and fits beautifully into a wide variety of screen resolutions and devices.</p> </div> </body>

2 Answers

Ana Gledovic
Ana Gledovic
7,465 Points

Hi Michael, please, watch the video here on the right side, "Tips for asking questions", for better and easier to understand the question. Best, Ana

Remove 'float: left' from h4 & p elements and possibly use 'text-align: center' depending on your needs