Arrange elements side by side within siblings, while keeping the HTML structure intact

As evident from the code snippet, there are 2 dynamically generated flex divs (although there could be more).

Is there a method to horizontally align items on larger screens without altering the HTML structure?

I am seeking something similar to:

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

.detail-card {
  margin-bottom: 1rem;
  padding: 1rem;
  border: 1px solid rgb(222, 226, 230);
  border-radius: 0.5rem;
}
.custom-checkbox-wrapper {
  display: flex;
  column-gap: 1rem;
  margin-top: 1rem;
  align-items: baseline;
  justify-content: flex-start;
}
@media screen and (max-width: 576px){
  .custom-checkbox-wrapper {
    flex-direction: column;
  }
}
<div class="detail-card">
  <h4>title</h4>
  <div class="custom-checkbox-wrapper">
    <div>
      <input type="checkbox">
      <label>First</label>
    </div>
    <p>Price: <span>50 €</span></p>
    <p>Name: <span>Name 1</span></p>
  </div>
  <div class="custom-checkbox-wrapper">
    <div>
      <input type="checkbox">
      <label>Second second</label>
    </div>
    <p>Price: <span>60 €</span></p>
    <p>Name: <span>Some Name 2</span></p>
  </div>
</div>

Answer №1

Utilize the table-row and table-cell to line up rows in a manner similar to table elements.

.detail-card {
  margin-bottom: 1rem;
  padding: 1rem;
  border: 1px solid rgb(222, 226, 230);
  border-radius: 0.5rem;
}

.detail-card h4 {
  flex-basis: 100%;
}

.custom-checkbox-wrapper {
  display: table-row;
  column-gap: 1rem;
  margin-top: 1rem;
  align-items: baseline;
}

.custom-checkbox-wrapper p,
.custom-checkbox-wrapper div {
  display: table-cell;
  padding: 1rem;
}

@media screen and (max-width: 576px) {
  .custom-checkbox-wrapper {
    display: flex;
    flex-direction: column;
    padding: 0;
  }

  .custom-checkbox-wrapper p,
  .custom-checkbox-wrapper div {
    padding: 0;
  }
}
<div class="detail-card">
  <h4>title</h4>
  <div class="custom-checkbox-wrapper">
    <div>
      <input type="checkbox">
      <label>First</label>
    </div>
    <p>Price: <span>50 €</span></p>
    <p>Name: <span>Name 1</span></p>
  </div>
  <div class="custom-checkbox-wrapper">
    <div>
      <input type="checkbox" disabled="disabled">
      <label class="disabled" title="Second">Second second</label>
    </div>
    <p class="disabled">Price: <span>60 €</span></p>
    <p class="disabled">Name: <span>Some Name 2</span></p>
  </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

Aligning images and input fields vertically with relative measurements

I'm looking for a way to vertically position two images, one on the left and one on the right, so that they are centered between labels and input fields within a containing div. Is it achievable using only relative lengths? Check out this jsfiddle fo ...

The margins are misaligned on a tablet-sized device due to an issue with the media

Why are the margins not maintained well when media queries are applied for tablet view, i.e., medium-sized devices? The third block is coded to acquire 100% width in medium size but the margins do not align well. What could be causing the third paragraph t ...

Define the width of jqgrid

I have been utilizing SmartAdmin jqgrid to showcase data in tabular format. The number of columns in the datatable changes dynamically each time. I am converting the DataTable to a JSON object and assigning it to the jqgrid. However, it appears that jqgrid ...

How to handle CSS line wraps: enlarge the second line or determine the number of words per line specifically?

Is it possible to use CSS to control line wraps? I would like to have lines with a similar amount of words per line, or at least avoid one-word lines. Original: A few words for a very long title that will probably span two lines Desired Outcome: A few ...

The PHP content form is malfunctioning and not processing email submissions properly, resulting in the PHP code being

Following a tutorial, I attempted to create a basic contact form using PHP. As a beginner in PHP, I found the process fairly straightforward, but encountered some bugs in the code. Upon integrating the code on my website, clicking the submit button redirec ...

