The justify-content: space-between command functions properly for the last two products, but is not working as expected for one of the products

I have three products displayed with images and descriptions side by side. I used justify-content: space-between to create spacing between them, which seems to work for the last two products but not the first one, which is very annoying.

Even after trying to make the width 100% to give enough room for justify-content to apply the spacing, it still doesn't work.

.products-container {
  margin-left: 10px;
  margin-right: 20px;
  outline: 2px solid yellow;
  position: relative;
}

.products-container-title {
  border-top: 3px solid black;
  padding-top: 25px;
  text-align: center;
  text-transform: none;
  font-family: /*"Sofia",*/ "Neutra Book", sans-serif;
  font-size: 1.7rem;
  color: black;
  margin-bottom: 80px;
  max-width: 287px;
  margin-left: auto;
  margin-right: auto;
}

.product {
  display: flex;
  justify-content: space-between;
  margin-bottom: 80px;
}
<div class="products-container">

  <h2 class="products-container-title">REPLACEMENT BRUSH HEADS</h2>

  <div class="product">
    <div class="product-1-image">
      <img src="img/precision-clean.png">
    </div>
    <div class="product-1-info">
      <h2>PRECISION CLEAN</h2>
      <p>Features cup-shaped bristles to reach deep between teeth, for cleaner teeth and healthier gums*</p>
      <p>*vs a regular manual toothbrush</p>
      <a href="" class="button-product-1">Learn More/Buy</a>
    </div>
  </div>

  <div class="product">
    <div class="product-2-info">
      <h2>FLOSSACTION</h2>
      <p>Features soft MicroPulseTM bristles for deep cleaning between teeth.</p>
      <a href="" class="button-product-2">Learn More/Buy</a>
    </div>
    <div class="product-2-image">
      <img src="img/floss-action.png">
    </div>
  </div>

  <div class="product">
    <div class="product-3-image">
      <img src="img/sensitive-clean.png">
    </div>
    <div class="product-3-info">
      <h2>SENSITIVE CLEAN</h2>
      <p>Provides a gentle brushing experience, ideal for sensitive teeth and gums.</p>
      <a href="" class="button-product-3">Learn More/Buy</a>
    </div>
  </div>
</div>

https://i.sstatic.net/gihUK.jpg

https://i.sstatic.net/7RLFg.jpg

Answer №1

It seems like there's a slight confusion in your interpretation of what justify-content: space-between does based on the images you provided.

In the image featuring product 2, the extra space is actually a result of utilizing display: flex. Each element has been assigned a width of 50% to accommodate two child div elements. The text within .product-2-info doesn't occupy the entire width, leaving the purple section as surplus.

On the other hand, for .product-1-info, the text expands to fill the complete width and wraps accordingly, eliminating any purple area.

To rectify this issue, consider applying a width that is less than 50% to both the info and image classes.

Furthermore, it's worth noting that classes should be used when multiple elements require the same styling, while IDs are more suitable for unique styles. In this scenario, if you intend for all info and image classes to share identical styles, simply utilize:

.product-image

and

.product-info

Answer №2

After experimenting, I incorporated the following CSS rules to achieve the desired result.

.item-picture {
  max-width: 500px;
}
.item-details {
 max-width: 500px;
}

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 process for creating a personalized <a> tag using CSS?

On my website, I am looking to differentiate between two types of <a> tags - one for inline links and the other for standalone links. This means that I want these two variations of <a> tags to have distinct colors and styles. For inline links, ...

Utilize background-size:cover and incorporate text in a horizontally scrolling webpage

Struggling to create a minimalist HTML layout with a horizontal scrollbar, featuring a large image on the left and a lengthy text with columns on the right? I suspect the issue lies in the implementation of position:relative with float, as well as position ...

The navigation bar designed with flex boxes is experiencing an issue where the "Login" button positioned on the right is being partially hidden

My website's navbar has a display: flex property to provide padding around the links, but it is causing some issues with overflow. For more details, you can check the JSfiddle link here: https://jsfiddle.net/Bradley_/3bhroby2/3/ I have noticed that m ...

Managing multiple element click events through bubbling

I have a collection of controls contained within a main div called overlay-controls. Each control has its own set of overlay-controls. To handle deletion, I am using a for loop to attach an event listener to each button with the class delete. Prior to a ...

