Solution 1 :

Give your header top: 0; to move it to the top, some height to your list (or calculate it using JavaScript, etc.). Also give your ‘.anan’ margin-top: (height of your header and list to compensate.) Note that there may be a better version that doesn’t require setting height to the list, I just can’t think of it right now 🙂

*{
            padding: 0px;
            margin: 0px;
            box-sizing: border-box;
        }
    
        :root{
            --background: rgba(85, 214, 170, .85);
        }
    
        html{
            font-family: sans-serif;
        }
    
        ul{
            list-style-type: none;
        }
    
        a{
            text-decoration: none;
        }
    
        #top-bar{
            top: 0;
            position: fixed;
            background-color: var(--background);
            width: 100%;
            height: 80px;
        }
    
        .container{
            max-width: 1200px;
            margin: 0 auto;
            
            height: 100%;
        }
    
        .list{
            display: flex;
            justify-content: center;
            height: 80px;
        }
    
        .list ul{
            position: absolute;
            top: 100%;
        }
        
        .anan {
            margin-top: 160px;
        }
<!DOCTYPE html>
<html lang="tr" dir="ltr">

<head>
    <meta charset="utf-8">
    <title>Nav-Bar</title>
    <link rel="stylesheet" href="main.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css" integrity="sha512-+4zCK9k+qNFUR5X+cKL9EIR+ZOhtIloNl9GIKS57V1MyNsYpYcUrUeQc9vNfzsWfV28IaLL3i96P9sdNyeRssA==" crossorigin="anonymous" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    
</head>

<body>
<nav id="top-bar">
    <div class="container">
        <div class="list">
            <h1 class="logo">Logo</h1>
            <ul>
                <li><a href="">Home</a></li>
                <li><a href="">About</a></li>
                <li><a href="">Blog</a></li>
                <li><a href="">Contact</a></li>
            </ul>
        </div>
    </div>
</nav>
<div class="anan">
    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
</body>

</html>

Problem :

when I do “position: fixed”, the new sections or sections that I open below do not automatically come to the bottom line and start from the top of the page. Top-bar has to start directly below. Also, the article I wrote looks like I did not give background color directly. What is the reason for this transparency? How can I solve these two problems?

Thanks in advance for your answers.

*{
  padding: 0px;
  margin: 0px;
  box-sizing: border-box;
}

:root{
  --background: rgba(85, 214, 170, .85);
}

html{
  font-family: sans-serif;
}

ul{
  list-style-type: none;
}

a{
  text-decoration: none;
}

#top-bar{
  position: fixed;
  background-color: var(--background);
  width: 100%;
  height: 80px;
}

.container{
  max-width: 1200px;
  margin: 0 auto;
  height: 100%;
}

.list{
  display: flex;
  justify-content: center;
}

.list ul{
  position: absolute;
  top: 100%;
}
<!DOCTYPE html>
<html lang="tr" dir="ltr">

<head>
  <meta charset="utf-8">
  <title>Nav-Bar</title>
  <link rel="stylesheet" href="main.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css" integrity="sha512-+4zCK9k+qNFUR5X+cKL9EIR+ZOhtIloNl9GIKS57V1MyNsYpYcUrUeQc9vNfzsWfV28IaLL3i96P9sdNyeRssA==" crossorigin="anonymous" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>

<body>
 <nav id="top-bar">
   <div class="container">
   <div class="list">
     <h1 class="logo">Logo</h1>
     <ul>
       <li><a href="">Home</a></li>
       <li><a href="">About</a></li>
       <li><a href="">Blog</a></li>
       <li><a href="">Contact</a></li>
     </ul>
   </div>
   </div>
 </nav>
 <div class="anan">
  Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
 </div>
</body>

</html>

Comments

Comment posted by tacoshy

your backgroudn color is:

Comment posted by tacoshy

what is the actual design you trying to achieve. can you make a drawing of it? I find it quite difficault to understand what you trying to achieve with the intended behavior. Most issues you have are caused by fixed and absoltue positioning to the body without margins or relative position to counter the collision it will cause.

Comment posted by OyeeBerkay

Thanks, but after that I will not have to do this calculation again in the new divs I added under the “anan” div, right?

Comment posted by tacoshy

no you wont. However it would be better to change you code slightly to not have any caclulations needed in the first place.

By