Other options to consider besides using flex wrapping

Is it possible to use other methods to wrap these image items with the display: flex; property besides using the flex-wrap property? Are there alternative approaches available?

body {
  margin: 0px;
}

img {}

h1 {}

p {}

a {
  background-color: #ddd;
  border: 1px solid #000;
  padding: 10px 20px;
  margin: 10px;
}

.container {
  display: flex;
  flex-wrap: wrap;
}

.item {
  background-color: #eee;
  padding: 10px;
  margin: 10px;
}
<div class="container">

  <div class="item">
    <img src="http://lorempixel.com/1024/512/" alt="">
    <h1>Title 1</h1>
    <a href="#">Link</a>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vel suscipit ligula. Vestibulum eu metus nibh. In nec dignissim orci.</p>
  </div>

...
...

  <div class="item">
    <img src="http://lorempixel.com/512/512/" alt="">
    <h1>Title 7</h1>
    <a href="#">Link</a>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vel suscipit ligula. Vestibulum eu metus nibh. In nec dignissim orci.</p>
  </div>

</div>

Answer №1

One day, a different approach will emerge as display: grid:

.wrapper {
  display: grid;
  grid-auto-flow: row;
}

Demo on Github

Answer №2

If you're looking for an alternative to using flex-wrap: wrap, consider switching from flex-direction: row to column by utilizing a media query.

Check out the demo on jsFiddle

body {
  margin: 0px;
}

img {}

h1 {}

p {}

a {
  background-color: #ddd;
  border: 1px solid #000;
  padding: 10px 20px;
  margin: 10px;
}

.container {
  display: flex;
  /* flex-wrap: wrap; */
}

.item {
  background-color: #eee;
  padding: 10px;
  margin: 10px;
}

