The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS [Solved] Beginner: CSS Layout problem

  • This topic is empty.
Viewing 15 posts - 1 through 15 (of 22 total)
  • Author
  • #161181

    Hi, I new to this forum and this is my first post related to css. Recently I have started learning CSS. I am using pure css for creating this website

    Here I have several problems regarding my code. Please help me 1. My fixed header(id:navigation) is eating the div container (id:content) 2. I am not able to set the background for (id:navigation) fixed header div 3. How can I make the scroll smooth using pure css if possible

    If possible can anyone give me pure CSS solution for these. Here is the codepen link


        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "">
        <link rel="stylesheet" href="style.css" type="text/css">
            <div id="navigation">
                    <li><a href="#one">One</a></li>
                    <li><a href="#two">Two</a></li>
                    <li><a href="#three">Three</a></li>
                    <li><a href="#four">Four</a></li>
                    <li><a href="#four">Five</a></li>
            <div class="content" id="one"></div>
            <div class="content" id="two"></div>
            <div class="content" id="three"></div>
            <div class="content" id="four"></div>
            <div class="content" id="five"></div>


        margin: 0px auto;
    #navigation {
        text-align: center;
        background: rgba(0,0,0);
    ul {
        display: inline-block; /*important line*/
        list-style: none; /*define it in ul tag*/
        padding: 0px;
        margin: 0px auto;
    li { 
        width: 159px;
        float: left;
        /*border: white solid 1px;*/
        border: 1px dashed #000; 
      font-family: Helvetica, Verdana,  sans-serif;
      font-size: 14px;
      font-weight: bold; /*normal,bold,900px*/
     /* font-style: normal, italic, oblique*/
      text-align: center;
      color: white;
      display: block; 
      padding: 8px;
    a :hover{
      color: rgba(255,0,0);
      width: 800px;
      margin:0px auto;
       background: green; 
       background: red; 
       background: blue; 
       background: gray; 
       background: black; 

    Because the fixed header is ‘taken’ out of the flow the rest of the content moves up.

    To correct this add some padding-top to the first element after the header, usually the same amount as the height of the header.


    I’ve made a couple of corrections to your CSS as well


    thank you Paulie_D ! :) But still div (id:content) is hiding under the header. Using padding I can shift the content but can you tell me how to shift div container below the header?

    Other problem is that background-color: is not taking rgba() where as hex is working fine in fixed header(id:navigation)


    but can you tell me how to shift div container below the header?

    Technically, you can’t because you have fixed position the header.

    The padding-top just means that the actual content (text etc) inside your '.content divs will be pushed down.

    There is a sort of hacky way where you can add 'margin-top to the first content div in the same way as the padding-top. Now initially this won’t do anything due to the way margins collapse but if you add a 1px transparent border to the body it has the same effect.

    Codepen updated to show this option:

    The padding-top is the best solution though.

    Other problem is that background-color: is not taking rgba() where as hex is working fine in fixed header(id:navigation)

    You have to remember that rgba requires 4 values whereas your original had omited the last alpha/opacity value.


    Okay then shifting the div container using css is not possible then is it possible using js? if yes then how?


    What do you mean by “shifting the div container”? It’s not clear what you want to achieve that hasn’t been solved by Paulie.

    Visually, it appears below the menu header. Technically, it’s a margin/padding that shifts it down, but that doesn’t matter, as what the user sees is the effect you seem to be looking for.


    I wanted that the top of the div containers with id: content should touch exactly bottom of the fixed header. I wanted it to be done using pure css but since Pauli_D said it is technically not posssible becasue I have fixed the header. Do you have any idea if I can’t do it with pure css then how to do it with JS.


    navigation is fixed, but not told to where.

    Add: top:0; This positions it to the top of parent/body.

    Place the divs classed as “content” inside a wrapper and move it down the height of the Nav. Add to the Markup: [div id=”wrapper”> [“content” id= one-five] [/div>

    Add to the stylesheet:
          #wrapper {margin-top:32px;}

    To set the colors in the Nav section, Add to the stylesheet: li:first-child {background:green;} li:nth-child(2) {background:blue;} li:nth-child(3) {background:red;} li:nth-child(4) {background:maroon;} li:last-child {background:tan;}

    Anyway, problems with this forum – check out the revised version at:


    @Gus Thanks but now the links are not working, I mean when you click on the links it doesn’t go to the divs.

    [solved] sorry it was not working in the codepen but when I ran it from my html file it worked. Thanks :)

    [Problem] Now again the wrapper margin only work once at the page load but after that when you click on the links to navigate other divs, rest of the div containers remain have some hidden top under the header.


    Do you mean like this? All I did was take what Paulie_D did and change the padding-top to 30px instead of 50px so it visually aligns with the navigation.

    Because the header is fixed, it is removed from the flow of elements. Nothing can change that, CSS or JS. What you can do is make it appear that it’s behaving that way, which is exactly what he did. There’s no reason to use JS because it can only do the same thing, make it appear that way.


    @nkrisc …. Pauli_D has solved my problem but the other problem was almost solved by the GUS :) but I think his code needs a little tweak to achive what I exacly want.


    can anyone of you tell me why two javascripts used in the code is not working together?

    I have seperated them by dotted line


    can anyone of you tell me why two javascripts used in the code is not working together?

    Please create a new thread in the Javascript section for this since your original problem has been solved


    Pauli_D :) Thanks for suggestion but I have solved the problem. Actually it needed to be inlude jquery.min.js in the head section and it is working now but can you tell me when I have created each file on my desktop such as html, css and js file and linked css and js file in the html so CSS file is working fine but javascript is not working at all. I have tried to link the js file both ways. I have downloaded the jquery.min.js

        <script type="text/javascript" href="jquery.min.js"></script> 
        <script type="text/javascript" src=""></script> 

    It has again stopped working. Am I doing something wrong?


    You’re linking to the same (apparently) file in two different places (one local and one at the CDN) and there is no need to do that.

    However, if you still can’t solve a JS issue…please start a new thread in the JS section.

Viewing 15 posts - 1 through 15 (of 22 total)
  • The forum ‘CSS’ is closed to new topics and replies.