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

Same padding-top, but pages behave different, how do I solve this?

The padding-top for the "Buteyko taining" page is 140px. Just as the "Symptomen" and the "index" page. The last two pages are appearing neatly under the header. The Buteyko training page doesn't. Part of the text is behind the header.

Why is that and how do I solve it?

https://w.trhou.se/ap0aeyglqb

8 Answers

Let me start here and then get into the problem at hand. I'm not sure if you're aware of this, but you can inspect each element of your webpages CSS individually in the browser. Open the live preview of the page and go to the menu of the browser - where you'd go to look at history, bookmarks, or to change your settings. Go to more tools, developer tools and open the console. On the top left there's a little box next to an inline directory. The little box has a cursor arrow on it. Click that and then you can individually click on an element to view its default, or your style to it. Additionally, you can click on the element in the browsers html file in the console and it will highlight the selected element. This is a good way to debug your page, when it is not acting as expected.

Onto positioning --- first, you have contradictory styling. Your h1 has a margin-top of 38px, <section> has a margin of -80px, and #index has a padding of 140px. You would be well served to erase those and look at the behavior of the page in the browser - check out the console too. You should see that the h1 is hidden at this point. Why is the h1 hidden? Because you've changed the flow of the page by having a fixed navigation header. In other words, the nav section is no longer interpreted as part of the flow of the document. Test this by going to your main.css and putting a position of relative on the <header> and go back and preview the page again. You will see that <section id="index> has moved down and is visible because now <header> is part of the flow of the document. So now what? How do I handle this? I need my header to be fixed, but I obviously need my <section id="index> to be visible. Can you think of how to move <section id="index"> down below the nav header? What are some ways you can keep it in the flow of the document and what repercussions would you have by choosing one method over another? Hint: once you've eliminated all of the settings at the beginning of this paragraph all you need is one of them to move the <section id="index> down. NOTE: the repercussions might not apply here, but it's good to know them. Think about what you know about background-colors and how the box model plays into showing or not showing colors when different properties are applied.

Some other things to think about.... When styling your html, sometimes a fixed height is a good thing and other times it's not. Lets take your header nav section for an example. You currently have a fixed height, but when you resize the viewport it pushes the two large buttons down into the <section>. You can avoid this by setting a min-height. This will allow the browser to manipulate the headers height based on the needs of that particular section. It will grow to accommodate your buttons when they push down rather than have them possibly overflow onto, or behind another element. Its essentially the same as width 80% margin auto(to center), or width 100%. The min-height will allow for flexibility, if needed/wanted in the same way a % will.

Additionally, take a look at your main.css and note line 3, get in the habit of setting your body style - this will initialize the page, and good rule of thumb is margins: 0;, padding: 0;, color, font-size, font-family, line-height, etc of your entire document and will lead to an easier and more predictable layout, and if you need one element to be different just change that element, and remember that CSS means cascading style sheet(try putting background-color to black at the top of one of your sections grouped css and then go down to the very bottom of your css file and set the same elements background-color to red to get a visual representation of how this can impact your page when you have contradictions). Your CSS should follow the flow of the document. Each section should include all of the style for that section. Separating your id style and putting it at the bottom can lead to frustration of other developers who might work on your code and the stuff at the bottom gets rendered last. If they are teaching you to separate them, then follow what they say, but keep it in mind for later or leave comments at the top of your CSS file to let the next dev know that is how you like to write your CSS.

body {
    property: value;
}

header {
    property: value;
}

#section1 {
    property: value;
}

.section2 {
    property: value;
}

footer {
    property: value;
}

Let me know what you come up with for moving the <section id="index"> down. Good luck! If you need help figuring it out, feel free to ask. Oh, before I forget. Just as your CSS is structured with spaces, tabs, and carriage returns, you should have the same habits for making your html file readable as well. Nested elements get indented from the parent.

First, I can't see the page Buteyko taining. Second, at the line 31, you're opening another body tag. Third, never add space between the words in href parameters on the "a" tag. Right now it's "Buteyko training". Try to change to "buteykotraining" or "buteyko_training" as you prefer.

Thanks for the tip about Buteyko_training/buteykotraining. Although I don't know why I won't use any spaces anymore there. This is the right snapshot btw https://w.trhou.se/kwdjlte2yy.

