For some strange reason, centering divs using margin: 0 auto does not work. My code is:
HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Picture Gallery</title>
<link rel="stylesheet" href="css/week7.css">
</head>
<body>
<h1>The Mighty Avengers</h1>
<div class="slide1">
<img src="images/hawkeye.jpg" alt="Hawkeye" />
<img src="images/capmar.jpg" alt="Captain Marvel" />
<img src="images/beast.gif" alt="Beast" />
<img src="images/thor.jpg" alt="Thor" />
</div>
<div class="slide2">
<img src="images/cap.jpg" alt="Captain America" />
<img src="images/ant.jpg" alt="Ant Man" />
<img src="images/vision.jpg" alt="The Vision" />
<img src="images/scar.jpg" alt="Scarlet Witch" />
</div>
</body>
</html>
and CSS:
html {
background-color: gray;
}
h1 {
text-align: center;
}
img {
height: 250px;
margin-left: -20px;
width: 250px;
}
.slide1, .slide2 {
display: block;
margin: 0 auto;
width: 85%;
}
None of the other instances of this type of centering that Stack talked about helped. I tried this with and without the type of mapping set to classes, to no avail. Any understanding of this would be appreciated.
source
share