Split the nested flex container on smaller devices' screens

Check out this Fiddle for reference

Is there a way to split the main sections in each row into new lines on mobile phones using media queries, without breaking the image and text apart? I don't want to use display-direction: column; on .row-flex as it will break both the image and text. Instead, I want them to split like shown in the provided image.

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

.row-flex {
  display: flex;
}
.col-1 {
  flex: 1;
}
.col-2 {
  flex: 3;
}
<div class="row-flex">

  <a href="#" class="col-1">
    <img src="http://placehold.it/90x90">
  </a>

  <div class="col-2">
    <p>text text text text text text text text</p>
  </div>


  <a href="#" class="col-1">
    <img src="http://placehold.it/90x90">
  </a>

  <div class="col-2">
    <p>text text text text text text text text</p>
  </div>

</div>

Answer №1

If you're searching for display-direction: column, that property doesn't exist. What you actually need is flex-direction: column. Also, remember to use display:flex to wrap the elements in a row.

.row-flex {
  display: flex;
  flex-direction: column;
}
.col-1,
.col-2 {
  display: flex
}
.col-1 div {
  flex: 1;
}
.col-2 div {
  flex: 3;
}
<div class="row-flex">
  <div class="col-1">
    <a href="#">
      <img src="http://placehold.it/90x90">
    </a>
    <div>
      <p>text text text text text text text text</p>
    </div>
  </div>
  <div class="col-2">
    <a href="#">
      <img src="http://placehold.it/90x90">
    </a>
    <div>
      <p>text text text text text text text text</p>
    </div>
  </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

php prevent unauthorized direct access to URLs

I have a variety of files such as: _main.php_, _header.html_, _page1.php_, _page2.php_,.. The header.html is included in main.php and contains links to page1.php and page2.php. I want to restrict access to page1.php and page2.php so that they can only be ...

The rounded corners feature of PIE.htc does not seem to be functioning properly on Internet Explorer

Check out my code below: http://jsfiddle.net/parag1111/s5RLb/ Make sure to place PIE.htc in the CSS folder. I've already included the necessary JS and behavior for PIE.htc. Please provide any additional suggestions to ensure compatibility with IE8 a ...

Having trouble displaying my JavaScript objects in distinct columns

I have encountered an issue where my 2 Javascript objects are not displaying in separate columns on the DOM. The requirement is to showcase the details of two individuals on a 2 Column page, with one person's information on each side. My approach inv ...

Toggle button for activating or deactivating a dropdown menu

On my ASP.NET MVC page, I have a checkbox that I create like this: <div> @Html.CheckBoxFor(m => m.allUsers, new { Name = "allUsersCheck" }) @Html.LabelFor(m => m.allUsers) </div> Additionally, I have a listbox created u ...

Having trouble getting the CSS transition effect to work properly

With the click of a button, I alternate the opacity of an element between 0 and 1. A transition effect is supposed to take place for the opacity property. However, the transition effect does not seem to work as expected. Check out this link to see the p ...

The console.log and scroll event listener are not functioning properly

Hello, I'm currently working on implementing a parallax effect on a landing page. Following this tutorial for the jQuery part - you can check out the tutorial here (skip to 21:00). I've set up my jQuery code for the landing page separate from th ...

Using regular expressions to search for HTML tags in PHP may result in empty tags being overlooked

I have a question about using regular expressions to remove hidden tags along with the ending tag. It appears to be working, but there is one issue I am facing. After removing the elements, it leaves behind "<>" for all the found elements. Here is t ...

What causes variations in the maximum size of localStorage within the same browser?

I decided to test the maximum size of localStorage in my current browser (Chrome) using ReactJS. Interestingly, I discovered that the maximum size is not determined by the bytes but rather the number of items stored in localStorage. By running the followi ...

Ensuring that text inside a float left div remains aligned with the left margin

I have a situation where I have three divs that are all floating to the left, displayed like this: (1)(2)(3). The issue arises when the font size within div1 is longer than the width I set, causing it to go to the next line within the div. However, the nex ...

Encircle a circle within the Progress Tracker

Is there a way to create a ring around the circle in this progress tracker, similar to the image shown here? The progress tracker is based on You can view an example here. The CSS approach used was: .progress-step.is-active .progress-marker { backgrou ...

Tips for customizing angular-material radio buttons

I attempted to modify the appearance of the radio button component using CSS in my code, but unfortunately, it does not seem to be effective. The default setup for this component places the button on the left and the label on the right. I am interested in ...

Capture an image of the video frame every second

Have you ever noticed the cool feature on YouTube where you can easily 'scrub' through video and see a thumbnail view at each second? https://i.sstatic.net/Yi8He.png I'm curious - how is this achieved? Does the server have to send over eac ...

I am unable to see the last row of the table when I apply a condition after the table name

I need to display all the data from my table. However, if I include ORDER BY id DESC or any code after $sql="SELECT * FROM $tbl_name, the last row does not appear. <?php include "db.php"; $tbl_name="report"; // Table name $sql="SELECT * FROM $tbl_ ...

Are HTML files and PHP generated files cached differently by web browsers?

My current setup involves Nginx as a web server and Firefox to check response headers. I added two files on the server - test.html and test.php, both containing the same content. In the Nginx config file, I have set the expires directive to 30d in the serv ...

Creating alignment for text within a span element that is nested inside a p tag

I am having trouble aligning some text that is enclosed in a span, which is nested inside a p element. Despite my efforts, it doesn't seem to be working as expected. <p>This line has no alignment.<br /><span class="new">This is righ ...

What is the best method to deactivate zoom in/out buttons using JavaScript?

As a newcomer to Phonegap, I've managed to implement zoom in/out functionality using websettings in the .java file. However, I now face a challenge where I need to disable/enable the zoom in/out buttons and stop scrolling at a specific point. I attemp ...

The radio button allows for the selection of multiple items, rather than just one at a time

https://i.sstatic.net/9MEzS.png I have implemented a radio input as shown below <input type="radio" id={el.name} className="form-check-input" name={el.name} data-count={el.name} value={el.id} onChange={this.select_role.bind(this)} style={{margin: "4px ...

Are web components capable of managing changes in CSS (maybe through cssChangedCallback)?

Is there a way to control the application of CSS to a web component similar to using attributes through attributeChangedCallback. I am currently developing a couple of web components that could benefit from being styled with CSS classes. However, I requir ...

What is the best way to create distance between two rows?

I am trying to create space between two rows in an HTML file Where should I insert the code to add space between the two rows? <script type="text/javascript" src="https://code.jquery.com/jquery-3.4.1.slim.js"></script> <link rel="s ...

Navigating a roster of users in JavaScript

I'm dealing with a collection of user data stored in an array accountsade: [ { id: 0.4387810413935975, name: "Adrian", password: "345", userName: "nathanael" }, { id: 0. ...