Dynamic, adaptable, and expandable tiles that effortlessly span the full width of the screen

Trying to design fluid and flexible "tiles" for a website, which should expand across 100% of the browser viewport. The goal is for them to adjust in size if necessary to fill any white space gaps left by unfitted tiles.

Using a standard div tag with a min-width and min-height of 200px, set to "display: inline-block," solves most of the issue. As the browser window widens, the tiles will stack up on the top line if there's room for another.

The challenge arises when there's no space for the next tile, resulting in whitespace on the right side. In such cases, I want each tile to 'scale up' to occupy the full width of the line.

For example, if the browser width is 675px, instead of having three 200px-wide tiles, they would resize to 225px each. If you then resize the browser to 800px, there would be four 200px-wide tiles.

I aim to replicate the layout displayed on . Consequently, I'm seeking a CSS-only solution, although I suspect utilizing some JavaScript may be necessary, particularly for handling window resizing. Any suggestions?

Answer №1

To achieve a pure CSS solution, you can utilize media queries in conjunction with percentage-based widths:

.tile {
    /* Display 4 tiles per row */
    width: 25%;
}

@media (max-width: 500px) {
    .tile {
        /* Adjust to display 3 tiles per row */
        width: 33.33333333332%
    }
}

@media (max-width: 300px) {
    .tile {
        /* Change to show 2 tiles per row */
        width: 50%
    }
}

Check out this fiddle for a visual representation of the CSS approach: http://jsfiddle.net/bDBMP/1/

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

Is it possible to have a variable number of dynamic CSS Grid columns with the option of including a header or footer

Implementing a dynamic number of columns with CSS Grid is a breeze. .grid { grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); } // These .cells are beautifully aligned <div class="grid"> <div class="cell"></div> ...

Enhancing Tapestry Grid component column sort icons

In the Tapestry Grid components, the default column sort icons are blue and white, but if your page has a different color scheme, you may want to personalize them. How can you replace the default Tapestry Grid column sort icons with your own custom icons? ...

Enhance navigation in your HTML5 iPad app with a swipe effect for seamlessly transitioning to the next page

I am in the process of creating a mobile application for browsing products offline on the iPad. The application will be developed using HTML5 / JS and will feature offline image caching and local storage. One of the key features I want to include is swipe ...

Limiting the scrolling capability within a flex container by using the nowrap

When using flex with nowrap, it appears that the horizontal scroll bar only allows moving to the right while the items on the left remain hidden. To demonstrate this issue, I have created a sample on CodePen: http://codepen.io/anon/pen/QpgvoZ This behavio ...

Differentiate input elements with custom styling

I'm experiencing an issue while trying to style a specific form field in Angular 7. The style doesn't seem to be applying properly. Below is my form structure: <ul> <li> <mat-form-field *ngIf="number"> <input ma ...

What is the best way to show a background color on a heading?

I am new to website design and I have successfully created a slideshow. However, I am facing an issue with applying a background color to the heading so that it stands out over the image. Despite setting the background color in the CSS, it is not displayin ...

Creating a table with a fixed width that matches the dimensions of a textarea

Is it possible to have a textarea box with fixed dimensions, followed by a table of the same size that does not dynamically resize when the window is resized? I attempted to achieve this by styling the table with table{ table-layout: fixed; width: 100px; } ...

One way to change the cursor CSS property is by dynamically altering it based on scrolling behavior. This involves modifying the cursor property when scrolling

I'm attempting to adjust the cursor property within an Angular function. The issue I'm facing is that when I begin scrolling the webpage, the cursor changes to a pointer, but when I stop scrolling, it remains as a pointer. I've attempted to ...

What is the process for combining AngularJS filters?

I currently have a fragment object like this: [{id: 721, titulo: "Cotizador Gastos Médicos Bx+ 2019", descripcion: "Cotizador Gastos Médicos Bx+ Tarifas 2019", updateDate: "2020-03-25 14:30:22.0", idCategoria: "1", …}, {id: 88, titulo: "Cotizador GMM ...

Creating PDF files with PDFkit in Node.js while rendering HTML data

I am looking for a way to generate a PDF file using the 'PDFkit' library. The data is being retrieved from a MySQL database, and some of the content includes HTML tags. However, when I try to render the HTML data to PDF using the 'html-to-te ...

Step by Step Guide to Creating Vote Tallying Buttons with XHTML

I'm trying to create a voting system where users can choose between two images. However, all the tutorials I've found focus on text or check-box options. How can I make clickable buttons tally votes for each image and then display the results on ...

Is your browser displaying dimensions different from the ones specified in the CSS?

On my webpage, I have defined the header and leftpane as div. The specified height of header is 116px, and the width of leftpane is 181px. However, upon inspecting the page using chrome-developer-tool, the displayed height and width are 98.36px and 165.41p ...

Bootstrap 5 alert: The function `$(...).carousel` is not recognized

Despite browsing through numerous similar questions, none of the solutions seem to work for my issue. Listed below are some points I have checked: Jquery is loaded before bootstrap Bootstrap libraries are up to date Confirmation that bootstrap.min. ...

CSS Code That Is Ineffective

Having some trouble with creating a hidden background that will still show up but not on the main content page. I'm looking to have a different background for the main content itself, but for some reason it's just not working. The main background ...

Despite adding a content security policy within the meta tag of my HTML, the policy does not seem to be properly enforced

I have implemented the Content Security Policy within the HTML meta tag <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initia ...

It displays the PHP code as a comment rather than executing it

I am encountering an issue with my PHP code. Instead of processing the code, it is treating it as a comment. Interestingly, when I used ?php instead of ?, the website doesn't even recognize the code as a comment. What could be causing this issue? < ...

Using a border-radius on Internet Explorer 11 reveals the background through the corners

Encountering issues with rounded borders in IE 11 (11.0.9600.18350)? Check out this minimal fiddle for more information: https://jsfiddle.net/7phqrack/2/ Here's the HTML code snippet: <div class="backgrounddiv"> <div class="outer"> ...

Obtain the script's event feedback from the WebView and transfer it to React Native

My HTML script is used to display a module, but I encountered an issue with the eventHandler not responding. How can I ensure that the eventHandler in Web View triggers responses? I am not receiving any logs for the onSuccess, onError, or onClose methods w ...

What are some creative ways to design nested flexboxes?

I'm currently working on creating a navigation bar using two nested flex boxes within one parent container. However, I'm facing difficulty in styling the inner flexbox without impacting the main container items. Here is how my layout is supposed ...

Troubleshooting a JavaScript function's ineffectiveness when triggered by clicking an

What is causing the function to not work properly when I click on the "Rate me" button? function increaseValue(){ var rate = parseInt($("#rateme").value, 10); rate = isNaN(rate) ? 0 : rate; rate++; $("#rateme").value = rate; } <scr ...