The arrangement of elements in an inline-block is determined by the width of the section

I have been attempting to replicate the layout shown in the image for quite some time.

The elements (.element) are aligned vertically but they are not centered, instead they stick to the left side.

My current code is as follows:

HTML:

<div id="_technology_page" class="region">
    <div class="actions_container">
        <div class="actions">
            {{#each actions}}
            <div class="action">
                <a href="{{link}}">
                    <img src="/img/technology/grafiki/{{icon}}.png" alt="">
                    <p class="action_text">
                        {{text}}
                    </p>
                </a>
            </div>
            {{/each}}
        </div>
    </div>
</div>

CSS (SCSS):

#_technology_page {
    .actions_container {
        max-width: 100%;
        position: relative;
        text-align: center;
        display: flex;
        .actions {
            position: relative;

            .action {
                float: left;
                margin: 10px 40px;
                text-align: center;
                height: 300px;
                width: 250px;
                display: flex;
                
                img {
                    margin: auto;
                    width: 120px;
                }

                .action_text {
                    width: 100%;
                    color: black;
                    position: absolute;
                    bottom: 0;
                }
            }
        }
    }
}

I have tried various solutions and looked at examples, but nothing seems to achieve the desired outcome.

Even when attempting to use the Bootstrap grid system, the elements remain aligned to the left of the container.

If possible, could you please provide some guidance or examples on how to properly implement this? I seem to be stuck and unsure of how to proceed further.

https://i.sstatic.net/s0zaL.png

Answer №1

By utilizing the power of flexbox, a more concise code can be achieved compared to yours

body {
  margin: 0
}

.region {
  border: solid;
  padding: 50px 0
}

.actions {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  border: red solid;
  padding: 10px;
}

.action {
  flex: 0 140px;
  height: 140px;
  border: orange solid;
  margin: 5px;
}
<div id="_technology_page" class="region">
  <div class="actions_container">
    <div class="actions">
      <div class="action">
        <a href="{{link}}">
          <img src="/img/technology/grafiki/{{icon}}.png" alt="">
          <p class="action_text">
          </p>
        </a>
      </div>
      <div class="action">
        <a href="{{link}}">
          <img src="/img/technology/grafiki/{{icon}}.png" alt="">
          <p class="action_text">
          </p>
        </a>
      </div>
      <div class="action">
        <a href="{{link}}">
          <img src="/img/technology/grafiki/{{icon}}.png" alt="">
          <p class="action_text">
          </p>
        </a>
      </div>
      <div class="action">
        <a href="{{link}}">
          <img src="/img/technology/grafiki/{{icon}}.png" alt="">
          <p class="action_text">
          </p>
        </a>
      </div>
      <div class="action">
        <a href="{{link}}">
          <img src="/img/technology/grafiki/{{icon}}.png" alt="">
          <p class="action_text">
          </p>
        </a>
      </div>
      <div class="action">
        <a href="{{link}}">
          <img src="/img/technology/grafiki/{{icon}}.png" alt="">
          <p class="action_text">
          </p>
        </a>
      </div>
      <div class="action">
        <a href="{{link}}">
          <img src="/img/technology/grafiki/{{icon}}.png" alt="">
          <p class="action_text">
          </p>
        </a>
      </div>
    </div>
  </div>
</div>

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

What is the best way to retrieve the color of a WebElement when dealing with a complex CSS structure in Webdriver

I am currently trying to determine if the color of a specific page changes immediately after clicking on a button designed to alter the color of an element within that page. My goal is to extract the RGB value stated as rgb(183,168,168); in this particul ...

Failure to align Bootstrap columns side by side despite being within the same row

I'm having an issue with aligning the columns in my testimonials section. Despite using col-md-5 for each column, they are not lining up side by side as expected. Here is the code I am currently using: <section id="testimonials"> <d ...

The incorporation of zoom disrupts the smooth scrolling capability of the menu

My landing page has a menu that scrolls users to the selected section. However, my client prefers the page at a 90% zoom level. To accommodate this request, I added the following line of code: body { zoom:90%; } Unfortunately, when I click on a menu o ...

Is there a way to move the cards to the next line within a wrapper when the screen size is reached?

My goal is to showcase multiple elements in cards, obtained from my routing system, much like how I'm setting up my sidebar (which is functioning correctly). I have all the titles and icons ready, and the linking works seamlessly. This is where I&apo ...

Issue with displaying YouTube videos in HTML causing them to be downloaded instead of playing

I'm currently facing an issue with loading a video on my HTML page using the following code: <video v-for="(data, key) in projectData.videos" :key="key" width="320" height="240" controls> <source :src="data.url"> </video> One ...

Issues arise with Bootstrap's navbar dropdown menus, rendering them inoper

Currently I am developing a bootstrap website using the "Butterfly" template. Everything is functioning properly except for the navbar when viewed on mobile devices. The dropdown menu fails to open on mobile devices, and I suspect it might be related to th ...

Creating a custom progress bar using Javascript and Jquery

I developed a progress bar that is fully functional. Here is the HTML structure: <div class="progress"> <div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style ...

The process of enriching an ASP.NET hyperlink by making it both bold and under

I'm currently working on a webpage in asp.net. I have two hyperlinks and I want to make them active by applying a style sheet that makes them bolder and underlined, but for some reason it's not working. Here is the HTML: <li style="margin-le ...

Verify if a set of Radio buttons contains at least one option selected

Need help with validating a Feedback Form using either JQuery or Javascript. The requirement is to ensure that every group of radio-buttons has one option selected before the form can be submitted. Below is the code snippet from form.html: <form id=&ap ...

The callback function fails to execute the click event following the .load() method

Hey there, I've hit a roadblock and could really use some help figuring out where I went wrong. Let me break down my script for you. On page1.html, I have a div that gets replaced by another div from page2.html using jQuery's .load() method. Here ...

Are you struggling to get basic HTML and JS code to function properly?

I'm currently working on developing a racing game, and my initial step was to create the car and implement movement functionality. However, I've encountered an issue where nothing is displaying on the canvas - neither the rectangle nor the car it ...

Create two grid components for Material-UI and use Flexbox to ensure that both items have equal height

I'm currently working on ensuring that two grid items have the same height using flex in Material UI, but I've hit a roadblock. It seems like my approach with the Grid element might be incorrect. I've experimented with adjusting the height a ...

Modifying multiple heading tags simultaneously with jQuery

Currently utilizing jQuery to append a string to all heading tags (h1, h2,..., h6) and display it on the screen. Seeking guidance specifically for the replacing aspect, and open to solutions using plain javascript as well. The code I have so far, which I ...

Using the pattern `[A-Za-z]{50}` in HTML is mistakenly identifying valid input as invalid

I created a webpage with text fields and wanted to limit user input using the HTML5 pattern attribute. Here is an example of how I implemented it: <input name="team_name" type="text" pattern="[A-Za-z]{50}" value="<?php echo $team_name;?>"> Ev ...

Divide the Javascript code from the HTML Canvas

I have been diving into HTML5 Canvas and exploring how to implement it using Javascript code. However, I am facing difficulties separating the Javascript code from the original html file. Despite trying some solutions: HTML5 Canvas not working in extern ...

The peculiar characteristics of the dragLeave event in various web browsers

I observed a peculiar behavior while working with drag events in Internet Explorer 11. It seems that adding a 'width' property to the elements triggers the dragLeave event, whereas without it, the event does not fire. Can anyone shed light on why ...

Resetting a component's color to its default state after being styled by a parent selector

The Bootstrap stylesheet contains the following code: pre code { color: inherit; } Even if I include an explicit pre code { color: red; }, the style from Bootstrap's stylesheet still takes priority. Why does this happen? [Edit: can ignore this ...

Where is the best place to import Bootstrap in my SCSS file when customizing it with Sass?

When attempting to customize bootstrap using Sass, I discovered that overriding default bootstrap variables can be quite confusing. I am curious if someone could provide an explanation for the inconsistent behavior. Some variables only seem to be overridd ...

Achieving this result in HTML using a jQuery accordion component

Hey there, I'm looking to create a full-height accordion that extends from the bottom to the top of the page, similar to what you see on this website: . I also have a footer positioned below the accordion. The content should load when the page loads ...

Difficulty achieving gradient effect with partial background color change in table-cell

In order to achieve a unique look for this particular design, I am seeking ways to alter the red background color of each cell in varying degrees - such as 100% for the first cell, 100% for the second cell, and 50% for the third cell. Update: After experi ...