A pair of div containers arranged in rows

I currently have 9 different div containers, each with unique styling for spacing and padding. My goal is to arrange these div cards into 2 rows with sufficient spacing between them for easy readability. As of now, I have all the div containers stacked in a single row, creating inconsistent spacing. Below, I will outline my logic with both CSS and HTML code.

// css code

.cards-container {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
}

.card {
  width: 100px;
  height: 100px;
  
}

.card img {
  max-width: 60px;
  max-height: 60px;
}

.card h3 {
  font-size: 16px;
  margin-top: 10px;
}

.card-container > .card {
    width: 120px;
    height: 120px;
}

.card-body {
    display: flex;
    flex-direction: row;
    align-items: center;
    height: 50px;
    padding: 10px;
}

.icon {
    font-size: 24px;
    margin-right: 5px;
}

h3 {
    margin: 0;
    font-size: 14px;
}

// bootstrap html code

<!-- Shop by Categories starts here -->
        <div id="hot">
          <div class="box py-4">
            <div class="container">
              <div class="row">
                <div class="col-md-9">
                  <h2 class="mb-0">
                    Shop by Categories
                  </h2>
                  <!-- Health and Beauty icon -->
                  <a href="category-full.html">
                    <div class="cards-container d-flex justify-content-between">
                      <div class="card-container">
                        <div class="card">
                          <div class="card-body">
                            <div class="row flex-wrap">
                              <div class="col-12">
                                <img src="img/eShop-Images/NewBeauty.png.png">
                                <h3>Health and Beauty</h3>
                              </div>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>
                  </a>

                  <!--Clothing & Accessories icon-->
                  <a href="category-full.html">
                    <div class="card-container">
                      <div class="card">
                        <div class="card-body">
                          <div class="row flex-wrap">
                            <div class="col-12">
                              <img src="img/eShop-Images/clothes_accessories.png.png">
                              <h3>Clothing & Accessories</h3>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>
                  </a>

                  ...
                  
                  <!--Office equipment -->
                    <a href="category.html">
                      <div class="card-container">
                        <div class="card">
                          <div class="card-body">
                            <div class="row flex-wrap">
                              <div class="col-12">
                                <img src="img/eShop-Images/office_equipment.png.png">
                                <h3>Office equipment</h3>
                              </div>
                            </div>
                          </div>
                        </div>
                      </div>
                    </a>
               
              </div>
            </div>
          </div>
        </div>

Answer №1

** Here is a custom HTML and CSS solution for your question. It may not be exactly what you're looking for, but it could be helpful. This solution does not use Bootstrap.**

@import url("https://fonts.googleapis.com/css2?family=Alegreya:wght@400;500;600;700&family=Mulish:ital,wght@0,200;0,300;0,400;0,500;0,600;0,700;0,800;1,400&family=Oxygen:wght@300;400;700&family=Poppins:wght@100;200;300;400;500;700;800&family=Roboto:ital,wght@0,100;0,300;0,500;0,700;0,900;1,400&family=Source+Sans+Pro:wght@200;300;400;600;700&display=swap");

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: "Poppins", sans-serif;
}

.container {
  display: flex;
  flex-wrap: wrap;
  flex-direction: row;
  width: 600px;
  margin: 20px auto;
  justify-content: center;
  /* justify-content: space-between; */
  border: 1px solid;
}

h1 {
  text-align: center;
  font-size: 25px;
  margin-top: 10px;
}

.card {
  width: 250px;
  height: 250px;
  background-color: aqua;
  margin: 20px;
  border-radius: 6px;
  position: relative;
  cursor: pointer;
  box-shadow: 0px 1px 10px 0px lightgray;
}

.card-img img {
  height: 250px;
  width: 100%;
  border-radius: 5px;
}

.card-text {
  position: absolute;
  bottom: 0px;
  background-color: white;
  border-radius: 0 7px 0 5px;
  font-weight: bold;
  padding: 20px 30px 20px 5px;
}

.card-text a {
  text-decoration: none;
  color: black;
}
  <section>
      <h1>Shop by Categories</h1>
    </section>

    <section>
      <div class="container">
        <div class="card">
          <div class="card-img">
            <img
              src="https://cdn.pixabay.com/photo/2023/04/03/11/45/water-7896610_960_720.jpg"
              alt=""
            />
            <div class="card-text">
              <a href="#">Video Games GTA-5</a>
            </div>
          </div>
        </div>

        <div class="card">
          <div class="card-img">
            <img
              src="https://cdn.pixabay.com/photo/2023/04/03/11/45/water-7896610_960_720.jpg"
              alt=""
            />
            <div class="card-text">
              <a href="#">Video Games GTA-5</a>
            </div>
          </div>
        </div>

        ...
        <!-- Code truncated for brevity -->
        
      </div>
    </section>

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

The <pre> tag is not adjusting the column width properly within the Bootstrap framework

I have utilized Bootstrap CSS to style my webpage. Interestingly, when I incorporate the <pre>...</pre> tag within the class="col", it does not adjust the width of the column as expected, and instead enlarges the entire column's ...

Creating a dynamic navbar in an ASP.NET website by populating it with data from a