Having trouble reloading a seekbar (input range) in Angular 7 with a function?

I am currently in the process of developing a music player using Angular 7, and below is the HTML code for my component: <div class="track-controller"> <small>{{musicPlayerService.getCurrentTime()}}</small> <div class="progress- ...

Construct a structure containing the key/value pairs of cells within an HTML table row using JavaScript

I'm completely new to JavaScript so please be patient with me; I'm not even sure if I'm searching for the solution correctly. Despite spending hours googling and experimenting, I still can't get it to work. My issue is related to an HT ...

Implementing function invocation upon scroll bar click

I have a Div element with a scroll bar. When a user clicks the scroll bar, I want to call a function based on that click event. How can I achieve this? On the client side, I am using jQuery and on the server side, I am using PHP. I am familiar with makin ...

Is there a way to fill the remaining height of the parent with the middle item when sandwiched between two others using CSS?

I am facing a design challenge with a parent container that has 3 children arranged vertically. The top and bottom children are wide (600x200), while the middle child is tall (200x600). The parent container itself is much smaller (100x200) as I want to ens ...

The request parameter is missing when trying to invoke methods on the MultiActionController

During the Spring 3.0 era suppose I have a jsp page with two different links, each calling a different method on MultiActionController <form:form method="POST"> <a href="user.htm?action=add" style="color: blue;">Add</a> <a hr ...

Creating a CSS Box Along the Border of Another Box: A Step-by-Step Guide

Is there a way to render a box on another box's border, similar to the example image here: Expected Output I attempted using flexbox to achieve this, but unfortunately wasn't successful in finding a solution. If you have any advice or suggestio ...

Is it possible to center content with Bootstrap?

Is there a different method to center content with empty space on either side? For instance: <div class="col-md-3"></div> <div class="col-md-6"> <div class="form-group"> .... </div> </div> <div class="col ...

Having trouble reaching the elements stored in an array?

As a beginner in Angular and JavaScript, I may be making some obvious mistakes so please bear with me. I have written this code that allows the selection of 2 text files and then combines them into a single array. $scope.textArray = []; $scope.textUpload ...

Retrieving a compilation of items found within text selected by the user on a website

Imagine a scenario in which a webpage contains the following structure: <p> <span class="1">Here's some text</span> <span class="2">that the user</span> <span class="3">could select.</span> </p> I ...

Employing [style.something.px]="2" in Angular to specify the thickness of the border

Presently, I am setting the width of the element using this code format: <div [style.width.px]="size" [style.height.px]="size"></div> What I am aiming for is to utilize a comparable format but to define the border-width css attribute, such as ...

Tips for querying multiple elements that share a common ID and verifying if the input has been modified

I have a series of text inputs that share a common id prefix but differ slightly at the end. Whenever a user enters text in any of these input fields, I want to trigger a function. Currently, I have this functionality implemented with the following code: ...

The variables are filled with HTML tags that will render the display in

I am facing an issue with displaying HTML tags in my website. When I try to print a variable containing HTML tags in the tpl file, it shows the tags along with the content. This is how it looks in the PHP file: $content = "<h1>Header</h1>< ...

What is the process for developing an Alphabetizer Program?

I have been working on this and I am having trouble getting the "alphabetized" version to display. I've tried a few things already, but I'm not sure what is missing or needs to be changed. Any advice on how to fix this would be greatly appreciate ...

The Dropdown Button Functions Once and Then Stops

I am facing a challenge in implementing a button within an HTML table that triggers a dropdown menu when clicked, and closes upon another click or when the user clicks outside the menu. Oddly, the button only seems to work once before completely losing fun ...

Unusual behavior observed while looping through an HTMLCollection returned by the getElementsByClassName method

After spending some time debugging, I discovered an issue with my function that changes the class of elements to modify their properties. Surprisingly, only specific elements were being affected by this change. It took me a while to troubleshoot and resolv ...