0

demo of the main problem with header

Here's a link to the sandbox because I couldn't get the code in here CODEPEN

Hello, I have tried absolutely everything but the header still sticks to the screen when the page is compressed please help

If I add margin site just breaks because the header extends beyond

enter image description here

.body {
  font-family: Inter, sans-serif;
  margin: 0;
  padding: 0;
}

.header {
  background-color: var(--color-light);
  border-radius: 28px;
  box-sizing: border-box;
  padding: 20px;
  position: absolute;
  z-index: 1;
  width: 100%;
  top: 50px;
  left: 0;
  right: 0;
  margin: 0 auto;
}

.header__nav {
  display: flex;
}

.header__list {
  display: flex;
  align-items: center;
  list-style: none;
  margin: 0;
  padding: 0;
}

.header__link {
  text-decoration: none;
  font-style: normal;
  font-weight: 400;
  font-size: 16px;
  line-height: 22px;
  color: var(--color-dark);
  transition: color 0.2s linear;
}

.header__link:hover {
  color: var(--color-main);
}

.header__item:not(:last-child) {
  margin: 0 40px 0 0;
}

.header__item:last-child {
  margin: 0;
}

.header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  padding: 15px;
  border-radius: 16px;
  font-style: normal;
  font-weight: 600;
  font-size: 16px;
  line-height: 22px;
  cursor: pointer;
  box-sizing: border-box;
  font-family: "Inter", sans-serif;
}

.btn_type_bg-none {
  border: 2px solid var(--color-light);
  color: var(--color-light);
  transition: background-color 0.1s linear;
}

.btn_type_bg-none:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

.btn_color_purple {
  background-color: var(--color-main);
  color: var(--color-light);
  transition: background-color 0.1s linear;
}

.btn_color_purple:hover {
  background-color: #665dac;
}

.btn_color_light {
  background-color: var(--color-light);
  color: var(--color-main);
  transition: background-color 0.1s linear;
}

.btn_color_light:hover {
  background-color: rgb(240, 240, 240);
}

.container {
  max-width: 1230px;
  padding: 0 15px;
  margin: 0 auto;
  box-sizing: border-box;
}

.hero {
  height: 100vh;
  background-color: var(--color-main);
  border-radius: 0 0 52px 52px;
  padding: 230px 0 0 0;
}

.hero__title {
  width: 100%;
  font-style: normal;
  font-weight: 700;
  font-size: 75px;
  line-height: 105.02%;
  color: var(--color-light);
  margin: 0 0 35px 0;
}

.hero__text {
  display: flex;
  flex-direction: column;
  max-width: 613px;
  width: 100%;
}

.hero__subtitle {
  font-style: normal;
  font-weight: 400;
  font-size: 20px;
  line-height: 24px;
  color: var(--color-light);
  margin: 0 0 50px 0;
}

.hero__parthners {
  padding: 0 0 50px 0;
}

.hero__left {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.hero__inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 0 0 100px 0;
}

.hero__image {
  display: block;
  width: 100%;
  height: auto;
  max-width: 400px;
  object-fit: cover;
  object-position: center;
}

.hero__btns {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  justify-items: stretch;
  align-items: center;
  width: 60%;
  gap: 30px;
}

.hero__bottom-img-container {
  background-color: hsla(0, 0%, 100%, 0.3);
  max-width: 1200px;
  width: 100%;
  box-sizing: border-box;
  height: auto;
  border-radius: 28px;
  margin: 70px auto 150px auto;
  padding: 20px;
}

.hero__bottom-img {
  width: 100%;
  display: block;
  object-fit: cover;
}

.modal-signup {
  opacity: 0;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 500px;
  min-height: 600px;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(1.5);
  z-index: 999;
  text-align: center;
  background: linear-gradient(169.29deg, #f8f4f0 7.95%, #ffffff 99.86%);
  border-radius: 20px;
  transition: opacity 300ms ease-in-out, transform 300ms ease-in-out;
  pointer-events: none;
  cursor: default;
}

.reset-weight {
  font-weight: 400;
}

 :root {
  --color-main: #8578e6;
  --color-light: #fff;
  --color-dark: #32313b;
  --color-pink: #f48eba;
}

.header__container {
  position: relative;
  max-width: 1200px;
  padding: 0 15px;
  width: 100%;
}
<div class="container header__container">
  <header class="header">
    <div class="header__inner">
      <a href="" class="logo logo_position_header">
        <img src="images/logo.svg" alt="tines logo" class="logo__image" />
      </a>
      <nav class="header__nav">
        <ul class="header__list">
          <li class="header__item">
            <a href="#" class="header__link">Products</a>
          </li>
          <li class="header__item">
            <a href="#" class="header__link">Use cases</a>
          </li>
          <li class="header__item">
            <a href="#" class="header__link">Resources</a>
          </li>
          <li class="header__item">
            <a href="#" class="header__link">Company</a>
          </li>
          <li class="header__item">
            <a href="#" class="header__link">Pricing</a>
          </li>
        </ul>
      </nav>
      <button class="btn btn__modal-open btn_color_purple" data-modal="1">Sign up for free</button>
    </div>
  </header>
</div>
Pete
  • 57,112
  • 28
  • 117
  • 166
Flain
  • 7
  • 1
  • The question isn't actually a duplicate of what it has been closed for. This problem is to do with having `width` and `max-width` values that don't work together, namely have a 100% width value used with `max-width`. Hence the container taking up 100% below 1200px which is the problem at hand. I've covered this in my answer. – paulo77 May 31 '22 at 13:26
  • @Emmy OP is wanting 15px padding of parent container so it is a duplicate and has nothing to do with the max width - the title of the questions are even nearly identical – Pete May 31 '22 at 13:36
  • They aren't tho. They want the header to have space from the parent instead of sticking to 100% of the window size. Like all such issues there would potentially be a fix on that with padding, but this issue is the header taking up 100% of the screen below a certain screen size, which in this case is due to the width property. In fairness, I'm sure that question has been asked a 1000 time as well :) – paulo77 May 31 '22 at 13:39

2 Answers2

1

Try removing the width and change the left and right value.

.header {
    background-color: var(--color-light);
    border-radius: 28px;
    box-sizing: border-box;
    padding: 20px;
    position: absolute;
    z-index: 1;
    top: 50px;
    left: 15px;
    right: 15px;
    margin: 0 auto;
}
sumeshsn1
  • 756
  • 5
  • 13
0

You need to change the width: 100% property on .header__container down to a value below 100%. Although it has a max-width: 1200px value, once it goes below 1200px it will just then stay at 100% of the size of the parent container.

You could do width: 90% to add some space or a calculated value such as width: calc(100% - 2rem)

Codepen link https://codepen.io/thechewy/pen/zYRWmQr?editors=1100

paulo77
  • 174
  • 14
  • 1
    I spent all day, without exaggeration, solving this problem! The solution with the calc function works as I need it thank you very much!!! – Flain May 31 '22 at 19:27