When the browser window is minimized, the @media CSS will wrap to the bottom line

When the browser has a standard resolution, the layout looks like this:

https://i.sstatic.net/tNR6X.png

However, on smaller screens, it appears like this:

https://i.sstatic.net/U3RnZ.png

Is there a way to adjust the positioning of these blocks using @media in CSS for users with lower screen resolutions? I'm aiming for something like this:

https://i.sstatic.net/SpJ8y.png

This is my template code:

         <div class="flex-c">

        <div class="jackpot__information" v-if="luckyOfDay">
          <div class="widget widget_jackpot widget_luck">
            <div class="widget__head">
              <div class="widget__title"><i class="icon icon_horseshoe"></i><span> Удача дня </span>
              </div>
            </div>
            <div class="widget__main">
              <a class="widget__photo photo" :href="'/user/' + luckyOfDay.winner.uid">
                <img class="widget__image image"
                     :src="luckyOfDay.winner.avatar"
                     :alt="luckyOfDay.winner.username">
              </a>
              <div class="widget__information">
                <div class="symbol_usd widget__bank">{{ luckyOfDay.total_bank }}</div>
                <a class="widget__nickname link" :href="'/user/' + luckyOfDay.winner.uid"> {{ luckyOfDay.winner.username }} </a>
              </div>
            </div>
            <a class="widget__chance link" :href="'/jackpot/history/' + luckyOfDay.game_id"> Шанс {{ luckyOfDay.winner_chance }}% </a>
          </div>
        </div>

        <div class="jackpot__last">
          <div class="widget widget_jackpot widget_last_game ng-star-inserted" v-if="lastGame">
            <div class="widget__head">
              <div class="widget__title"><i class="icon icon_clock"></i><span> Пред. игра </span>
              </div>
            </div>
            <div class="widget__main">
              <a class="widget__photo photo" :href="'/user/' + lastGame.winner.uid">
                <img class="widget__image image"
                     :src="lastGame.winner.avatar"
                     :alt="lastGame.winner.username">
              </a>
              <div class="widget__information">
                <div class="symbol_usd widget__bank">{{ lastGame.total_bank }}</div>
                <a class="widget__nickname link" :href="'/user/' + lastGame.winner.uid"> {{ lastGame.winner.username }} </a>
              </div>
            </div>
            <a class="widget__chance link" :href="'/jackpot/history/' + lastGame.game_id"> Шанс {{ lastGame.winner_chance }}% </a>
          </div>
        </div>

      </div>

This is my CSS code:

.widget_luck {
    position: relative;
    width: 164px;
    height: 150px;
    padding: 18px 20px;
    background-color: #213137;
    border-radius: 10px
}

(... CSS styles continue)

@media (min-width:1600px) {
    .widget_luck .widget__title {
        font-size: 15px;
        line-height: 16px
    }

    .widget_luck .widget__chance {
        font-size: 13px;
        line-height: 35px
    }
}

(widget_last_game CSS styles and media queries are similar...)

I have attempted various methods of utilizing different @media css declarations where the dimensions are predefined, but none have been successful for me. If you can provide guidance, I would greatly appreciate it!

Answer №1

Here is an illustration showcasing the use of css-grid in tandem with media queries.

body {
  margin: 0;
  padding: 20px;
  display: grid;
  grid-gap: 20px;
}

@media only screen
  and (max-width: 480px) {
    body {
      grid-template-columns: repeat(2, 1fr);
    }
}

@media only screen
  and (min-width: 481px) {
    body {
      grid-template-columns: repeat(4, 1fr);
    }
}

.grid-span-2 {
  grid-column: span 2;
}

div {
  border: 1px solid black;
  padding: 5px;
}
<div class="grid-span-2">Widget 1</div>
<div class="grid-span-1">Widget 2</div>
<div class="grid-span-1">Widget 3</div>

This example features 3 boxes/widgets arranged as depicted in your design. These items align horizontally if the screen width is 481px or higher, splitting the body into 4 columns. The first widget consistently spans 2 columns.

If the screen width falls below 481px, the body contracts to 2 columns. Consequently, the second and third boxes/widgets drop to a new row since they can no longer fit side by side in the initial row.

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

Change the colors of a dynamic row in an HTML table using various options

I have successfully implemented a dynamic table using HTML and JavaScript. However, instead of applying alternate row colors, I want to assign a unique color to each row. How can I achieve this? <!DOCTYPE HTML> <html> <head> ...

When scrolling, the selected text does not maintain its correct position

I'm looking to enable my users to search by selecting text. Once they select text, a new button will appear on the right side of the selected text giving them the option to search or not. However, when the user scrolls to the bottom of the page, the p ...

