Nothing I try seems to work properly, sometimes I can center the image but the the figcaption then squeezes itself into a tiny corner.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/5.4.1/css/bootstrap.min.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.custom-row {
background: linear-gradient(to bottom, #f8efef, #f7faf8);
padding:10px;
border-radius: 15px;
padding-left: 10%;
padding-right: 10%;
margin-left: 0;
margin-right: 0;
position: relative;
left:0%;
}
#fps{width:60%; }
</style>
</head>
<body>
<div class = "row custom-row">
<h3 style = "text-align: center"> A first person shooter in JavaScript from scratch </h3>
<a> <!-- i need this a tag -->
<p style = "text-decoration: none;">
example text hyhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhjgjgjgkgfkluyfkutdytfkgflhblblhlijhhyhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhjgjgjgkgfkluyfkutdytfkgflhblblhlijh
</p>
<figure>
<img id = "fps" src = "../static/fps.png"/>
<figcaption style = "text-decoration: none; color: inherit; display: table-caption; caption-side: bottom ;">
my figcaption text
</figcaption>
</figure>
</a>
</div>
</body>
</html>
I’ve also tried having my row class like:
<div class = "row custom-row justify-content-md-center">
It doesn’t seem to change a thing.
I’ve also tried .text-center and . img-centre like this:
<figure class="text-center">
<img id = "fps" class="img-center"...
This also does nothing
How can I have this image centered nicely?
2
Answers
Try to use flex center properties over figure element:
Or css flex classes of bootstrap:
https://getbootstrap.com/docs/5.3/utilities/flex/#enable-flex-behaviors
Fiddle:
You can delete these styles in
figcaption
and give
figure
tag style