Ways to adjust the placement of a div element with the class card

Good evening,

I am currently in the process of developing an online shopping website.

I would like to adjust the positioning of a specific div on the page to align it similarly to another class called card div.

Please refer to the image below for better understanding:

https://i.sstatic.net/3VvGe.png

As you can see, I want the div containing "Yopro" to be slightly elevated and not aligned with the first one.

Here is the snippet of my HTML code:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8>
  <title>Online Shopping Website</title>
  <link rel="icon" href="img/Fevicon.png" type="image/png">
  <!-- More CSS and JS links go here -->
</head>
<body>

  <header class="header_area">
  <!-- Header content details go here -->
  </header>

  <main class="site-main">

    <section class="hero-banner">
      <!-- Hero banner content goes here -->
        <div class="container">
          <h1>Welcome to our Online Shop</h1>
        </div>
    </section>

    <section id="section_all_produit">
      <!-- Product cards displayed here -->
    </section>

  <footer class="footer">
    <!-- Footer section details go here -->
  </footer>

  <script src="js/main.js"></script>
</body>
</html>

Above is just a portion of my complete HTML file. I'm also utilizing some CSS which includes styling for different elements like headings and buttons.

#h1_all_product {
  text-align: center;
  font-size: 250%;
  text-transform: uppercase;
  color: #2a2b75;
}

.prix{
  color: red;
  font-size: 150%;
  display:inline-block;
  margin-right: 65px;
}

.btn-achat{
  margin-bottom: 30px; 
  margin-top: 15px;
}

#card2{
  display: inline-block;
}

.cardcss{
  display: inline-block;
}

Your assistance in achieving this layout adjustment will be highly appreciated. Thank you!

Answer №1

For optimal image display, consider giving your images a fixed height and percentage width while using object-fit: cover and object-position:center. Here's an example:

img.card-img-top {
  object-fit: cover;
  width: 90%;
  height: 300px;
  object-position: center;
}

#h1_all_product {
  text-align: center;
  font-size: 2em;
  text-transform: uppercase;
  color: #2a2b75;
}

.prix {
  color: red;
  font-size: 150%;
  display: inline-block;
  margin-right: 65px;
}

.btn-achat {
  margin-bottom: 30px;
  margin-top: 15px;
}

#card2 {
  display: inline-block;
}

.cardcss {
  display: inline-block;
}

img.card-img-top {
  object-fit: cover;
  width: 90%;
  height: 300px;
  object-position: center;
}
<section id="section_all_produit">
  <h1 id="h1_all_product">Browse through all the products available at our "Marjane" store</h1>

  <div class="card cardcss">
    <img src="https://placekitten.com/300/600" class="card-img-top" alt="...">
    <div class="card-body">
      <h5 class="card-title">Perly</h5>
      <p class="card-text">Quantity: 90g</p>
      <p class="card-text">Brand: Jaouda</p>
      <p class="card-text">Manufacturing Location: Taroudant</p>

      <h3 class="prix">Price: 2.5 Dhs</h3>
      <button href="#" class="btn btn-primary btn-lg btn-achat"><i class="fas fa-shopping-cart"></i></button>
    </div>
  </div>

  <div class="card" id="card2">
    <img src="https://placekitten.com/300/550" class="card-img-top" alt="...">
    <div class="card-body">
      <h5 class="card-title">Yopro</h5>
      <p class="card-text">Quantity: 90g</p>
      <p class="card-text">Brand: Jaouda</p>
      <p class="card-text">Manufacturing Location: Taroudant</p>
      <h3 class="prix">Price: 2.5 Dhs</h3>
      <button href="#" class="btn btn-primary btn-lg btn-achat"><i class="fas fa-shopping-cart"></i></button>
    </div>
  </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

I am in search of a specialized 3D camera with a unique effect

I am seeking assistance with animating a camera to replicate or closely resemble the effect seen in this demo: Any help would be greatly appreciated. ...

Utilizing @media queries in a unique React setup that involves a mixture of .tsx and .ts files

I have been immersed in the world of React for a good couple of years now, and have also dabbled in @media queries since the early 2000's. Recently, I joined a new project where they are taking a unique approach to building React components that is qu ...

Select a checkbox from a dropdown menu

