# Displaced user-card, need some help with CSS

**URL:** https://meta.discourse.org/t/displaced-user-card-need-some-help-with-css/95006
**Category:** Support
**Created:** [August 17, 2018, 4:01pm UTC](https://meta.discourse.org/t/displaced-user-card-need-some-help-with-css/95006 "2018-08-17T16:01:44Z")
**Posts on this page:** 1
**Showing post:** 6

<div class="post-metadata">

### Author: ![Johani](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/johani/32/176920_2.png) [@Johani](https://meta.discourse.org/u/Johani)
#### Post date: [August 18, 2018, 1:26pm UTC](https://meta.discourse.org/t/displaced-user-card-need-some-help-with-css/95006/6 "2018-08-18T13:26:02Z")

</div>

First a bit about `position: absolute`

> The element is removed from the normal document flow, and no space is created for the element in the page layout. It is positioned relative to its closest positioned ancestor, if any; otherwise, it is placed relative to the initial [containing block](https://developer.mozilla.org/en-US/docs/Web/CSS/All_About_The_Containing_Block). Its final position is determined by the values of `top` , `right` , `bottom` , and `left` .

[read more](https://developer.mozilla.org/en-US/docs/Web/CSS/position#absolute)

User-cards, group-cards and a few other elements in Discourse have `position: absolute` with the nearest positioned ancestor for them - in the case of native Discourse UI - being `#main` which by default has

```plaintext
#main {
  position: relative
}

```

One key difference about them is that the `top` and `left` values are set dynamically with JS - so that they show up where they are supposed to show up.

Examples:

Your user-card has these values

 ![%60](https://global.discourse-cdn.com/meta/original/3X/1/3/131a69d879e1886f39e334839748f4baeb7b9ef3.png)

and the user-card for the avatar right below yours has these values

 ![2](https://global.discourse-cdn.com/meta/original/3X/3/7/3714977ba2cadab9176e1d2820e4e7463e09e021.png)

Note the higher `top` value since the second one is lower.

As I mentioned above, these value are relative to the nearest positioned ancestor - `#main`

So in the case of your use-card it would be

~341px from the top of `#main` and ~1490px from its left side.

The `#main` element in Discourse extends the full width of the screen.

 ![4](https://global.discourse-cdn.com/meta/original/3X/d/f/df32a054bc477a91180e850c0f64de036ec2c526.png)

Your theme changes that to add a visual effect. But you also use `margin: 0 auto` on it to centre it.

Something like this

```plaintext
#main {
  width: 1110px;
}

```

Which creates this

 ![3](https://global.discourse-cdn.com/meta/original/3X/d/6/d630161a07c8770756c14e5eec78206463d362ce.png)

and you fixed it by using

```plaintext
#main {
  margin: 0 auto;
}

```

which creates this

 ![5](https://global.discourse-cdn.com/meta/original/3X/6/a/6ac1920d244fe730604eb3899d3b7dcb2b15389d.png)

however, this fix is not registered by the JS that calculates the `top` and `left` values for user-cards, group-cards etc. It assumes the `#main` element starts here

 ![6](https://global.discourse-cdn.com/meta/original/3X/7/6/76579be309304d0bf75cc91194cdfc097f55c9ef.png)

and so the values are based on that… and so going back to your use-card

`left: 1490px`

is based on that, however, it is still relative to `#main` and so when you pushed `#main` to the center with

```plaintext
#main {
  margin: 0 auto;
}

```

You’re also pushing user-cards and other similar elements by the same amount because the JS that calculates their position is not aware of your change.

And so you get this

 ![7](https://global.discourse-cdn.com/meta/original/3X/d/4/d4b5a3c28e3da564483cda4bbfbb828322bafe13.png)

The CSS in my post above

```plaintext
#main {
  position: static;
}

```

Makes it so that `#main` is no longer positioned. So going back to the `position: absolute`

> otherwise, it is placed relative to the initial [containing block](https://developer.mozilla.org/en-US/docs/Web/CSS/All_About_The_Containing_Block).

The containing block here is the `body` element and its left side is here

 ![6](https://global.discourse-cdn.com/meta/original/3X/7/6/76579be309304d0bf75cc91194cdfc097f55c9ef.png)

and so the JS values for `top` and `left` are accurate again and order is restored to the universe.

---

_[View the full topic](https://meta.discourse.org/t/displaced-user-card-need-some-help-with-css/95006)._
