A visual element positioned centrally within a row, directly beneath a paragraph tag

Every solution I attempt fails to work correctly, at times I achieve centering the image but then the figcaption ends up crammed into a small 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">  Building a JavaScript first person shooter game from scratch </h3>
        <a>   <!--  I need this anchor tag   -->
            <p style = "text-decoration: none;">
                example text  hyhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhjgjgjgkgflkuyfkutdytfkgflhblblhlijhhyhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhjgjgjgkgflkuyfkutdytfkgflhblblhlijh
            </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 attempted changing my row class to:

<div class = "row custom-row justify-content-md-center">

But it has made no difference.

I've also tried using .text-center and .img-center like this:

<figure class="text-center"> 
    <img id = "fps" class="img-center"...

This approach also proves ineffective

How can I successfully center this image?

Answer №1

Consider utilizing the flex center properties within the figure element:

display: flex;
align-items: center;
justify-content: center;
flex-direction: column;

Alternatively, you can use the CSS flex classes provided by Bootstrap:

d-flex flex-column align-items-center justify-content-center

https://getbootstrap.com/docs/5.3/utilities/flex/#enable-flex-behaviors

Check out the Fiddle:

.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%;
}
<!-- Include Bootstrap CDN https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d5b7babaa1a6a1a7b4a595e0fbe6fbe4">[email protected]</a>/dist/css/bootstrap.min.css -->

<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="33515c5c47404741524373061d001d02">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row custom-row">
  <h3 style="text-align: center"> A first person shooter in JavaScript from scratch </h3>
  <a>
    <!-- This is the needed a tag   -->
    <p style="text-decoration: none;">
      Example text here
    </p>
    <figure class="d-flex flex-column align-items-center justify-content-center">
      <img id="fps" src="../static/fps.png" />
      <figcaption style="text-decoration: none; color: inherit; display: table-caption; caption-side: bottom ;">
        My updated figcaption text
      </figcaption>
    </figure>
  </a>
</div>

Answer №2

If you want to remove certain styles from figcaption, simply delete the following CSS properties:

    display: table-caption;
    caption-side: bottom;

Instead, apply the following style to the figure tag:

text-align: center;

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Vertical centering of inline-block elements remains unaffected by line-height changes

I attempted to center an inline-block vertically in the following manner: div { width: 50px; height: 50px; background: red; line-height: 50px; } span { display: inline-block; width: 20px; height: 20px; background: white; } <div> ...

The addEventListener feature in Bootstrap 5.2.3 seems to be malfunctioning

I have a sample page with a Bootstrap dialog being returned from the server. I want to display it inside a DIV. However, when clicked, I receive this error: Uncaught TypeError: myModal.addEventListener is not a function It points to this line of code: ...

Having trouble with the alignment of CSS menu in Safari?

Can someone please assist me with a strange issue I am experiencing on my website? The menu appears misaligned when using Safari, and it's been driving me crazy. I've tried troubleshooting for hours without success. Here is a link to the site: I ...

Arranging Bootstrap dropdown and buttons on a single line

Check out my code snippet here: http://jsfiddle.net/52VtD/7462/ I'm facing an issue where I want to align my dropdown and buttons on the same line, but the dropdown being a div, it stays on the line below. How can I ensure they are on the same line? ...

Personalized hover effect using CSS on Caldera Forms

Struggling to customize the CSS style of my Caldera forms on a WordPress site. My goal is to add a hover effect to the radio checklist fields. Currently, I've only managed to style the bullets and need help adding a hover effect to the fields themselv ...

Can someone provide assistance on how to add an icon to a button?

Help needed with adding icons to buttons! I am new to coding and struggling with adding icons to each button. If any classes need to be changed, please let me know. I am currently learning HTML and CSS and could use some guidance. Thank you! Example: ...

implementing jquery typewriter plug-in for a responsive bootstrap image

I am using Bootstrap and my image response dynamically, but I am having trouble adding text to it. I would like to use a jQuery typewriter plugin for the text on the image, which should resize according to screen size. Here is my HTML code and I have used ...

Adding a line and text as a label to a rectangle in D3: A step-by-step guide

My current bar graph displays values for A, B, and C that fluctuate slightly in the data but follow a consistent trend, all being out of 100. https://i.stack.imgur.com/V8AWQ.png I'm facing issues adding lines with text to the center of each graph. A ...

Customizing Material-UI elements in React using CSS styling

My goal is to style all the <Chip> elements within a <Grid> that has the class .table-header, but they are not changing their style (I have a <p> that should be colored in red and it works). Why does the styling work for the <p> ele ...

I have noticed that the share buttons on Sharethis.com only show up after I resize the viewport

After integrating share buttons from Sharethis.com, I noticed that they do not appear when the page is refreshed. However, when I resize the viewport, they suddenly show up. <!DOCTYPE html> <html lang="en"> <head> <script t ...

Create a focal point by placing an image in the center of a frame

How can an image be placed and styled within a div of arbitrary aspect ratio to ensure it is inscribed and centered, while maintaining its position when the frame is scaled? Ensure the image is both inscribed and centered Set dimensions and position usin ...

Difficulty with font rendering across different web browsers such as Firefox, Chrome, and Opera

Visit the following website: I have implemented font-face on my site: @font-face { font-family: 'SegoeUI'; src: url('{site_url}themes/site_themes/agile_records/fonts/segoeui.eot?') format('eot'), url(' ...

Is it possible for me to create a menu using the .row and .col classes from Bootstrap?

I attempted to create a menu using Bootstrap's cols. Something similar to this: https://i.stack.imgur.com/55xst.png However, I faced numerous challenges when trying to implement it into Wordpress and realized that it may not be the best approach... ...

Stylesheet specific to Internet Explorer not loading

My Rails application (link) is experiencing display bugs in Internet Explorer. I am trying to fix these bugs by making changes in the app/views/layouts/application.html.haml file where I have included: /[if IE] ...

What determines the root element of the CSSOM (CSS Object Model)?

As I dive into my research on browser rendering, I've reached the stage in the rendering process where the browser creates the CSSOM from raw CSS. In many tutorials I've encountered, the authors confidently state that the body element is the roo ...

Guide to crafting a flawless pixel-perfect separator with CSS borders

I have a menu with a black background and a submenu with a grey background. Now, I want to add a pixel-perfect divider between them. However, I'm unsure of which border color to use in order to achieve this perfection. Can anyone provide some guidan ...

JavaScript Animation of Text

I have a challenge where I want to animate text's opacity in JavaScript after the user presses enter. However, I am struggling to achieve this with my current code. I can provide all of my code for you to review and help me understand why the animatio ...

Prevent a HTML button from being clicked multiple times before it disappears (using Django)

I am currently working on a Django project that involves events where users can join by adding their user_id and event_id to the attend model. On the event page, there is a join button form that, when clicked, adds the user to the attendees list. After cli ...

Font icon not appearing when toggling the class "before"

I am attempting to utilize two classes, both with a :before pseudo-element. When the target class is hovered over, the two classes swap. This functionality works correctly in Safari, but in other browsers, the icon at the bottom does not display properly. ...

accordions that are supposed to adapt to different screen sizes are

My custom responsive accordions are not functioning as expected. The requirement is to display headings and content for desktop view, but switch to accordions on smaller devices. I have managed to do this, however, when resizing the window, the functionali ...