I need help with automatically checking a checkbox when an option is selected from a dropdown menu. Here is an example of the HTML code: <table> <tr> <td> <input type="checkbox" name="check1" />Process 1:< ...

Tips for achieving vertical alignment of a Bootstrap 4 Carousel slide while it transitions

I am currently working on building a carousel to showcase testimonials, but I am facing some challenges regarding the vertical alignment of the slides. My goal is to have the slides centered when they enter the screen, but currently they start at the top ...

Django No Reverse Match Error - All Functions Are Failing

After spending countless hours troubleshooting, I have encountered an issue where the HTML form action in a newly rendered page is causing the page not to load properly. Surprisingly, this specific line of code seems unrelated to the rendering process itse ...

html querying an iframe

Here is a scenario that I have encountered: I want to display a top bar on an HTML page, followed by another HTML page dynamically included at the lower part of the page using an iframe. The goal is to prevent scroll bars for the window and only show a sc ...

What is the best way to ensure that a particular page on my WordPress site displays a responsive design?

The specific URL of concern is weddings.blaskphotography.com.au/photographs When accessing this page on an iPhone, I would like it to utilize the mobile stylesheet included in Woothemes' Canvas theme that I have implemented. My current setup involve ...

Get rid of the horizontal scrolling issue caused by the navbar

Take a look at this basic Bootstrap example: Check out the demo here. I'm encountering an issue with the navbar causing horizontal scrolling. Any suggestions on how to fix this? Appreciate any help, thank you! ...

Implement changes to C# code via website or database management

I've been researching different methods of retrieving content from a web server or database online, and I've come across a lot of discussions about using the WWW method. However, I'm looking for a solution where I don't have to constant ...

Tips for displaying a message in a concealed field with jQuery

I have an input field that saves values for checking a specific condition. When the condition is false, I want to display a message. If the field is hidden, the message will not be displayed. HTML <input type="hidden" id="year1_req_fund_hidden" name= ...

Shift the checkbox label over to the left with just CSS

I am faced with the following code snippet: <div> <span> <input type="checkbox"> <label>I desire this to appear on the left-hand side</label> </span> </div> My goal is to shift the label to the left side of ...

Utilizing PHP to Extract Information through cURL and HTML Parsing

Is there a way to search through an HTML page specifically for text contained within a particular div element? ...

Even after the loading spinner stops and the page appears, there is a 10-second delay where scrolling and clicking buttons are not responsive in the browser

Despite the browser's loading spinner stopping and the initial content of the page appearing ready, all buttons are unresponsive and scrolling is impossible for at least 10 seconds after the spinner stops. This page contains multiple views that are i ...

Sending text from a Tinymce textarea using Laravel 4.2

I am currently facing an issue with a form that includes a tinymce textarea, allowing users to edit text and save it into a database with HTML tags for display on their profile. The problem arises when Laravel 4.2 escapes the HTML tags, making it difficult ...

Having trouble altering font-family, font-size, and font-weight with JavaScript?

Looking for a way to dynamically change textareas based on selections made in dropdown menus? Check out this JavaScript code snippet: http://jsfiddle.net/73udajhm/ The following is the JavaScript used: $(function () { $("#fontsize").on('change&a ...

What is the best way to retrieve the value from a malfunctioning HTML date input field?

I am currently developing a custom calendar picker to complement (and serve as a replacement for the default date picker provided by certain browsers) an input with type="date". It has come to my attention that Chrome's date input allows fo ...

Looking for assistance in crafting the flag of Iceland using only HTML or CSS coding

Can someone assist me in coding the flag of Iceland using only HTML and CSS, without using any images? Your help is greatly appreciated. https://i.sstatic.net/ND6bq.png ...

Is there a way to use AngularJS foreach to extract targeted values by a specified key from a JSON object?

I have received a JSON object from an elastic search query as shown below: How can I extract the Agent and calls values from this JSON data? $scope.results = client .query(oQuery.query($scope.queryTerm || '*')) . ...

:empty selector for targeting an empty tbody element

Here is the table provided for reference: <table id="incidents"> <thead> <tr> <th></th> </tr> </thead> <tbody> </tbody> </table> When using jQuery, th ...

Flexible Columns with Bootstrap

After completing the construction of my website, my current focus is on making it responsive. My inquiry pertains to a specific page on my site that consists of 8 containers with full viewport height. These containers are arranged into two equal columns ...