Tips for Aligning Several Images Horizontally in an Article

Does anyone know how to center pictures in an article horizontally? I've tried various techniques without success.

If it would be helpful, I can share the CSS I currently have. However, I am open to starting from scratch with the CSS as well since I am working from a Dreamweaver template.

https://i.stack.imgur.com/ZcSsm.png

<article class="fluid gallery">
<h2 class="fluid showAreaH2 headingStyle">Edutech Personal del Portador</h2>
<figure class="fluid tiles zeroMargin_desktop zeroMargin_tablet"> <img src="images/mauricio.jpg" alt="Maricio"/>
  <figcaption class="textStyle">Mauricio y Rosalía Sánchez</figcaption>
</figure>
<figure class="fluid tiles"> <img src="images/guillermo.jpg" alt="Guillermo y Sarit"/>
  <figcaption class="textStyle">Guillermo y Sarit Llanos</figcaption>
</figure>

Answer №1

section.media-responsive.gallery {
  align-content: center;
}

Answer №2

Flexbox is a great solution when you need to center content horizontally. Just set the display property to flex, and use justify-content:center. Keep in mind that older browsers may require vendor prefixes.

section {
  width:100%;
  display:flex;
  justify-content:center;
}
img {
  padding:1em;
}
<section>
  <img src="http://placehold.it/50x50">
  <img src="http://placehold.it/50x50">
</section>

Answer №3

To ensure that your pictures are centered within a document, you can enclose them in a specific div like this:

<div class="image-container">
   <img src="..." alt="...">
   ...
</div>

Don't forget to apply the following CSS to style the image container:

.image-container { text-align: center; }

This way, you can easily align your images with the rest of the content on your page.

Answer №4

If you're looking to horizontally center images on your website, here's a suggestion that might help. It shouldn't be too difficult to implement.

My advice would be to create a container element for the images you want to center horizontally. Then, set those images or their container elements to have a display: inline-block; style.

.gallery {
  text-align: center;
}
.img-container {
  display: inline-block;
}
<div class="gallery">
  <div class="img-container">
    <img src="http://placehold.it/100x50">
    <p>
      Caption
    </p>
  </div>
  <div class="img-container">
    <img src="http://placehold.it/100x50">
    <p>
      Caption
    </p>
  </div>
  <div class="img-container">
    <img src="http://placehold.it/100x50">
    <p>
      Caption
    </p>
  </div>
</div>

Check out the demo on JSFiddle.

Answer №5

(Revised response)

Enclose both pictures in a container and align the content within it:

<article class="fluid gallery">
    <h2 class="fluid showAreaH2 headingStyle">Edutech Personal del Portador</h2>
    <div class="wrapper1">
      <figure class="fluid tiles zeroMargin_desktop zeroMargin_tablet"> <img src="images/mauricio.jpg" alt="Maricio"/>
        <figcaption class="textStyle">Mauricio y Rosalía Sánchez</figcaption>
      </figure>
      <figure class="fluid tiles"> <img src="images/guillermo.jpg" alt="Guillermo y Sarit"/>
        <figcaption class="textStyle">Guillermo y Sarit Llanos</figcaption>
      </figure>
    </div>
    <!-- additional text? -->
</article>

CSS:

.wrapper1 {
  width: 100%;
  text-align: center;
}

Answer №6

I concur with Arathi Sreekumar's suggestion. In addition, it is important to include the following CSS code:

.figure-wrapper figure { display: inline-block; }

You may also consider including padding for the .figure-wrapper figure element.

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

Occasions focused on the <input type="file"> feature