@media ( max-width: 500px ) {
.container {
  flex-direction: column;
}
<div class="container">

  <div class="item">
    <img src="http://lorempixel.com/1024/512/" alt="">
    <h1>Title 1</h1>
    <a href="#">Link</a>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque eget mauris. Suspendisse id velit. Integer sed metus vel ante mattis gravida nec ut turpis.</p>
  </div>

  <div class="item">
    <img src="http://lorempixel.com/512/512/" alt="">
    <h1>Title 2</h1>
    <a href="#">Link</a>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque eget mauris. Suspendisse id velit. Integer sed metus vel ante mattis gravida nec ut turpis.</p>
  </div>

  <div class="item">
    <img src="http://lorempixel.com/1024/512/" alt="">
    <h1>Title 3</h1>
    <a href="#">Link</a>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque eget mauris. Suspendisse id velit. Integer sed metus vel ante mattis gravida nec ut turpis.</p>
  </div>

  <div class="item">
    <img src="http://lorempixel.com/512/256/" alt="">
    <h1>Title 4</h1>
    <a href="#">Link</a>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque eget mauris. Suspendisse id velit. Integer sed metus vel ante mattis gravida nec ut turpis.</p>
  </div>

  <div class="item">
    <img src="http://lorempixel.com/512/512/" alt="">
    <h1>Title 5</h1>
    <a href="#">Link</a>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque eget mauris. Suspendisse id velit. Integer sed metus vel ante mattis gravida nec ut turpis.</p>
  </div>

  <div class="item">
    <img src="http://lorempixel.com/1024/512/" alt="">
    <h1>Title 6</h1>
    <a href="#">Link</a>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque eget mauris. Suspendisse id velit. Integer sed metus vel ante mattis gravida nec ut turpis.</p>
  </div>

  <div class="item">
    <img src="http://lorempixel.com/512/512/" alt="">
    <h1>Title 7</h1>
    <a href="#">Link</a>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque eget mauris. Suspendisse id velit. Integer sed metus vel ante mattis gravida nec ut turpis.</p>
  </div>

</div>

Answer №3

Another option instead of utilizing flex is to eliminate display: flex from the container and employ display: inline-block for all item images.

.item{
  display: inline-block;
  background-color: #eee;
  padding: 10px;
  margin: 10px;
}

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

The HTML code as content

While working on an AJAX project, I ran into this issue: http://jsbin.com/iriquf/1 The data variable contains a simple HTML string. After making the AJAX call, I noticed that the returned string sometimes includes extra whitespaces. I attempted to locat ...

Version 66 of Chrome on Mobile Browser now offers Autoplay functionality

My goal is to implement a feature where an image with a play icon is displayed, and when the user clicks on the icon, a video is loaded in an iframe within a popup window. Despite following the guidelines provided in this link, we are facing issues with ...

The vertical spacing in Font "bottom-padding" appears to be larger than anticipated

Recently, I purchased the font Proxima Nova for my project and I am encountering issues with vertical alignment. Despite setting margins, line-heights, and padding to match those of Arial, the results are not consistent as the Proxima Nova appears misalign ...

Having trouble applying CSS styles to a class using Material UI withStyle? If you're finding that withStyle isn't working as

Check out this code snippet: import { withStyles, MuiThemeProvider, createMuiTheme } from '@material-ui/core/styles'; import classNames from 'classnames'; const styles = theme => ({ myGridStyle:{ '&:.my-row-s ...

Adjust Font Size inside Circular Shape using CSS/jQuery

I have been searching for different libraries that can resize text based on the size of a container. However, my container is circular and I am facing difficulty in preventing the text from overflowing beyond the border. Below you will find a Fiddle conta ...

What might be the reason for jQuery not functioning in Internet Explorer 11?

Working on developing a slideout menu for my website using jQuery. It functions perfectly in Chrome, but encountering issues in Internet Explorer (IE11). Extensive search hasn't provided a solution yet. Seeking assistance and any help would be highly ...

Is there a specific code repository available that can verify and transform blog comments into XHTML strict format?

I'm currently developing a PHP website that allows users to make comments similar to a blog, and I am specifically interested in restricting the use of certain HTML tags. Is there any existing library that can process user comments and output valid XH ...

I am looking to conceal an element as soon as a list item is scrolled into view and becomes active

Is it possible to hide a specific element when the contact section is activated on scroll, and have it visible otherwise? How can this be achieved using Jquery? <ul class="nav navbar-nav navbar-right navmenu"> <li data-menuanchor="ho ...

Using Angular Project: Exploring the Feasibility of Accessing SCSS Files from Node_modules in Custom Components

When setting up Angular, how can I include a Bootstrap SCSS file in a Custom Component using Style.SCSS? In Angular.json { "$schema": "./node_modules/@angular/cli/lib/config/schema.json", "version": 1, "newProjectRoot": "projects", "p ...

invalid audio element

I'm currently working on building an audio player with a visualizer feature. However, when I try to initiate the audio player by clicking on the input button, my debug console keeps showing this error message: Uncaught (in promise) DOMException: Fa ...

When the window is resized, the text and images become jumbled and distorted

As a beginner in CSS, I am encountering an issue where the text and images on my website get distorted when I resize the window. How can I resolve this? HTML <img src="images\titles_03.jpg" class="tt1" > <img src="images\titles_05.jpg ...

The style of CSS remains constant within the JSP file

Having trouble updating styles on a JSP page using CSS. Here is the code snippet for linking: <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/Profile.css" /> Initially, the styling wo ...

Enhance the speed of webview on Android devices

I have been working on an application that utilizes a webview to load both HTML and JavaScript files. Unfortunately, I have noticed a significant decrease in performance when displaying the content. Despite trying various solutions such as: webVi ...

What is causing columns.render not to trigger when DataTable().draw() is invoked?

I'm wondering why the columns.render method is not part of the execution flow when using DataTable().draw(). For instance: HTML <table id="data"> <thead> <tr> <th>TimeColumn</th> < ...

How can I add a Facebook HTML5 Like Button to AJAX Pages?

I am trying to implement the Facebook HTML5 Like Button on my Ajax views. On my main page, this is what I have: <div id="fb-root"></div> <script>(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById( ...

`What purpose does the data-view attribute serve in Durandal JS?`

While experimenting with the Durandal JS starter kit application, I happened to view the page source in Mozilla browser and noticed the following. <div class="" data-view="views/shell" style="" data-active-view="true"> </div> I couldn't ...

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 ...

What is the best way to create an HTML5 Range that gracefully degrades?

I want to incorporate the <input type='range' /> element from HTML5 for modern browsers and fallback to a <select /> if needed. Since I am working with Ruby-on-Rails, as a last resort, I could implement something similar to this on th ...

The expected response from CSS3 animated images may not be fully realized

I've been working on this project with 4 images. While hovering over one image causes the others to change size as intended, I can't figure out why the ones on the left are not following the same pattern even though I have specified that they sho ...

Can you please provide instructions on how to implement an ng-repeat loop within an HTML table?

<thead> <tr> <th ng-click="sortData('firstname')"> Firstname <div ng-class="getSortClass('firstname')"></div> ...