Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (20.3k points)

I'm having a problem centering an element that has the attribute position set to absolute. Does anyone know why the images are not centered?

body {

  text-align: center;

}

#slideshowWrapper {

  margin-top: 50px;

  text-align: center;

}

ul#slideshow {

  list-style: none;

  position: relative;

  margin: auto;

}

ul#slideshow li {

  position: absolute;

}

ul#slideshow li img {

  border: 1px solid #ccc;

  padding: 4px;

  height: 450px;

}

<body>

  <div id="slideshowWrapper">

    <ul id="slideshow">

      <li><img src="img/dummy1.JPG" alt="Dummy 1" /></li>

      <li><img src="img/piano_unlicened.JPG" alt="Dummy 2" /></li>

    </ul>

  </div>

</body>

1 Answer

0 votes
by (40.7k points)

Try using the code given below:

position: absolute;

margin-left: auto;

margin-right: auto;

left: 0;

right: 0;

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...