I don't see any missing elements, but..... In addition to what Lucas said, you have a number of syntax errors in your CSS file, as well, there is some extraneous/repeated property-value pairs(read background-color...as one of them). I'm not aware of the specific lesson, but I'd be wary of using 'selected' as an id. It could be a way to get you used to the idea of placing selected in the tag, but again, I didn't take the course. If you haven't already learned about attributes, selected is one and requires no prefix. It is best to avoid using classes and id's that resemble predetermined keywords, in any language. It's like saying class="div" or <h1 id="h1">Your header</h1> here's a way that selected is used.. <option value="your-value" selected> choice </option> Keep in mind, consistency is important, when writing your code. CSS selectors should always have a space after them and then the curly brace, don't place empty lines after the property-value pair, and place a carriage return between the closing brace and the next selector. You want your code to be readable to not only you, but anyone that comes along after you.

Notice the difference between the css rule 1, rule 2 && rule 2, rule 3? As well, rule 3 has some serious issues all on its own.

selector {
    property: value;
}

selector {
    property: value;
}
selector{ 
    property:value;

}

May I ask why your header is carried off the page with a margin-left: -30px;? Why not just keep it short of 100% on the width property-value pair? Furthermore, instead of using a margin of 900px to move an element down below another one, why not set the height of the #index section to 900px and move the paragraph inside the #index to wherever you want.. I hope this helps you. Good luck and keep working at it! You'll get there one line of code at a time and some patience.

Excuse me, here is the right snapshot. https://w.trhou.se/kwdjlte2yy I think the margin -30px is solved here as it should be. Setting the height seems a clearer solution. How should I implement that in the code I posted in the snapshot? I tried #index {height: 140px} but that messes everything up. Thanks for the advices about css, i corrected that.

The height of the header is adjusted, the body is styled and I think the css follows the flow of the document. The id’s are brought together in one id and placed under the header wich I think is in the flow of the document. And I cleared up the html.

The contradictory style is erased and I have reviewed tutorials on youtube about the box model. Only I don’t know what you mean with <section id="index>? That code isn’t in my html. Maybe the <section id="index> was from another snapshot. I am keeping track now of the present workspace when I ask a question. This is the snapshot after your response on https://teamtreehouse.com/community/how-do-i-float-three-images-in-a-row.

https://w.trhou.se/slaq0jnfdr

Yes, i have a question: I didn't change any coding in flexbox, but the "Symptomen" page isn't aligned anymore? And what's best practice to make the h1 appear, with padding-top? Thanks for all the advice and info!

Sorry for the long delay, been out of town. I only see one html file, so, I'm not sure about your "symptomen" page. Good, I'm glad you looked up the box model. It's important to know. As far as your header goes... I personally use margins to move things, unless the behavior will impact my page negatively. Sometimes the behavior requires padding to be adjusted, like text in a table moves with padding, but not margins, or if I plan to put a background-color to it - like a button. I think it just depends on the situation. The question lies in where the child is how you want to style it, what lay above it, parent element style and, again, bg color. Odd behavior - sometimes a child with a margin on top can push its parent element down(leaving unintended white space between two sections) and other times it wont. If I recall correctly this has something to do with the parents margins and collapsing margins, but to be honest, I just change to padding or relative position when I have a problem like that - which is when the parent has no margin and I want each sections bg color to meet. I did find this - http://stackoverflow.com/questions/1762539/margin-on-child-element-moves-parent-element

That's ok, i was allready thankfull for your previous advices, but glad to see your reply. To be honest I was hoping for that, because your answers are one of the best that I got here. Thanks for sharing your approaches to these kind of problems. As you know I am learning coding by myself. Although treehouse is a great learning environmont it seems my development here is slowing down. For now I am watching EJ media's jquery's tutorials on youtube in order to create a mobile drop down menu. It would be great if you want to answer my questions about that later. For now power to you, especially in the recovery of your health!

