简体   繁体   中英

How should I center the fixed position element occupied by translateX?

I want an HTML element centered horizontally, example:

.u-message {
    position fixed
    left 50%
    //transform: translateX(-50%); //but css animate occupy translateX, so i cant's use transform attribute,
    //margin-left: xxxpx;  //and I dont't sure how long of the HTML element width,so I cant's use it too.
}

What can I do ?

Try using flex box

.u-message {
  display: flex;
  align-items: center;
  justify-content: center;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM