如何将绝对div居中

问题描述 投票:0回答:1

当我将其设置为绝对时,我想控制它

我尝试让它向左30%向右30%,然后我给了顶部一个特定的像素,当它到达我想要的位置时,它被压扁了我应该做什么,因为我想给它一个最大宽度

html css position tailwind-css
1个回答
0
投票
  position: absolute;
  left: 0;
  right: 0;
  margin: auto;
  top: 100px; /* Adjust the top position as needed */
  max-width: 500px; /* Adjust the maximum width as needed */
}```

This will center the absolute div horizontally within its container and give it a maximum width, preventing it from becoming squished when the viewport width changes. You can adjust the values for top and max-width to suit your design requirements.
© www.soinside.com 2019 - 2024. All rights reserved.