I am encountering issues with the responsiveness of my layout as it is

My goal is to create a responsive layout utilizing code and examples from this website: www.responsivegridsystem.com

To achieve this, I have nested a few containers to ensure a content area of 960px width centered within a 1000px container.

My plan is that when the width is less than 960px, both containers should expand to 100% width. While the layout appears as intended in full size, it does not respond correctly when the width is below 960px.

This is my current CSS (with some adjustments based on recommendations but still not functioning correctly):

.masterContainer {
    position:relative;
    margin:0 auto;
    margin-top:-10px;
    background-color:#FFF;
    width:1000px;
    overflow: hidden;
}
.pageContainer {
    position:relative;
    display:table;
    margin:0 auto;
    width:960px;
    overflow:hidden;
}
/*  SECTIONS  */
.section {
    clear: both;
    padding: 0px;
    margin: 0px;
}

/*  COLUMN SETUP  */
.col {
    display: block;
    float:left;
}
.col:first-child { margin-left: 0; }


/*  GROUPING  */
.group:before,
.group:after {
    content:"";
    display:table;
}
.group:after {
    clear:both;
}
.group {
    zoom:1; /* For IE 6/7 */
}

/*  GRID OF THREE  */
.span_3_of_3 {
    width: 100%;
}
.span_2_of_3 {
    width: 70%;
}
.span_1_of_3 {
    width: 30%;
}

@media only screen and (min-width: 481px and max-width: 960px) {
    .masterContainer {
        width:100%;
    }
    .pageContainer {
        width:100%; 
    }
}

@media only screen and (max-width: 480px) {
    .span_3_of_3 {
        width: 100%; 
    }
    .span_2_of_3 {
        width: 100%; 
    }
    .span_1_of_3 {
        width: 100%;
    }
}

HTML

<div class="masterContainer">
    <div class="pageContainer">
        <div class="section">
            <div class="col span_3_of_3" id="header">Header
            </div>
            <div class="col span_3_of_3" id="slideshowContainer">Slideshow
            </div>
        </div>
        <div class="section group">
            <div class="col span_2_of_3" id="contentArea">
            This is column 1
            </div>
            <div class="col span_1_of_3" id="rightColumn">
            This is column 2
            </div>
        </div>
        <div class="col span_3_of_3" id="footer">Footer
        </div>
        <div class="col span_3_of_3" id="bottom">
        </div>
    </div>
</div>

Could there be an issue with my @media code or did something else go wrong?

Answer №1

Your CSS queries are instructing classes to perform actions, even though your HTML has them designated as IDs. Consider revising it to the following format:

@media only screen and (max-width:960px){
    .masterContainer {width: 100%;}
    .pageContainer {width: 100%;}
}

For demonstration purposes, I have set background colors in the code provided below.

View JS Fiddle with revised code

Answer №2

Based on the information you provided, it appears that there are no @media codes included in your post. It is important to note that if you want your page to be responsive, you should not have specific widths set such as masterContainer width 1000px. Instead, consider revising it like this:

@media (min-width: 700px), handheld and (orientation: landscape) 
{
   .masterContainer{
     width:60%; // or adjust accordingly
   }
}

Take a look at some examples here: https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Media_queries

Answer №3

To make it specific using @media queries, you can do the following:

@media screen and (max-width: 959px) {
    .masterContainer,
    .pageContainer {
        width: 100%;
    }
}

Answer №4

Your CSS is missing media queries.

To handle different screen sizes, consider creating separate files for each and organizing your styles accordingly. This simplifies the process.

For a better understanding of how media queries function, check out this informative article:

CSS-Tricks Media Queries

Answer №5

The issue with the code not functioning correctly lies in this line:

@media only screen and (min-width: 481px and max-width: 960px)
which is an incorrect query.

The correct syntax should be:

@media screen and (min-width: 481px) and (max-width: 960px)

You cannot combine the properties min and max as you attempted to do.

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

Upgrading from Vuetify 2 to 3 involves replacing the deprecated styles like .v-application, rounded, and flat with

I need help with upgrading from Vuetify/Vue 2 to Vue 3. I don't have much experience in front-end development, but I am responsible for updating some old code to keep things running smoothly. The migration guide is not very clear and assumes a certain ...

Multiple Ajax(Jquery method) Submissions with just one click and issue with Image not being sent to the server

Having trouble submitting form data to the server after client-side validation using jQuery. I've been working on this all day and could really use some help. I created a jQuery slider for my login form, where it slides to the next input field after v ...

