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
Lindsay Barrett
Python Web Development Techdegree Student 7,357 PointsHow to make a container any size?
I have floated an element I am am trying to make the width of it any size I want. But if the width becomes smaller than 50%, all the elements inside move around.
How can I have a element be any size on the page?
3 Answers
lauraniebel
4,685 PointsI assume your container just becomes too small to keep all the elements inside in their place... Maybe you can post your code here, so we can have a closer look at the issue?
Roy Penrod
19,810 PointsHey, Lindsay.
It sounds like what you're running into is you're resizing the container, but the contents are staying the same size and wrapping differently based on the new size of the container.
What you want to do conceptually is resize each of the elements within the floating container so they keep their proportion.
You'll set up breakpoints so that when you hit a certain size, you change the CSS properties of the container and it's contained elements.
For example, let's say you start with your floated container and it's at 100% width. It contains a paragraph with a font-size set to 2em and an image with a width of 200px floated to the right.
When you set your breakpoint for the floated container to be at 50% width, you would change the paragraph font-size to 1em (50% of the original size) and the image width to 100px (50% of the original size). You would also need to scale any white space.
Lindsay Barrett
Python Web Development Techdegree Student 7,357 PointsThank you Roy that is part of the issue. I have an div element inside a container that I want to make the background element any size.
I know with inline block you can set a width percentage and then add padding. So the element appears bigger, then its actually width.
Is this possible with floated elements? To have a container any size that content will move around if there is more padding.
Roy Penrod
19,810 PointsI'm having trouble visualizing what it is you're trying to do, Lindsay. Can you show me a screenshot of what you're trying to do?
Lindsay Barrett
Python Web Development Techdegree Student 7,357 PointsIs it possible to bring a picture into the comments? Thanks!
Roy Penrod
19,810 PointsYeah, you just need to host the image somewhere. Could be your website, Dropbox, or a free image hosting service. The tags to include the image are in the Markdown Cheatsheet just below the box where you type your comments. Just click on "Markdown Cheatsheet" and it will pop open a window with the tags.
Lindsay Barrett
Python Web Development Techdegree Student 7,357 PointsThanks Rob, I have attached the code with the sample images. Example 1 is what I am trying to achieve, example 2 is currently what is happening.
I want to make the "box2" element bigger, but the text keep moving down if I I floated the class. So I changed the the class "box2" to inline block to maker it bigger with padding, but now the text and photo are staying below instead of expanding with the background.
My Code: https://w.trhou.se/v2pmfmvcey
Thank you for your help!
Roy Penrod
19,810 PointsHey, Lindsay ...
I forked your workspace and the code is pretty broken. It looks like you yanked the html out of your complete page, but the styles aren't showing correctly without the supporting structure. For example, it doesn't even show your orange background color.
Zip the actual files you're using and email them to me at roy@roypenrod.com. I'll take a look at it and see if I can figure it out.
Roy
Lindsay Barrett
Python Web Development Techdegree Student 7,357 PointsLindsay Barrett
Python Web Development Techdegree Student 7,357 PointsYes, that is the issue. I will post the code later this evening.