Looking for a way to write a file input in React that accepts CSV files, validates them, and prevents upload if there are errors? Check out the code snippet below: <CustomInput type="file" id="fileBrowser" name="file" label={filename || 'Choos ...

Issues with $.post function causing HTML to be displayed instead of the intended value

I have a question about sending the value of an HTML element to the server using POST. When I alert the result, I expect to only see the value but I am also getting the HTML content of the PHP file included in my code. Why is this happening? function post ...

Modify the navbar background color in bootstrap-vuejs

As per the information provided in the documentation, the instructions for setting styles for the navigation bar are as follows: <b-navbar toggleable="lg" type="dark" variant="info"> <!-- Or --> <b-navbar toggleable="lg" type="dark" variant ...

The functionality of Flatbutton(Input handler) appears to be malfunctioning

I am having trouble with the file uploader from Material-UI. It doesn't seem to be working properly when I try to select a file. Does anyone have any suggestions on how to handle the input from the file selector? <FlatButton icon={< ...

How to load a URL into a div using jQuery and then update the div with new content?

I have a codeigniter view that I want to load into a div as an iframe using the following code: <script type='text/javascript'> $(document).ready(function (){ $('#divId').load('http://www.domain.oo/page.php?test=1); }); ...

Enclose each set of objects, such as text, within a separate div, except for div elements

Is there a way to wrap each immediate group of objects that are not contained in a div with a wrap class? Input: var $code = 'Lorem Ipsum <p>Foo Bar</p> <div class="myclass"></div> <p>Foo Bar</p> <div clas ...

When scrolling, use the .scrollTop() function which includes a conditional statement that

As a newcomer to jQuery, I've been making progress but have hit a roadblock with this code: $(window).scroll(function(){ var $header = $('#header'); var $st = $(this).scrollTop(); console.log($st); if ($st < 250) { ...

Using AJAX to update content based on selected value in a dropdown menu

My challenge lies in ensuring that a select box retains the selected value from a database entry and triggers an onchange event during form editing or updating. While I have successfully populated the data in the select box based on other selections, I a ...

Tips for adjusting the value of a textbox up and down

I am facing an issue with my booking flight form that is supposed to take input from users regarding the number of travelers. I have three textboxes for Adult, Children, and Infants respectively, along with a main textbox to display the final result. Howev ...

Adjusting the size of the post title's font

Looking to decrease the font size of the latest post's title and keep it centered on my Jekyll based blog. I attempted to adjust https://github.com/x0v/x0v.github.io/blob/master/_sass/atoms/_feature-title.scss by adding font-size: 45px !important; f ...

Troubleshooting CSS Issues in ASP.NET Boilerplate

I am attempting to apply a CSS style to a text input similar to the one found on the CreateUser default page. However, I am encountering an issue where the blue line under the textbox does not appear when I navigate away from and then return to the page. ...

The process of eliminating body padding in Nuxt.js

I'm considering building a website using Nuxt.js because I've heard it's both cool and user-friendly. While I do have some knowledge of vue.js, I'm stuck on a particular issue: How can I remove the padding from the body? I understand ...

Unlock the Full Potential: Enabling Javascript's Superpowers through PHP Execution

I specialize in PHP and JavaScript. Currently, I am attempting to incorporate JavaScript functionalities into my PHP code. However, I am encountering an issue where the code is not functioning properly. The PHP code that executes the JavaScript code is as ...

PHP table not displaying data

I am brand new to this and currently enrolled in a class with an unhelpful professor. I am attempting to read data from a file into a table, but for some reason the data is not displaying. I have tried multiple approaches, but I am feeling quite lost. Any ...

What is the best way to showcase an image that is being retrieved from PHP using ajax?

I need to show the image that is being received from PHP via ajax. I can display the name <span id="pic_name">Pic name here</span> but how can I display the image as <img src="images/pic/picname" /> //alert(a); $.ajax({ ...

Ways to boost CSS transform with GPU acceleration

Is there a way to ensure smooth animations by utilizing GPU acceleration for CSS transforms in browsers? When does this acceleration occur and how can it be forced? For more information, check out this article ...

Troubleshoot: Unable to trigger change event for input type file

Hey, I'm trying to capture and display the file name that a user selects using an input type file control. Unfortunately, the jQuery onchange event doesn't seem to be working in IE 8. Does anyone have a solution for this? // Here's my jQuer ...

Resize images in PHP and MySQL with precision without distorting the image

I'm looking for a solution to resize images on upload without deforming them. The current code uploads the image and stores it in the database, but I need to add resizing functionality. I'd prefer not to use JavaScript, but if necessary, please i ...

Issue with ellipsis not functioning correctly on dynamic placeholders when they are in focus

When I focus on my dynamic placeholder input, the text-overflow: ellipsis property is lost for some reason. However, it is regained when blurred. Can anyone explain why this is happening? If you want to experiment with it, I have set up a stackblitz: htt ...

Challenges with form validation

Hello everyone, I'm a newbie to JS and struggling with my code. It seems like everything should work, but it just won't. The issue seems to be with the phone number form validation. I've written code that, in theory, should do the job, but ...