Issues with CSS not applying to smaller page sizes when using @media queries

My website was created using bootstrap and CSS. I have a list displayed on the side in a normal screen size, such as on a computer or laptop. However, when the screen size is reduced to less than 500px (mobile), I want the list to drop to the bottom of the page.

To achieve this, I used the bootstrap class hidden-md-down to remove certain divs when the page collapses, which has been working great so far.

You can view an example on CodePen here: https://codepen.io/anon/pen/qwZxbm. In the example, the bottom photo disappears on smaller screens due to a bootstrap class being used to hide it. However, the list does not drop all the way to the bottom of the page as intended.

Here is a snippet of the sidebar on the page:


    <div class="row">
                <!-- Sidebar -->
                <div class="col-sm-4">
                    <div class="sidebar">


                        <div class="sidebar-section">
                            <h5><span>Post</span></h5>
    <a href="#"><img src="#" title="new" alt="photo"></a>
                        </div>

<div class="hiddenmobile">
                        <div class="sidebar-section">
                            <h5><span>Latest Blog Posts</span></h5>
                            <?php foreach($posts as $post): { ?>
                            <ul style="list-none;">
                                <li><strong><a style="color:lightgreen;" target="_blank" href="<?php echo site_url('/Blog/'.$post['slug']);?>"><?php echo $post['title']; ?></a></strong></li>
                            </ul>
                            <?php } endforeach; ?>
                        </div>
</div>

                        <div class="sidebar-section hidden-md-down">
                            <h5><span>Photo</span></h5>
    <a href="#"><img src=“#” title="new Gift Ideas" alt="photo"></a>
                        </div>
                    </div>
                </div>

CSS The @media query doesn't seem to be working properly to move the div with class 'hiddenmobile' to the bottom of the page.

@media(max-width: 575px) {
  .hiddenmobile{
    display: flex!important;
    flex-direction: column-reverse!important;
  }
}

Answer №1

In order for your media query to function correctly, you will need to make the necessary adjustments:

@media screen and (max-width: 575px)

UPDATE: To ensure that the block moves to the bottom at a specific resolution, here is one of the various options available to you:

.sidebar {
  display: flex;
  flex-direction: column;
}

@media screen and (max-width: 575px) {
  /* Consider replacing this class with one that suits your block better */
  .hiddenmobile { 
    order: 1;
  }
}

By using the order property, you can determine the position of the desired block. If other blocks do not have this property, then the respective block will be placed at the bottom.

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

Issue with nivo-lightbox not opening upon clicking image

I have diligently followed the instructions to set up this JavaScript plugin, but unfortunately it doesn't seem to be functioning properly. The plugin I'm using can be found here: All the links to the CSS, theme, and JavaScript files are display ...

Arranging rows and columns in Bootstrap 3 for small screens

My layout is structured as follows: <div class="container"> <div class="row"> <div class="col-md-8> <div class="row"> <div class="col-md-12"> box 1 & ...

What is the best way to encode and split audio files so that there are no gaps or audio pops between segments when I put them back together?

In my current project, I'm developing a web application that involves streaming and synchronization of multiple audio files. To accomplish this, I am utilizing the Web Audio API in conjunction with HTML5 audio tags to ensure precise timing of the audi ...

Tips for substituting @media (max-width) with Stylish or Greasemonkey?

I am encountering an issue when trying to access this specific website on my desktop browser. The site has a responsive/fluid design that switches to displaying a mobile menu button instead of a horizontal nav-bar when the browser width is less than 990px. ...

Tips for displaying a div element alongside a button within a reactJS table

How can I position a div element next to a button in a ReactJS table? I have a table component where I want to display some options in a small window that closes when clicked outside. Options : https://i.sstatic.net/sT8Oi.png Action button in the table ...

Achieving a full-width image display in Bootstrap: A guide

I've been struggling to find a solution to stretch an image across a div using CSS and Bootstrap. I attempted to make both the div and parent container fluid, but no matter what I try, there always seems to be some white space on the left and right si ...

Click on an element using jQuery to apply a specific class to all other similar

I am looking to dynamically add a class to a DIV after clicking on an A element with the same class. Here is an example: <ul> <li><a href="#1" class="test1">1</a></li> <li><a href="#2" class="test2">2</a>< ...

Leveraging the power of React in conjunction with an HTML template

After purchasing an HTML template from theme forest, I am now looking to incorporate React into it. While I find implementing Angular easy, I would like to expand my skills and learn how to use React with this template. Can anyone provide guidance on how ...

Clustering in an environment requires merging and minifying granules

While Granule is effective for minifying and merging CSS/JS files on a local environment, it presents challenges in clustered environments. The issue arises when each node of the cluster computes its own file during runtime, causing discrepancies when a us ...

"Searching for the index of a clicked element? Here's how to do

I am trying to determine the index of a clicked anchor element in my navigation using jQuery. However, when I use the following code snippet, I always get zero in the console: $('.navigation ul li a').click(function(e) { e.preventDefault(); ...

The addition of one-page navigation in Angular 7 seems to be experiencing some glitches

I recently added a new menu option to my Angular 7 project, but it's not functioning correctly. I used Bootstrap 4 and followed this example from here. Can anyone help me figure out the correct way to implement this? Check out the sample on StackBlit ...

Bootstrap 5's h-100 feature functions flawlessly in Chrome, however, it encounters issues when used with a group

Can you please refer to this question: Issue with Aspect Ratio of Images in Bootstrap 5 due to Padding After applying the h-100 solution, everything looks great on Chrome. Unfortunately, when I check it in Safari, the aspect ratio of the image gets distor ...

Is it possible to load babel-polyfill using <script async> tag?

I have created a modal dialog on my webpage that appears when certain interactions occur. Utilizing React, I used webpack to generate a compact bundle that can be added to my page using a script tag. Since it incorporates Generators and needs to support ...

Ways to tally elements that have been dynamically loaded onto the webpage through AJAX requests

My page has a dynamic region that is continuously updated using jQuery's .ajax and .load methods. In order to submit the form, there need to be at least 3 of these 'regions', so I have to keep track of the number of DIVs with a specific cla ...

Using `margin: auto;` alone will center a div horizontally, but it won't

My goal is to perfectly center the text within the anchors in my li container, both horizontally and vertically. I've come across a method that involves using text-align: center; on the container for horizontal alignment. However, vertical alignment r ...

css determining the width through calculation

I am facing a challenge with a math problem. My content box is 700 pixels wide, and my hentry (inside content) is 100% wide with padding of 10 pixels. This causes the hentry to be wider than the content, resulting in an overflow... Does anyone have a so ...

When using IE8 with pie.htc, implementing html5shiv.js causes rounded corners to disappear once more

While everything is running smoothly in most browsers, there seems to be an issue with IE8. After connecting pie.htc to address the rounded corners problem, everything seemed fine until html5 issues cropped up in IE8. To combat this, I implemented html5shi ...

How to insert an image into a placeholder in an .hbs Ember template file

I'm looking to enhance a .hbs template file in ember by incorporating an image. I am not a developer, but I'm attempting to customize the basic todo list app. <section class='todoapp'> <header id='header'> & ...

Excessive text overflowing in a chat interface can be resolved through CSS styling

After conducting a thorough search, it appears that very few individuals are taking this important element into consideration. I currently have a chat interface set up with a div element containing a ul, which then houses li elements that contain p element ...

Simultaneous opening of several bootstrap collapse panels with a single button press

I have been developing a blog-style web application with Django. My goal is to display all the posts on the home page, with each post containing a collapse panel. Initially, I had hardcoded the IDs to trigger the collapse panels, causing all the panels to ...