Can you point out the syntax error in my flex code?

I'm attempting to redesign my layout grid using flex. It seems that the flex code I commented out is incorrect, possibly due to an issue with setting the width in my .container class. The grid auto property adjusts the columns automatically within my .even-columns class based on the current width set in .container, but I'm unsure of how to rewrite this using flex.

Do I need to include the correct width property or should I have applied flex to my container instead?

/* CONTAINER CLASS */

.container {
  --max-width: 1110px;
  --padding: 1rem;
  width: min(var(--max-width), 100% - (var(--padding) * 2));
  margin-inline: auto;
}


/* EVEN COLUMNS CLASS */

.even-columns {
  display: grid;
  gap: 1rem;
  /* Trying same layout with flexbox
  display: flex;
  gap: 1rem;*/
}

@media (min-width: 50em) {
  .even-columns {
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    /*Trying same layout with flexbox
    display: flex;
    flex-direction: column;*/
  }
}
<!-- Main -->
<main>
  <section>
    <div class="container">
      <div class="even-columns">
        <div>
          <h1 class="fs-primary-heading fw-bold">Bring everyone together to build better products.</h1>
          <p>Manage makes it simple for software developers to chorolate their projects and share them with other teams and colleagues. </p>
          <button class="button">Get Started</button>
        </div>
        <div>
          <img src="images/illustration-intro.svg" alt="">
        </div>
      </div>
    </div>
  </section>


  <section>
    <div class="container">
      <div class="even-columns">
        <div>
          <h2 class="fs-secondary-heading fw-bold">Manage your team</h2>
        </div>
        <div>
          <ul class="numbered-items" role="list">
            <li>
              <h3 class="fs-600 fw-bold">Advertising</h3>
              <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quis laborum at quia odio laudantium qui incidunt, laboriosam facere dolores deleniti quos quod reiciendis deserunt officiis explicabo impedit ducimus, expedita consequatur?</p>
            </li>

            <li>
              <h3 class="fs-600 fw-bold">Version Control</h3>
              <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quis laborum at quia odio laudantium qui incidunt, laboriosam facere dolores deleniti quos quod reiciendis deserunt officiis explicabo impedit ducimus, expedita consequatur?</p>
            </li>

            <li>
              <h3 class="fs-600 fw-bold">Database Management</h3>
              <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quis laborum at quia odio laudantium qui incidunt, laboriosam facere dolores deleniti quos quod reiciendis deserunt officiis explicabo impedit ducimus, expedita consequatur?</p>
            </li>
          </ul>
        </div>
      </div>
    </div>
  </section>

Answer №1

When it comes to grid rules and flexbox rules, they display content in opposite ways.

The grid functions correctly with min-width by dividing the content into two columns of the same row when the width is 50em or more.

However, the same media query used with your flexbox code instructs it to display content in a column when the width exceeds 50em, which is completely contrary.

To put it simply, looking at it from a "mobile-first" perspective, your grid rules will render content in a column, while your flex rules will show content in a row.

You have two possible solutions:

Option one is to leave the code unchanged and adjust min-width to

max-width</code; this change will make flexbox work correctly.</p>
<p>Secondly, if you desire a "mobile first" design, there's no need to modify the application rule of the media query.</p>
<p>Just include <code>flex-direction: row;
within the .even-columns that is inside the media query, and add flex-direction: column; to the .even-columns located outside the media query.

Furthermore, if you want the columns to have equal widths, you must define the width for the children of .even-columns.

This is where grids excel because they eliminate the need to define all these styles for the container's children.

/* CONTAINER CLASS */

.container {
  --max-width: 1110px;
  --padding: 1rem;
  width: min(var(--max-width), 100% - (var(--padding) * 2));
  margin-inline: auto;
}


/* EVEN COLUMNS CLASS */

.even-columns {
  display: flex;
  gap: 1rem;
}

@media (max-width: 50em) {
  .even-columns {
    display: flex;
    flex-direction: column;
  }

}

.even-columns > div {
  min-width: 50%;
}
<!-- Main -->
<main>
  <section>
    <div class="container">
      <div class="even-columns">
        <div>
          <h1 class="fs-primary-heading fw-bold">Bring everyone together to build better products.</h1>
          <p>Manage makes it simple for software developers to chorolate their projects and share them with other teams and colleagues. </p>
          <button class="button">Get Started</button>
        </div>
        <div>
          <img src="images/illustration-intro.svg" alt="">
        </div>
      </div>
    </div>
  </section>


  <section>
    <div class="container">
      <div class="even-columns">
        <div>
          <h2 class="fs-secondary-heading fw-bold">Manage your team</h2>
        </div>
        <div>
          <ul class="numbered-items" role="list">
            <li>
              <h3 class="fs-600 fw-bold">Advertising</h3>
              <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quis laborum at quia odio laudantium qui incidunt, laboriosam facere dolores deleniti quos quod reiciendis deserunt officiis explicabo impedit ducimus, expedita consequatur?</p>
            </li>

            <li>
              <h3 class="fs-600 fw-bold">Version Control</h3>
              <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quis laborum at quia odio laudantium qui incidunt, laboriosam facere dolores deleniti quos quod reiciendis deserunt officiis explicabo impedit ducimus, expedita consequatur?</p>
            </li>

            <li>
              <h3 class="fs-600 fw-bold">Database Management</h3>
              <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quis laborum at quia odio laudantium qui incidunt, laboriosam facere dolores deleniti quos quod reiciendis deserunt officiis explicabo impedit ducimus, expedita consequatur?</p>
            </li>
          </ul>
        </div>
      </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

