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:

.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

It appears that the Facebook share feature is not picking up any meta OG tags

There seems to be an issue with my Facebook share functionality as it's not reading any of the meta tags. It is indicating that the required properties such as og:url, og:type, og:title, og:image, og:description, and fb:app_id are missing. <script ...

A layout featuring a grid of 3 rows and 2 columns, each containing 6

Is there a more effective method to construct this 3x2 "table" using DIVS? I'm considering using traditional tables code <table> since it's simpler, but modern practice leans towards Divs. So, what is the most polished approach to achiev ...

A dynamic 2-column website design featuring a mobile-friendly layout and an adaptable image

After searching through numerous resources on the topic, I have yet to find a solution to this particular challenge. Is it feasible to create a webpage layout with a text column on the left and an image column on the right that will seamlessly transition i ...

Using Javascript to select a radio button in a form depending on the value entered in a text box

I have a form that interacts with a Google Sheet to insert and retrieve data. For instance, the form contains two radio buttons: <input id="Rdio_1" name="RdioSelect" type="radio" class="FirstCheck" value="1" onchange="RadioValInsert ()"/> < ...

Increasing the level of CSS list counters

HTML <ol> <li>item1 <ol> <li>item2</li> </ol> </li> <li>item1 <ol> <li>item2</li> <li>item3</li> </ol> </li> </ol> SC ...

The screen is cloaked in a dark veil, rendering it completely inaccessible with no clickable

Utilizing Bootstraps modals, here is my current layout. Within the site's header, there exists a "settings" button that triggers a modal containing various options. These options are not tied to the question at hand. The button responsible for displ ...

Is there a way to display all of them inline in Woocommerce?

Can anyone assist with making each of these inline? <div class="atc_nsv"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <ul> <li><img class="ad lazyloaded" data-src="//cdn.shopify.com/s/files/1/0608/5882/6972/fi ...

Understanding the integration of sass with webpack in an Angular 4 project

Is it possible to reference a sass file instead of a css file directly in the index.html? If so, how does webpack compile the sass into a css file? Additionally, what is the most effective way to bundle the sass file when building the application? The ve ...

Validate the presence of an element on a page using selenium

I attempted to use the following code: if driver.find_element_by_xpath("/html/body/div[2]/div[3]/div[1]/div[1]/button"): pass believing it would be successful, however it did not work and instead resulted in: selenium.common. ...

I am currently facing an issue with validating forms in JavaScript Document Object Model (DOM)

Whenever I click on a field and move to another one, the span tag turns red. Then, after pressing the submit button, an alert message pops up. However, if I turn the span red, fill in the field, and press the submit button, it shows success even if other f ...

The CSS selector seems to be malfunctioning

I am facing an issue with calling HTML elements from CSS using CSS selectors. It's strange that the class selectors work fine, but I'm unable to select the elements directly from CSS. Therefore, I had to assign them classes. What I aim to achiev ...

Utilize a dynamic approach to add the active class to navigation list items

My files all have a header that includes a navigation bar. I am trying to use jQuery to add the 'active' class to the relevant list items (li). The method I initially thought of involved setting a variable on each page, assigning an ID equal to ...

Repetitive Anchor IDs and Web Standards Compliance

Today, I encountered the task of converting outdated attributes on a page to make it more XHTML friendly. This led me to consider the anchor tag and its usage: Initially, I had anchor tags in the form of <a name="someName"></a>. However, upon ...

Is it possible to trim a video using HTML code?

I am trying to find a way to crop a video using HTML 5. <video id="glass" width="640" height="360" autoplay> <source src="invisible-glass-fill.mp4" type="video/mp4"> </video> Currently, the video has a resolution of 640x360. However ...

Why isn't this code for hiding the animation and displaying it not functioning properly?

Why isn't this animation from display none to block working properly? The initial code appears as follows, and it functions correctly: $(".box_outer").stop().animate({top: '25px' , opacity: 1}, 100); When I add display: none; to the class ...

Internet Explorer experiencing printing issues

Can anyone explain why IE (8,9 Tested) is refusing to print the right side of this coupon on the red background? The left side (phone number) prints fine. Other browsers like Chrome and Firefox print the whole document correctly. To see the bug, you can ...

Steps to include a HTML webpage within another page

I need assistance with a scenario involving two separate HTML pages on different servers. Merchant Form - Server A Payment Form - Server B Here's the desired scenario: The user completes all necessary fields on the Merchant Form and clicks submit. ...

Is it possible to have the cursor rotate or animate by 45 degrees when clicked

Do you know how to create a unique custom cursor using CSS? Say, for example, we have this code: cursor: url(images/cursor.png) 15 15, auto; Now, what if we wanted to take it up a notch and make the cursor rotate -45 degrees when clicked, and then revert ...

What is the best way to utilize a mask in an inline SVG that is compatible with Chrome browser?

I am looking to visually crop my element using an SVG shape that is defined within the same HTML file (inline SVG). Using clip-path works perfectly: div { width: 200px; height: 200px; background-color: red; clip-path: url("#c"); } <div> ...

Customizing the appearance of two separate tables

I have a pair of tables that I want to style differently. Table 1 needs the images centered with no border, while table 2 should have text left-aligned with a border. Here is the CSS: table, th, td { border: 1px solid #999; border-collapse: colla ...