# Position fixed question?

**URL:** <https://forum.freecodecamp.org/t/position-fixed-question/335128>\
**Category:** General\
**Created:** [December 22, 2019, 2:57pm UTC](https://forum.freecodecamp.org/t/position-fixed-question/335128 "2019-12-22T14:57:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bego96](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/bego96/32/73440_2.png) [@Bego96](https://forum.freecodecamp.org/u/Bego96)\
**Post date:** [December 22, 2019, 2:57pm UTC](https://forum.freecodecamp.org/t/position-fixed-question/335128/1 "2019-12-22T14:57:37Z")

</div>

Im testing around with position fixed. I havent used HTML and CSS for a while because i was doing other things and being focused on UX UI lately. I set my boxes to be all 60% of width while centered with margin 0 auto. I have given each box its own class box1, box2 etc… then on box1 i put position: fixed, later when i move the box over the other boxes i noticed that box1 with given position of fixed now has bigger width than other boxes even though they have all the same width of 60%. Can someone explain this to me? I used 500px instead of 60% later, and width was the same again but not when i use % instead of px. Why is this?

**As you can see Box1 is a bit bigger in width when given position fixed**

 ![Screenshot_1](https://global.discourse-cdn.com/freecodecamp/original/3X/1/d/1daeab88e4c8aa66e7cab41c965ca9a5723e84fe.jpeg)

Here is code:  
**HTML** :

```auto
<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta charset="utf-8">
        <link rel="stylesheet" href="style.css" type="text/css">
    </head>
    <body>
        
        <h1>HTML and CSS termin 6</h1>
        
        <div class="wrapper">
            
            <div class="box box1">
                <p>Ovo je Box 1</p>
            </div>
            
            <div class="box box2">
                <p>Ovo je Box 2</p>
            </div>
            
            <div class="box box3">
                <p>Ovo je Box 3</p>
            </div>
            
            <div class="box box4">
                <p>Ovo je Box 4</p>
            </div>

        </div>
        
        <div class="footer"></div>
        
    </body>

</html>

```

**CSS** :

```auto
body {
    padding: 0;
    margin: 0;
}

h1 {
    background-color: aqua;
    text-align: center;
    padding: 10px;
    font-size: 3em;
    margin: 0;
}

.wrapper {
    background-color: #ccc;
    padding-right: 20px;
    padding-left: 20px;
}

.box {
    width: 60%;
    padding: 60px;
    margin: 0 auto;
}

p {
    font-size: 2em;
    text-align: center;
    font-weight: bold;
    color: #fff;
}

.box1 {
    background-color: blue;
    position: fixed;
    left: 17%;
}

.box2 {
    background-color: red;
}

.box3 {
    background-color: orange;
}

.box4 {
    background-color: green;
}

.footer {
    background-color: #bbb;
    padding: 90px;
}

```

---

<div class="post-metadata">

**Author:** ![snigo](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/snigo/32/128765_2.png) [@snigo](https://forum.freecodecamp.org/u/snigo)\
**Post date:** [December 22, 2019, 3:39pm UTC](https://forum.freecodecamp.org/t/position-fixed-question/335128/2 "2019-12-22T15:39:41Z")

</div>

You cannot do `margin: 0 auto;` trick for out-of-flow boxes, that’s true, you need to use this instead:

```auto
...
left: 50%;
transform: translateX(-50%);
...

```

---

<div class="post-metadata">

**Author:** ![Bego96](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/bego96/32/73440_2.png) [@Bego96](https://forum.freecodecamp.org/u/Bego96)\
**Post date:** [December 22, 2019, 7:19pm UTC](https://forum.freecodecamp.org/t/position-fixed-question/335128/3 "2019-12-22T19:19:31Z")

</div>

That doesnt fix strange width change!

EDIT: I removed paddings from wrapper and its better now. Idk why lol

---

<div class="post-metadata">

**Author:** ![snigo](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/snigo/32/128765_2.png) [@snigo](https://forum.freecodecamp.org/u/snigo)\
**Post date:** [December 22, 2019, 8:14pm UTC](https://forum.freecodecamp.org/t/position-fixed-question/335128/4 "2019-12-22T20:14:31Z")

</div>

That was because boxes except `box1` were in document flow and wrapper padding settings was affecting them. You can fix it with box sizing reset:

```auto
* {
  box-sizing: border-box;
}

```

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 16, 2021, 11:29am UTC](https://forum.freecodecamp.org/t/position-fixed-question/335128/5 "2021-01-16T11:29:44Z")

</div>

Closed on January 16, 2021, 11:29am UTC