Expanding the size of one div causes the surrounding divs to shift positions

I am currently working on creating a row of divs that expand when hovered over by the mouse. I have managed to achieve this functionality, but now I want the expanding div to cover its neighboring divs partially, without affecting their sizes or moving the ...

Issue with Jquery event not triggering correctly following ajax data retrieval

This script uses jQuery and Ajax to populate a navigation bar with categories and subcategories dynamically. The first unordered list is static, while the second one is populated after receiving data via Ajax. There are some jQuery events that need to be i ...

Is there a way to create a menu using only CSS?

Is there a way to achieve this using only CSS without any JavaScript? For reference, here's the fiddle: http://jsfiddle.net/q646Ljg6/4/ This is the HTML: <div id="navigation" class="navigation"> <div id="dropmenu" class="dropmenu"> ...

Optimizing text color for ultimate readability in PHP, JS, and CSS

When choosing a text color to go with an arbitrary background color A, it's important to consider which color B will be the most readable. In the past, many have used a simple solution that has become popular, but is ultimately incorrect: To determi ...

Ways to place a png image on top of a video background

How can I overlay a PNG over my background video without it appearing behind? I attempted to use z-index, but the video disappears when changing the position from relative to absolute or fixed. Here is the HTML and CSS code: <div id="page2"> &l ...

Guide to inserting text into an html element upon clicking an ASP:Button

In my code, there is a DIV that holds some text. Accompanying the text is an asp:Button. When this button is clicked, I aim to access and save this particular text. Nonetheless, it seems that once the button is clicked, the content of the DIV resets - lik ...

Ways to obtain jquery object for replaced DOM element

Is there a way to select the new content after using the replaceWith function in my plugin? I want to chain my plugin for the new content. $.fn.customPlugin = function() { this.replaceWith('<div>New Content</div>'); }; So, ideal ...

Problem with see-through images against a see-through backdrop

I'm experiencing a strange issue with a graphic that has rounded corners. On my HTML page, I have the body set to transparent (style="filter:alpha(opacity=100);opacity:100;background-color:transparent;"), and within this body is a div containing a PN ...

Enhancing Image Quality in Microsoft Edge

I'm trying to figure out how to make an image scale with bicubic in MS Edge. Is there a CSS solution or something similar that can change this behavior? Check out this page: On the right side of the page, there are two images with textured backgroun ...

Automatically update div content using jQuery including an AJAX request for loading

I have successfully implemented a method for loading output from now_playing.php (shoutcast now playing content) using a jQuery include ajax call, as recommended in this answer on Stack Overflow. Here is my code: <script> $(function(){ $("#now_ ...

Issues surrounding the determination of CSS attribute value using .css() function within a variable

I have been working on a function to change the color of a span dynamically from black to a randomly selected color from a predefined list. However, I am encountering an issue with the .css("color", variableName) part of my code and suspect that my synta ...

Styled-Elements Text or Passages

Can we apply styling to text or paragraphs with styled-components? And if so, how can we insert text into the component? For instance, consider this Footer component: const Footer = () => ( <footer className="site-footer"> <p className= ...

Issues with form_valid in django

https://i.sstatic.net/xj0Ys.pngIn my Django project, I am utilizing a Class-Based View (CBV) with Detail View and FormMixin to handle the functionality of listing posts and creating comments. However, I am encountering an error, as shown in the image, when ...

What steps should I follow to make a brief .mp3 audio file play with each keystroke?

I'm in the process of developing a web application with a form, and I want to incorporate a keypress sound effect as a progressive enhancement for better user experience. The sound effect I have chosen is quite short (0.18s). However, when testing m ...

Disabling Scrolling in AngularJS Material Tab Components

I'm experimenting with AngularJS Material components and struggling with creating tabs. Every time I add a tab, the content inside the child md-content element automatically gets a fixed height with a vertical scrollbar instead of adjusting its heigh ...

Embeddable video player failing to adjust size properly within parent div

I've been tackling the challenge of making iframes responsive within a div element, but I've hit a roadblock. While there are plenty of solutions available online, none seem to work seamlessly when dealing with YouTube video embeds. Currently, m ...