Conceal all div elements except for displaying the initial two

Can an entire div be hidden with only the first 2 entities visible? <div class="inline-edit-col"> <span class="title inline-edit-categories-label">Brands</span> <ul class="cat-checklist product_brand-checklist"> < ...

Steps for inserting a clickable phone number link within innerHTML1. First, create an

I've been trying to include a specific phone number using the <a href> tag within the innerHTML. I attempted using both double and single quotes. In the first case, nothing happens at all. In the second case, although the phone number appears, ...

Having difficulty submitting a form with ajax, while accomplishing the same task effortlessly without ajax

I have been experimenting with submitting a form using ajax to the same .php file. When I submit the form without ajax directly (form action), the database gets updated. However, when I try the same process with ajax, there is no change in the database. H ...

How to locate a specific object by its ID within a JSON structure embedded in an HTML template

I am currently working on the page where I display posts. Within my controller, I have: export class PostsComponent implements OnInit { posts$: Object; users$: Object; constructor(private data: DataService) { } ngOnInit() { this.data.getPo ...

Creating a grid layout with a row of buttons

I'm currently working on aligning buttons within a div to achieve the desired effect shown in the image below. My goal is to have all buttons centered on the page, with the small circles placed in a separate div as they are initially invisible and it& ...

Enhancing the appearance of a JSX component in React

I have a segment of code within my project that calculates a specific percentage and displays it on the dashboard. <text className="netProfit-circle-text" x="50%" y="50%" dy=".2em" textAnchor="middl ...

validation of dialog forms

Is there a way to trigger the $("#form").validated() function from the ok button in a jquery-ui-dialog? Please note that I would prefer not to use a submit button within the form. ...

Angular version 6 allows for specifying input types as numbers and displaying two decimal digits after the comma

How can I format user input to display as currency with thousand separators in Angular? <input type="number" (ngModelChange)="calculateSum()" (change)="calculateAmount(invoiceQuota)" [ngModel]="invoiceQuota.controls.grossAmount.value"> I have attem ...

What is the method for viewing the content within div tags on an apex page?

Locationbox is a system outside of Salesforce, similar to Google Maps. An example can be viewed here; I am aiming to integrate it into the Salesforce platform. The first script tag fetches JavaScript code from the Locationbox service. Once the startup() f ...

Prettyprint XML in Angular 8+ without using any external libraries

I am working with Angular 8+ and I need to display XML content in a nicely formatted way on my HTML page. The data is coming from the backend (Java) as a string, and I would like to present it in its XML format without relying on any external libraries or ...

Creating an If statement to evaluate the state of a parameter

In my simple Graphics User Interface, when the user clicks on "move", a yellow rectangle div moves across the screen. Now, I am trying to implement an event based on the position of the rectangle on the page. For example, if the div is at 400px (right), t ...

What is the best way to stop a jQuery function from applying titles extracted from the first row th's in thead's to multiple tables in a document?

My circumstances: I am new to jQuery and Stack Overflow, seeking assistance for my website project. The challenge: Building a website using Bootstrap 3.3.6 with intricate data tables that need to be stacked dynamically on mobile devices using CSS. It is c ...

Generate a new Div dynamically, positioned higher than the rest

Once a second, this script will utilize AJAX to open a new page and display the contents in a dynamically created div on this page. However, the issue is that the new divs are stacking under each other, and I would prefer them to be added at the top instea ...

Populate an HTML select with data as users click the create button

Encountering an issue when loading data into an HTML select after users press or click a button. The situation is as follows: A button is available to create another button dynamically Upon clicking the created button, a form is displayed Once the form i ...

Having trouble with redirecting a website to its appropriate version for mobile or desktop users?

After creating both the desktop and mobile versions of my website, I have a question. How can I determine whether a visitor is using a mobile phone or a PC when they come to my website? Specifically, if a visitor accesses my website through a mobile devic ...

Align title text to the right within the Material Design Card

I have implemented a Material Design (MDL) card to showcase numeric values in the title. However, I am facing an issue where the values are left aligned by default and I want them to be right aligned. Despite trying various styles, they are being ignored ...

Choose the checkbox if the tablerow includes specific text

I am working with a table that has two columns. The first column consists of checkboxes and the second column contains attribute names. My goal is to select the checkboxes next to a cell that includes specific text. Below is the structure of my table: &l ...

What are the steps to switch multiple CSS styles for creating a dark mode?

I'm currently using a combination of HTML, CSS, and JavaScript to construct my website. One feature I'd like to implement is a Darkmode switch button that toggles between Dark and Light mode when clicked. However, the issue I'm facing is tha ...

Ways to turn off textarea resizing

Is there a way to prevent horizontal resizing on a textarea while still allowing vertical resizing? I find that the textarea often disrupts the design of my contact us page. If anyone has a solution for disabling the horizontal resize feature, please shar ...

When using the "Content-Disposition" header with the value "inline;filename=" + fileName, it does not necessarily guarantee that PDF files will be displayed directly

When a link is clicked, I want the PDF file to first show in a new tab as a preview before allowing users to download it. I researched and found advice suggesting that including these two headers would achieve this: Response.AddHeader("Content-Dispositio ...