skip to Main Content

I want to have control over a div when I make it absolute

I tried making it left 30% right 30% then I gave top a particular pixel when it get to where I want to be it becomes squished what should I do because I want to give it a max-width

2

Answers


  1.   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.
    
    Login or Signup to reply.
  2. To center this div horizontally, try this:

    position: absolute;
    margin: 0 auto;
    top:100px //or whatever;
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search