design and construct a three-dimensional shelving unit

After much searching and failed attempts, I am determined to create a stationary cube-shaped bookcase using CSS. Can anyone offer some guidance on how I can achieve this? I have included an image of the design I want to replicate. Thank you .scene { ...

What steps should I take to ensure that clicking this button triggers the API request and returns the data in JSON format?

I'm attempting to have the button with id 'testp' return an api request in json format, however it seems to not be functioning properly. You can find the HTML code link here: https://github.com/atullu1234/REST-API-Developer-1/blob/main/js-bu ...

Tips for customizing the appearance of popup windows

I want to enhance the appearance of my popup window by applying a different format for opening it. How can I style it so that it looks visually appealing when the popup window opens? You can find below the source code I am working with: HTML: <div onM ...

Guide on validating an Australian phone number with the HTML pattern

When it comes to PHP, I have found it quite simple to validate Australian phone numbers from input using PHP Regex. Here is the regex pattern I am currently using: /^\({0,1}((0|\+61)(2|4|3|7|8)){0,1}\){0,1}(\ |-){0,1}[0-9]{2}(\ | ...

Are inline styles being utilized in a Styled component?

I'm currently utilizing styled-components within a React project and I am having trouble finding documentation regarding whether or not a styled component can accept inline styles on the "style" property. For example: The Text component has been styl ...

The background of the wrapper div refuses to expand beyond the original size of the browser window

I'm currently in the process of developing a website, focusing on establishing the fundamental structure of my design to facilitate the addition of content and allow for the dynamic expansion of the div based on the length of the content. Nevertheless ...

The appearance of HTML varies depending on the type of mobile device being used

My email template is having display variations on different mobile devices, with the textbox sometimes centered instead of left aligned as intended. Any suggestions on what might be causing this issue and how to resolve it? Desired Display on All Devices ...

Do you require a lightbox for a white text box set against a semi-transparent black background?

Currently, I am in the process of developing a Chrome extension that will be compatible with my Android app. As part of this development, I need to code the HTML/CSS for the extension. The main functionality of the extension allows users to add tags to a s ...

Can the presence of buttons and links improve mobile responsiveness?

I can't help but wonder about this. Is it user-friendly to create a div that looks like a button and has a 'click' event attached to it? Will all mobile browsers handle it accurately and always trigger the event when the div is clicked? In t ...

What could be the reason for meteor not injecting the text from my template helpers?

My goal is to dynamically generate a table displaying two different sets of data. Despite having verified returns from my database, the rendered page does not show the corresponding HTML elements as expected. Here is the template and HTML code: <templ ...

Transforming Input Background Color with jQuery based on Matching PHP Array Entry

I am looking for a solution to implement form validation in PHP. The form has 3 fields: user, id, and email. When a user enters their name or id in the respective input fields, I want to check if the entered value matches any of the values in the PHP arra ...

How can I pass an Objective-C object to JavaScript?

Currently, I am working on a UIWebView project that involves HTML and JavaScript. One of my friends is working on something similar but for Android. The challenge I'm facing is that in Android, there is a simple way to send an Android object to JavaS ...

What could be causing the div to be wider than the content inside of it?

I am having an issue creating a webpage with a 20-60-20 flex fill layout. The div in the center, which should occupy 60% of the page, is wider than its content, causing it to appear off-center. https://i.stack.imgur.com/WwCJy.png Here is my home.componen ...

What is the method for altering the background color of an input field upon entering text?

As a beginner in Javascript and jQuery, I am struggling to understand why my code is behaving the way it does. I have written two similar functions aimed at changing the background color of an input field. The objective is to set the background color of t ...

Scraping a website where the page source doesn't match what is displayed on the browser

Imagine I'm interested in extracting marathon running time data from a specific website: Upon inspecting the webpage using Google Chrome, I noticed that the desired data is not directly visible in the page source. Although I have successfully scraped ...

Is there a way to deactivate a full HTML page during an event, similar to when using a JavaScript alert?

I'm currently working on a JSP/HTML web page where I need to disable or "gray out" the entire page when a button is clicked. This will prevent the user from accessing any other elements on the page until it's disabled. Any ideas on how to achiev ...

Prevent the ability to add options dynamically to a drop-down select list

I have implemented a dynamic data retrieval feature from my database using jQuery's .getJSON function and appended the data to an HTML select drop-down list. The JavaScript code for this functionality is as follows: $.getJSON('url', f ...

Tips for organizing HTML logic in a separate document

I am faced with the task of displaying a list in HTML based on specific conditions: <!-- Display list if there are more than 5 results --> <div list.numberOfResults > 10"> <b>Name: </b>{{list.name}} <b>ID ...