Whenever I incorporate a media query in my CSS, I find that I am losing some of the stylings

Recently, I've started using media queries in my application to ensure that the webpages are responsive. It's a new concept for me and I'm still learning how to properly implement it. Below is an example of how I am incorporating media queries into my CSS:

@media screen and (min-width: 70em) {
div.MoreInfoterms {

    width: 800px;
    margin-right: 250px;
    margin-left: 55px;
    margin-top: 20px;
    border: 1px solid #cecece;
    background-color: #f7f9f9;
    max-height: 700px;
    margin-bottom: 20px;
}
}

And this is the corresponding HTML code:

<div class="MoreInfoterms">
        <ul>
            <li> <p> This App has no minimum term.</p> </li>
               <li> <p>This App has no minimum term.</p> </li>
                <li> <p>This App has no minimum term..</p> </li>

        </ul>
    </div>

http://jsfiddle.net/isherwood/LBuTj

I've encountered an issue where when the browser window is minimized and the media query comes into effect, only the contents are displayed without any styles. I would greatly appreciate any assistance in resolving this problem.

Answer №1

When this condition is met

@media screen and (min-width: 40em) 

The styles will be applied to the elements if the browser size exceeds 40em. To apply the opposite effect, you can either remove the styles from the media query declaration or create a new one:

@media screen and (max-width: 40em) 

To see an example, check out this demo http://jsfiddle.net/LBuTj/2/

Answer №2

I've transferred this content to a JSBin for better visibility of the query responses in the output. Your CSS is specifically targeting viewport widths greater than 40em, applying styles only within that range. Styles are not applied for viewport widths below 40em.

Answer №3

Styling with CSS:

@media screen and (max-width: 70em) { //consider using (max-width: 400px/ or any preferred size.)

    div.MoreInfoterms {

          width: 800px;
          margin-right: 250px;
          margin-left: 55px;
          margin-top: 20px;
          border: 1px solid #cecece;
          background-color: #f7f9f9;
          max-height: 700px;
          margin-bottom: 20px;
    }

}

It is advised to utilize px instead of em for media queries definition.

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

Changing React Phone Number input field's default style: A step-by-step guide

Is there a way to modify the appearance of the react-phone-number-input component using this npm package: https://www.npmjs.com/package/react-phone-number-input? I am working with React Hook Form and Tailwind CSS alongside this component. However, I' ...

Django CSS not loading properly on webpage after initial load

I am having trouble understanding why the main.css file is not loading properly in my Django project. I am using the skeleton boilerplate and trying to change the background color, but the changes are not reflecting on the webpage. It's strange becaus ...

Lines running horizontally on either side of the text

I recently found a helpful solution on Stack Overflow, but it's not exactly what I'm looking for due to two main reasons: I am unsure how to adjust the width of the lines to make them shorter. The solution uses H2, however, I have already d ...

Implementing a Class Addition Functionality Upon Button Click in AngularJS

I have a form that initially has disabled fields. Users can only view the information unless they click the edit button, which will enable the fields with a new style (such as a green border). I want to add a class to these fields that I can customize in m ...

Is there a way for me to position my chat messages on the right side in the chat room?

I have a react chat application and I'm looking to customize the appearance of my messages. Currently, all entries with an orange vertical bar belong to me and are displayed on the left side of the chat room. I would like to move them to the right sid ...

Alter the URL and CSS upon clicking an element

Currently, I am faced with a challenge on my website where I have multiple pages that utilize PHP to include content and jQuery to toggle the display of said content by adjusting CSS properties. However, I am encountering difficulty in implementing this ...

Different sizes of CSS tables

Creating a responsive layout involves displaying <div> boxes within a grid: The six individual boxes on this page are placed in a row within the HTML source: <div class="control"> <div class="controlContent"> <a>VARIABLE-HEIGHT CO ...

Navigational elements, drawers, and flexible designs in Material-UI

I'm working on implementing a rechart in a component, but I've encountered an issue related to a flex tag. This is causing some problems as I don't have enough knowledge about CSS to find a workaround. In my nav style, I have display: flex, ...

Issue with Bootstrap DIV not extending to full height when applying background-color

I have encountered numerous posts on this topic, but none of the solutions provided have worked for me. I must admit that I struggle to grasp CSS concepts, although I am making an effort to learn. Here is the code I am currently using: <!DOCTYPE html& ...

What steps can I take to properly center and repair my web page that is currently a mess

This web page I'm working on is giving me a headache. The #titlediv just won't center and the navbar keeps disappearing randomly. It seems like a big issue that I can't wrap my head around. If anyone out there can help salvage it, here' ...

Tips for positioning bootstrap dropdowns side by side in a row

I'm having trouble aligning my li items in a Bootstrap dropdown next to each other. I've tried everything but nothing seems to work. Here's my code: <nav class="navbar navbar-expand-lg navbar-light bg-light"> < ...

The radio button default selection is checked, but the desired styles are not being applied

My webpage features two radio buttons, "No" and "Yes," with the default selection being "No." I have implemented CSS styles for the checked elements, but they only work once physically selected. My goal is to apply these styles immediately on page load wit ...

Can the `lang` attribute be used in a `style` tag to specify the CSS preprocessor language for VueJS? Are there any disadvantages to using this method?

Occasionally, I notice people incorporating code like this: <style lang="scss"> ... </style> <style lang="stylus"> ... </style> I checked the documentation for the style tag and found that lang is not a valid a ...

Using CSS to enforce a specific height for text by overflowing its parent container horizontally

I have a lengthy phrase that takes up too much space on mobile devices. Here is an example: .artificial-phone-viewport { width: 320px; height: 500px; border: 1px solid darkgrey; } .container { width: 100%; height: 100%; } .text { /* * Do ...

Is it possible to enable auto-completion for IDs in a separate CSS file using WebStorm 7?

I am new to using WebStorm 7 and currently working on building a simple HTML/CSS website. Initially, I included my CSS within the HTML file using the style tag, but now I have decided to move it to a separate file. Auto completion is functioning for all h ...

Switch list items with more than a quantity of 3

I have a set of unordered list items that I want to display only the first 3 li elements for each when loading. Upon clicking the + sign, the remaining list items should toggle visibility for just that specific list group. While this can potentially be ach ...

Is it possible to change the style of the current page in PHP using the ?page href method?

Currently, I am facing an issue with styling in my code. Specifically, I want to style the page numbers that are currently open or active. For example, if a page is open, I would like its corresponding number to be displayed in a different color or style. ...

Aligning the <div> list to the center of the webpage

Is there a way to center this list element on the page? It consists of three boxes that are all the same size, and I want them to always remain in the middle. body { width: 100%; } .boxes { display: block; margin: 0 auto; } .box-container ...

Is it possible to apply a CSS transform without erasing the existing transform?

Looking for a solution: elem transform translateY(5px) scale(1.2) I want the element to move down an extra 5px on hover elem:hover transform translateY(5px) Is there a way to achieve this without knowing the previous state of the transform? Appr ...

Creating a Background Image Using CSS3: A Step-by-Step Guide

Hey there! I'm trying to figure out how to recreate the image attached using CSS3. I've tried a few online tools for generating gradients, but no luck so far. :( I have the original image, but I really want to create the background using CSS3 in ...