The menu does not adjust to fit the site properly, causing the video/photos to appear off to the right on smaller screens

Earlier, I received some fantastic help for which I am extremely grateful. However, I find myself in need of your expert assistance once again. The website I am currently working on is . After simplifying the code and removing absolute positioning, I enco ...

Searching for tables data by employing the Curl command

Seeking assistance with parsing data from a website. The JSON request runs successfully in the command line but encounters issues when attempting to execute it on Android: The request: "curl '' -H 'Host: billetterie.ctm.ma' -H &apo ...

Storing multiple HTML elements in a variable with React allows for easy manipulation and

Looking to optimize some repeated code in a React component that renders HTML elements. Trying to save the repetitive html parts in a variable and then return them, but running into issues. const renderAddress = event => { if (event.venue.address.a ...

The arrangement of columns and floating images along with the surrounding white spaces

There are 3 columns, each sized at 33% with images of varying heights inside. When viewed on a device the size of an iPad, I want to change the column sizes to be 50%. However, when I do this, the third column appears in the middle bottom of the top two co ...

The error message for validating my form magically disappears

I've been working on creating a registration form using HTML, Bootstrap, and JavaScript. My goal was to display an error message when a field is left empty, but for some reason, the error message appears briefly and disappears afterwards. I can't ...

Unable to implement CSS styles on the provided HTML code

I'm currently working on integrating evoPDF into my asp.net application. When I click on a part of the HTML file, I send that portion using AJAX. So far, everything is working well up to this point. However, when I try to use the following methods fro ...

Guide to creating a parallax scrolling effect with a background image

My frustration levels have hit an all-time high after spending days attempting to troubleshoot why parallax scrolling isn't functioning for a single image on a website I'm developing. To give you some context, here's the code I've been ...

Tips for altering the color of an image using CSS attributes

I am looking to create a male Head component in this design draft and modify the CSS according to the skin prop. I have attempted to use filter and mix-blend-mode properties, but have not found a solution yet. Any guidance on how to achieve this would be ...

Could you provide some advice for creating a Single Page website?

I am working on a simple HTML setup with various elements such as a navbar and content blocks. <html> <head> <title>My HTML5 App</title> <meta charset="UTF-8"> <meta name="viewport" content="wid ...

utilizing an ajax request to clear the contents of the div

When I click on Link1 Button, I want to use ajax to empty the contents in the products_list div <button type="w3-button">Link1</button> I need help with creating an ajax call that will clear the products in the product_list when the link1 but ...

Retrieve the HTML content of all children except for a specific child element in jQuery

Is there a way to utilize jQuery/Javascript for selecting the HTML content of the two <p> elements in the initial <div class="description? I'm open to using Regex as well. This specific jQuery selection is being executed within Node.js on a c ...

Adjusting the height of a card in Reactstrap

I am currently exploring Reactstrap and aiming to ensure a specific Card adjusts according to the size of the window by setting its aspect ratio using percentages rather than pixels. Interestingly, while adjusting the width works as desired, I'm faci ...

Java Library for Converting HTML to Textile Format

I have a requirement to convert a String from HTML format to Textile format. After researching various libraries such as Textile4J, Textile-J, JTextile, and PLextile, I found that none of them offer the specific functionality I need. Although they do prov ...

A revolutionary approach - Empowering websites with individual scrolling panels

I have a unique design layout that includes a top navigation, side navigation, and content. Both the side navigation and the content sections are taller than the page. My goal is to eliminate the need for a scrollbar for the entire page, but still mainta ...

Retrieving Table Cell Values Using Jquery: A Step-by-Step Guide

<table class="table" align="center" id="tblMain"> <tr> <td>Status</td> <td><b><span name="current" value="Dispatch">Dispatch</span></b></td> </tr> </table> JS $(&apos ...

What's the best way to make sure my table fits perfectly within its container's width?

I've encountered an issue with a table: If you want to see how the table was created, check it out on jsFiddle I attempted to modify the CSS like this : table{ width:100%; } td span { float:right; width:20%; text-align:center ...

Searching for all classes and IDs in a CSS Stylesheet that include a specific keyword

I am currently working with a premium WordPress theme that has an extensive styles.css file consisting of over 25,000 lines. My goal is to make sitewide changes to the font and main color, and in order to do this effectively, I need to identify all classes ...

Customize the default classes for DataGrid in Material UI

Attempting to customize the CSS properties in the "DataGrid" Material UI, specifically adjusting font weight and overflow of the header. Below is the JSX code snippet: import React, {useState, useEffect} from 'react'; import {DataGrid, GridToolb ...