Of course, I'm glad to help. I wouldn't worry too much about your progress. You're going to hit many temporary plateaus while going through the process. As a self-taught person, I can attest to the struggle of trying to gather info, comprehend it, and retain it, as well as trying to break through that next step. I think we all hit these issues, maybe just at different points. Here's how my journey has gone. I started with C programming about 6 months ago. I worked diligently for a month teaching myself before realizing I wanted something more/different. Day in and day out I was banging my head trying to see how this could all be useful later, even though I knew what it could be used for. About the same time, I had a lot going on with doctors, work, and disability so I took a break. About 2 weeks after my hip surgery, in mid-November, I decided I wanted to learn web development. I started with Coursera, followed by Freecodecamp, then Codeacademy. I didn't do Treehouses HTML and CSS courses, so I don't know what they're like. For me, the Codeacademy course is what really dialed in the knowledge. Prior to that, I felt like I was just going through the motions and not really learning anything, just parroting. Coursera's course was too intense for me. I chose their software engineering course and it dove right into deeper concepts of javascript - introduce giant brick wall number one. Freecodecamps program was nice and seemed like a more practical approach. The understanding that I garnered there was useful in accelerating my learning at Codeacademy. After Codeacademy's course, I went from spending 2 full days - I work on this stuff anywhere from 8 to 15 hours a day - trying to make a landing page to finishing them in just a couple of hours, and they were much better. This time includes wireframing, finding images, or anything else going on the site and then building the static page. After completing their course I went back to Freecodecamp and started their javascript courses. About halfway through I felt lost and sort of defeated. I understood loops and variables from doing C, but there were so many methods and the implementation seemed so foreign. I took a week off and tried to find something that seemed more in depth. I really want to become a full-stack developer and know that I can't do it without js and all the things that go on top of it - read Nodejs, MongoDB etc. I went back to Codeacademy and then ran out of money so I dropped the courses. I got an online book and started with that - nope, not working. This is when I came across Treehouse and their javascript program. It seemed very detailed, covering all the basics from the front through the back end. I sold some stuff around my house to get enough money to pay for the course. So far I like the way they go about things. I've been on it for a couple weeks but wasn't able to work much last week. I've had a couple AHA moments, but I still struggle daily. It's true what they say, there are those AHA! moments, followed by brick walls, all the time. I've decided that when I hit a brick wall, I'm going to take a small leave of absence on learning the next thing and solidify what I've already been working on. I think this will work for me because I'm pretty sure, for me, the brick wall is not having as strong of an understanding/command of the previous concepts as I thought I did. I don't think this slows down the process any, I actually think it will accelerate it. It's nice to feel accomplished by breezing through the courses, but in the end, I just feel like I haven't learned anything if I don't slow down. In fact, I'm going back and restarting the js course from the beginning. So, long story long, don't be too hard on yourself and know you're not alone in the struggle. Just don't give up.

On your question...you said media jquery's - are you working on media queries or jquery? I did a little jquery, but not enough to be helpful. If you're interested in talking about media queries, I can definitely help with that, so ask away.

Have a good one!

Great to read about your determination. If you have that mindset you will surely become a full stack web developer.
And good to hear your learning process, I had the idea that I should have profeciency in webdesigning now, because i see a lot of courses on internet wich say you can become a web designer in less than a month. I realise now that it takes more time to be a full stack web developer. If you want to know more about jquery I would recommend to watch the jquery tutorials on youtube from EJ media. I understood every tutorial in his series. And you can follow along in his tutorials with notepad++. The code's are also added in the youtube descriptions to make it easier. After those tutorials I went to the the jquery course at treehouse again. To the module on how to create a mobile drop down menu. In the course task I could create the mobile drop down menu, but on my own site i need to do some other things to make it work. If you check https://w.trhou.se/34ml37jffu you will see the media queries. I don't understand why the drop down menu dissapears when I resize my viewport. Do you know what to do to make that work? Sorry for the spelling error, this message has answered your question about that :)

It has been a while since I've been on here. Were you able to figure out the problem with your media queries? I saw you added me, or I assume that was you that added me on Ig. I will have to check those tutorials out, thanks for the heads up on that. I've been working my way through Codewars problem sets this week, well aside from the past couple days...I've spent those detoxing from the exorbitant amount of cigarettes I smoke. Today is day 3 and I feel somewhat more human today. Yeah, those that tout learning in a month might be talking about knowing enough to actually do something with it?? But, there's no way you could go from zero knowledge to job ready in one month. I feel like the more I learn this stuff the less I know. That's just my opinion, though.

Hi Kylee, i came across freecodecamps and became a member there. (RenevandenHeuvel) In a few days I will pause my subscription here. Talk to you later? I have also added you on instagram.