Seeking guidance on creating a dynamic Bootstrap navbar in an ASP.NET website based on the user's role stored in a database, while maintaining the same style. I have extensively searched for a solution without success. Any assistance would be greatly ...

Crafting a unique datalist from an XML file with the help of jQuery

<mjesta> <mjesto>Zagreb</mjesto> <mjesto>Split</mjesto> <mjesto>Ploce</mjesto> <mjesto>Pula</mjesto> <mjesto>Pazin</mjesto> <mjesto>Daruvar</mjesto> <mjesto>Bjelovar</mj ...

Discover the secret to toggling Bootstrap 4 cards visibility when hovering over the navigation menu using CSS

Hey, I'm currently working on a project where I want to show and hide specific sections of cards by just hovering over the menu list. While I can successfully hide the cards using CSS, I am facing issues with displaying them using the display:block pr ...

The CSS styling of Vuetify TreeView does not support text wrapping

I'm having trouble getting the long text in this CodePen snippet to break and wrap properly. It extends off screen, rendering the append button unclickable. I've experimented with various CSS rules but haven't found a solution yet. Check ou ...

Experiencing an issue of receiving an undefined value while attempting to retrieve a value from an input box

HTML: <input value='Rename' type='button' onclick='RenameGlobalPhase({$row['id']});' <span id='renameGlobalPhase{$row['id']}'>" . $row['phase'] . "</span> Below you wil ...

Maximizing Compatibility of CSS3 Responsive Image Sprites for Firefox

Take a look at the Demo. Make sure to test it on both Chrome and Firefox to experience the difference. I've created a div element with the following CSS classes to make a responsive sprite of images: .what-wwb-logo, .what-national-geographic-logo, . ...

Vue.js does not support the usage of external JSON files directly within HTML documents

I'm encountering issues fetching data from an external JSON file for a specific variable. I suspect that the problem lies in using Vue.js within the HTML, as it seems to be having trouble interpreting my code correctly.:joy: jsfiddle Additionally, I ...

Combining and removing identical values in JavaScript

I need to sum the price values for duplicated elements in an array. Here is the current array: var products = [["product_1", 6, "hamburger"],["product_2", 10, "cola"],["product_2", 7, "cola"], ["product1", 4, "hamburger"]] This is what I am aiming for: ...

The attempt to unserializing the configuration schema in Yii2 was unsuccessful

My brain feels scrambled... I am attempting to insert an image in HTML within Yii2. I retrieve it from the database and place it into the view file, but when I try to display it using HTML tags, an error is thrown. However, the image is being added perf ...

What is the process for creating URL query parameters?

What is the process for generating parameters after node?_=xxxxxx? If I am using a Python script to access the URL, how can I retrieve these parameters? edit: I apologize for not providing enough information. This is my first post as a novice. I am atte ...

Replace the default disc icon with a more detailed icon for UL lists

I am working with an unordered list and I want to use <details> to show a sublist for one of the items: <ul> <li><details> <summary>details bullet</summary> <ul> <li>detail 1</li> ...

What's the best way to apply a margin top to an image using Tailwind CSS?

Is there a way to adjust the top margin of an image in Tailwind CSS? I'm having trouble making my logo clearly visible and think giving it some space at the top might help. How can I do this within the Tailwind CSS framework? https://i.sstatic.net/Ae ...

How to retrieve and delete a row based on the search criteria in an HTML table using jQuery

Here is the HTML code snippet: <table class="table" id="myTable"> <tr> <th>Type</th> <th>Counter</th> <th>Remove</th> <th style="display:none;">TypeDistribution</t ...

PHP script not refreshing properly on reload causing randomized content to display inaccurately

In an attempt to create a dynamic website that features a random image on each page refresh, I have stored all images in a directory named "/pngs/" and set up a MySQL database with indexed rows for reference: <img src="pngs/000.png"> <img src="pn ...

Utilize jQuery, Flash, or HTML5 to upload an image

Does anyone know of an upload tool or plugin that has a similar look and functionality to the one used on Codecanyon's website? I tried Uploadify, but it doesn't work on all browsers. I need something that is compatible with all browsers, whether ...

Looking for an effective method to implement CSS styling within a list cell in JavaFX?

As a beginner in JavaFX with limited knowledge of CSS, I struggled to conduct proper research and provide relevant information here. I apologize for any confusion or duplication. I am seeking a solution to apply CSS to JavaFX controls, specifically in a Li ...

"Trouble with jQuery: Selecting an image to change isn't

Can someone help me figure out why my simple image change on a dropdown isn't working correctly? You can find the code on this Jsfiddle. Thank you for any assistance! $("#display_avatar").change(function(){ $("img[name=preview]").attr("src", $( ...

Ways to prevent a particular link from functioning in HTML or JavaScript

Hey there, I am currently using a Gchat voice and video chat script. Check out my website if you're interested. The issue I'm facing is that someone logs into my chatroom and uses this flash link to crash other users' browsers. Whenever th ...

Video Autoplay within an image carousel - A seamless integration

I need assistance embedding a YouTube video as the fourth item in a slideshow on my website, www.serenitygardenrooms.com. The slideshow should play the first three images and then autoplay the video before moving on to the next image. However, the code sni ...