I'm encountering difficulties trying to align my images in the center on a mobile device using foundation's XY grid system

I recently created a practice website using the new Foundation xy grid. However, I noticed that when I resize the browser to a smaller screen size, the images are no longer centered and instead hug the left side of the page. It's only when I make the screen as small as possible that the images finally center properly. I'm not sure what I did wrong, as I have applied the align-center class to the parent element.

Check out my Codepen here

<!doctype html>


    <html class="no-js" lang="en" dir="ltr">
     <head>
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Foundation for Sites</title>
    <link rel="stylesheet" href="css/foundation.css">
    <link rel="stylesheet" href="css/app.css">
  </head>
  <body>
    <header class='header grid-x align-center align-middle'>
        <div class='cell shrink'>
            <h1>Our Site</h1>
        </div>
    </header>
    <div class='grid-container'>
        <div class='main-content grid-x grid-padding-x align-center'>
            <div class='cell shrink'>
                <h3 class='pad'>What We Are</h3>
            </div>
        </div>
      </div> 
      <div class='grid-container'>
        <div class='grid-x grid-padding-x align-center'>
            <div class='cell medium-4'>
                <img src="http://skirogaining.tojnar.cz/gpx/gpx-web.svg" alt=''>
                <p>
                    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
                </p>
            </div>
            <div class='cell medium-4'>
            <img src="http://skirogaining.tojnar.cz/gpx/gpx-web.svg" alt=''>
                <p>
                    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
                </p>
            </div>
            <div class='cell medium-4'>
                <img src="http://skirogaining.tojnar.cz/gpx/gpx-web.svg" alt=''>
                <p>
                    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
                </p>
            </div>
        </div>
      </div>
    <script src="js/vendor/jquery.js"></script>
    <script src="js/vendor/what-input.js"></script>
    <script src="js/vendor/foundation.js"></script>
    <script src="js/app.js"></script>
  </body>

Answer №1

To ensure that the image is centered within the .cell container, simply use margin: 0 auto 0 auto;, as long as the max-width of the image is smaller than the width of the .cell container.

If necessary, adjust the top and bottom margin values to better fit your layout requirements.

.cell {
  text-align: center;
  margin: 0 auto 0 auto;
}

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

Modifying `<a>` tag attributes in HTML with JavaScript by detecting checkbox selections

As a newcomer to JavaScript, I am seeking some assistance and ideas. I have an HTML anchor tag that I would like to modify or add attributes to based on checkbox selections. Anchor tag with no checkboxes selected: <a href="javascript:void(0)" data-cb ...

Conceal email address within HTML code

Similar Inquiry: What is the best way to hide an email address on a website? I've been contemplating ways to keep my email address secure on my website, including using AJAX to request it from the server after key validation and then simulating H ...

Calculate variance between two numbers using Angular

Is there a way I can calculate the difference between two values in a table column and assign it to 'differenceInValues' variable? Any help would be appreciated. Thanks! <td scope="row"> {{change.oldValue}} </td> <td sc ...

Limit the scripts on the page to only those from utilized plugins

Can we optimize the HTML output by including only the necessary scripts and files used on the site/page? The page speed is significantly affected by loading all JS and CSS files for installed plugins and the admin interface, as seen in the example below: ...

Ways to retrieve the clicked item's index in a jQuery collection without using the index() method

Is there a way to obtain the index of clicked elements easily? var $inputs = $("input"); $inputs.click(function() { console.log($(this).index()) }); This method correctly works for the structure below: div>(input+input+input) However, I am encoun ...

The CSS hover effect does not function when used within a bootstrap modal overlay

Currently, I am in the process of creating a modal view with the assistance of the Bootstrap framework. Within this setup, there are two buttons displayed on the screen. My objective is to implement a hover effect when the mouse pointer hovers over these b ...

What is behind the peculiar reaction when checkboxes are used in React?

In this demo, what is causing the button to disable only after both checkboxes have been checked? Is the button not initially displayed as disabled due to the way state behaves in react? The example consists of two checkboxes: I have read and agree to te ...

I'm struggling to understand how to upload pictures from my files onto my website

Adding images to my website has been more challenging than I expected. For example, if I have a folder named "images" on my computer's desktop with an image called "eye," will the following code display the image correctly? <img src="Desktop ...

Ideas for designing nested grids/boxes with a touch of style

Hey there, I'm on the hunt for some creative ways to construct nested boxes like the ones illustrated in the image below. My preference is to achieve this using HTML and CSS, but I am open to utilizing frameworks such as Bootstrap for styling if neede ...

Having trouble determining the height of a div element?

I'm struggling with a seemingly simple problem that I just can't seem to solve. I'm trying to get the height of my div element, but for some reason it keeps returning 0. Even when I inspect the element in Chrome, it shows me a height. Here&a ...

Adjusting the position of Qualtrics sliders to the left or right

I've been working on creating a real effort task in Qualtrics and I'm trying to figure out how to offset the sliders from each other. Here's an idea of what I'm looking for: Example of slider layout So far, I haven't been able to ...

Having trouble displaying CSS background images on hyperlinks

Hello everyone! I am in need of some assistance with a problem I'm facing. When I view my web page on my local computer, everything appears correctly with the images showing up. However, once I upload the web page to a server, the images no longer ap ...

By including "on click" as a trigger, child nodes in the (_hyperscript) can be activated

Currently, my goal is to design a menu that keeps track of whether the user has expanded or collapsed a menu item and its sub-menu items. The issue I'm facing is that the "_"on click"" event gets "attached" to all child elements. I have sco ...

Elements in Bootstrap Container class failing to align properly

Hello Everyone, I am attempting to achieve the same layout as demonstrated in [original image] where the "browse collection" div and the "request brochure" div are aligned with the four items above them. My approach involves using Bootstrap, and I assume ...

What is the best way to change a byte array into an image using JavaScript?

I need assistance converting a byte array to an image using Javascript for frontend display. I have saved an image into a MySQL database as a blob, and it was first converted to a byte array before storage. When retrieving all table values using a JSON ar ...

Ways to personalize the arrow component in react-popper

How can I match the arrow style with the popper appearance? import React from "react"; import ReactDOM from "react-dom"; import { Manager, Reference, Popper } from "react-popper"; function App() { return ( <Manager> <Reference> ...

Is the navigation bar offset causing an issue?

After struggling with my navigation menu in Google Chrome, I finally found a solution. However, the nav bar is now offset on one page but not on another. For the aligned main site view, visit , and for the left-offset forum view, visit . This is the HTML ...

Steps to customize the appearance of a button within a file input field

When implementing the file input in my code on a Mac, I noticed that the alignment appears off. On all other devices, it looks just fine. However, when I try to apply a style specifically to the 'Choose file' button, the style also gets applied t ...

Conceal button with CSS when text is brief or character count is restricted

Employing solely CSS code, I have successfully implemented a feature to display and hide full paragraphs. The code snippet below demonstrates its functionality. However, the issue arises when the "Show More" button is visible even for short paragraphs that ...

Tips for adding line breaks in Jade HTML using the br tag

Can someone help me figure out how to include a tag? I've tried but it's not working. table tbody td Juan Perez td 01 33 4455 6677 td Av José Vasconcelos 804-A Pte. br Col. Los Sabinos,CP. 66220, San ...