Mobile media screen overrides CSS styles

I'm having an issue with my layout where the media screen for mobile is overriding my main CSS. On a laptop, the layout shows an orange color, but on mobile, it switches to yellow. Here's a snippet of my code:

  
/* main container */

#resume {
    padding: 1rem;
    margin-top: 2rem;
    background-color:silver;
}

.parent {
    display: flex;
    flex-flow: column nowrap;
    background-color:yellow;
}
  

/****************
*      PHONE
****************/

@media screen and (min-width: 460px) {
  #resume {
    width: 95%;
    margin: auto;
  }
  .display {
    max-width: 180px;
  }
  .child {
    flex: 100%;
    background-color:orange;
  }
  .topper {
    order: -1;
  }
}
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta content="width=device-width, initial-scale=1.0, user-scalable=no" name="viewport">
  <title>Steve</title>
  <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
  <link href="style.css" rel="stylesheet">
</head>

<body>
  <div id="resume">
    <div class="parent">
      <div class="child wider">
<header class="clear" id="header">
      <div>
        <h1 class="name">Steve</h1>
        <h2 class="label">Programmer</h2>
      </div><span class="location"><span class="address">2712 Broadway St,</span> <span class="postalCode">CA 94115,</span> <span class="city">San Francisco,</span> <span class="region">California</span> <span class="countryCode">US</span></span>
      <div id="contact">
        <div class="website">
          <span class="fa fa-external-link"></span> <a href="http://richardhendricks.com" target="_blank”>http://richardhendricks.com</a>
        </div>
        <div class="email">
          <span class="fa fa-envelope-o"></span> <a href="mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="eb998288838a998fab9d8a87887e92c5888486">[email protected]</a>"><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="99ebf0faf1f8ebfdd9eff8f5f5fce0b7faf6f4">[email protected]</a></a>
        </div>
        <div class="phone">
          <span class="fa fa-mobile"></span> <a href="tel:(912)%20555-4321">(912) 555-4321</a>
        </div>
      </div>
      <div id="profiles">
        <div class="item">
          <div class="username">
            <span class="fa fa-twitter twitter social"></span> <span>neutralthoughts</span>
          </div>
        </div>
        <div class="item">
          <div class="username">
            <span class="fa fa-soundcloud soundcloud social"></span> <span class="url"><a href="https://soundcloud.com/dandymusicnl" target="_blank">dandymusicnl</a></span>
          </div>
        </div>
      </div>
    </header>        
      </div>
      <div class=" child topper">
        2
      </div>
    </div>
    
  </div>
</body>

</html>

Answer №1

When designing for mobile screens, it is recommended to use MAX-width instead of min-width in CSS. You can achieve this by:

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

This CSS code will be effective when the screen width is less than 460px.

Answer №2

Due to the fact that your code functions on desktop and the media query is located below in the file, it will be executed afterwards

Give this a try

/* main container */


/****************
*      PHONE
****************/

  #resume {
    width: 95%;
    margin: 0px auto;
  }
  .display {
    max-width: 180px;
  }
  .child {
    flex: 100%;
    background-color:orange;
  }
  .topper {
    order: -1;
  }

@media screen and (max-width: 460px) {
  #resume {
    padding: 1rem;
    margin-top: 2rem;
    background-color: silver;
  }
  .parent {
    display: flex;
    flex-flow: column nowrap;
    background-color: yellow;
  }
}
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta content="width=device-width, initial-scale=1.0, user-scalable=no" name="viewport">
  <title>Steve</title>
  <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
  <link href="style.css" rel="stylesheet">
</head>

<body>
  <div id="resume">
    <div class="parent">
      <div class="child wider">
        <header class="clear" id="header">
          <div>
            <h1 class="name">Steve</h1>
            <h2 class="label">Programmer</h2>
          </div><span class="location"><span class="address">2712 Broadway St,</span> <span class="postalCode">CA 94115,</span> <span class="city">San Francisco,</span> <span class="region">California</span> <span class="countryCode">US</span></span>
          <div id="contact">
            <div class="website">
              <span class="fa fa-external-link"></span> <a href="http://richardhendricks.com" target="_blank">http://richardhendricks.com</a>
            </div>
            <div class="email">
              <span class="fa fa-envelope-o"></span> <a href="mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d3a1bab0bbb2a1b793a5b2bfbfb6aafdb0bcbe">[email protected]</a>"><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ddafb4beb5bcafb99dabbcb1b1b8a4f3beb2b0">[email protected]</a></a>
            </div>
            <div class="phone">
              <span class="fa fa-mobile"></span> <a href="tel:(912)%20555-4321">(912) 555-4321</a>
            </div>
          </div>
          <div id="profiles">
            <div class="item">
              <div class="username">
                <span class="fa fa-twitter twitter social"></span> <span>neutralthoughts</span>
              </div>
            </div>
            <div class="item">
              <div class="username">
                <span class="fa fa-soundcloud soundcloud social"></span> <span class="url"><a href="https://soundcloud.com/dandymusicnl" target="_blank">dandymusicnl</a></span>
              </div>
            </div>
          </div>
        </header>
      </div>
      <div class="child topper">
        2
      </div>
    </div>

  </div>
</body>

</html>

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

Ensure that the class is consistently assigned with identical col-md-* and col-lg-* properties across all instances

Bootstrap 5.2 is my framework of choice for targeting github pages, and here is a snippet of my code: <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" ...

Guide on incorporating a URL link into an <a class=> tag

Working on a Wordpress website, I encountered an issue in the widget section where I can't get any URL code to work! Here is the current code snippet; [one_third] <a class="home-buttons" href="http://example.com/mortgage-calculator"><i clas ...

Styling the <nav> element with CSS

Why is the CSS property not applying to the <nav> element? Are we unable to style these specific Bootstrap tags on our own? If it is possible, how can we achieve this? nav{ display: none; } <link rel="stylesheet" href="https://stackpath.boot ...

Desktop media queries are functioning properly, yet experiencing issues on mobile devices

I've come across this same question multiple times, but the solutions I've found so far haven't been helpful. My media queries are working perfectly on desktop, but they don't seem to take effect on three different android devices. It&a ...

Adjusting the dimensions of a Twitter widget to fit the screen size

My website is designed to resize based on screen size, but I encountered an issue when adding a Twitter widget. Despite setting the attribute width:'auto', the widget did not resize properly. Below is the code for the widget: <script charset= ...

Struggling to grasp the concept of fit-content? Let me

For my personal project, I am creating a simple react webpage. To incorporate zoom capabilities, I decided to use the library called React-zoom-pan-pinch. Initially, without implementing this library, my SVG element filled the screen in red, which was the ...

Tips for maintaining the default arrow icon for HTML select elements

While styling a drop down in Firefox on Mac OS X, I noticed that the arrow changes from the standard look to an unattractive downward arrow. How can I maintain the standard form element with the appealing up and down arrows, instead of the unsightly downwa ...

Preventing Adjacent Text from Moving Due to a Floated i Element

I have a div with a bootstrap icon positioned at the top right corner. However, I want to center the text horizontally without shifting the position of the icon. Is there a way to achieve this? See my sample code here: https://jsfiddle.net/x1Lvyu6t/3/ ...

Adjust the CSS styling to ensure that the div or iframe expands to fit the entire height of the

Having trouble making a map embedded via an iframe on a WordPress page display responsively at full height independent of the device? Check out: . To clarify, by full height, I mean that the bottom of the map should not extend beyond the screen, eliminati ...

Unable to modify the appearance of text on the canvas

Trying to customize the font style of canvas text with Press Start 2P The URL has been imported into a CSS file as follows: @import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap'); .canvasClass{ font-family: ...

Obtaining visuals in a specific manner

I have a customized slider (flexslider) with 10 images per slide. The images are currently manually inserted, but I want to optimize the slider to dynamically extract images using PHP. However, my current setup only displays one image per slide. How can I ...

Layer divs on top of each other without explicitly defining their stacking order

I am looking to stack multiple tile divs on top of each other by using negative margin-right: -10px. My goal is to have the previous div displayed on top, with new sibling divs appearing below it. Currently, the newer div overlaps the previous one. While ...

Techniques for Adding Background Color to Fieldset Border

Recently starting to learn HTML and stumbled upon a question: How can I create a background color or image for a field set border? Can I simply use regular color values, or do I need special codes for creating a background color in a field set? Any insig ...

Creating an svg ring using css: a step-by-step guide

Is there a way to create a ring in an SVG using CSS? I have the desired shape using a polygon, but I am looking for a method to achieve the same effect with a ring: clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%, 0 0, 6vh 0, 6vh 61vh, 44vh 61vh, 4 ...

Updating div width in Laravel blade using expressions or jQuery can be a simple task

Is there a way to dynamically change the width value of a div element based on a variable? The div contains blocks, and the size of each block is determined by the variable. For example, if $t->spotdiff = 2, I would like two equal blocks in a column wit ...

Tips for effectively utilizing the :valid pseudo-class in Material-UI components to dynamically alter the border styling

Currently, I am attempting to adjust the border color of Mui TextFields using createTheme from Mui v5 when the input is valid. The border itself is defined within the ::before and ::after pseudoclasses. For the TextFields, I am utilizing variant="stan ...

Adjusting font sizes based on window dimensions

I am currently in the process of building a website that requires the inclusion of images along with corresponding headings and descriptions. When viewing the website in full screen, the heading displays on a single line. However, as the browser width decr ...

Restricting Options in jQuery/ajax选择列表

Although there are similar questions posted, my specific issue is that I am unsure of where to place certain information. My goal is to restrict the number of items fetched from a list within the script provided below. The actual script functions correct ...

Develop and arrange badge components using Material UI

I'm new to material ui and I want to design colored rounded squares with a letter inside placed on a card component, similar to the image below. https://i.stack.imgur.com/fmdi4.png As shown in the example, the colored square with "A" acts as a badge ...

Finding the perfect label for effective web scraping with rvest

I am struggling to identify the correct tag to extract the specific text from a webpage. The HTML snippet in question is provided below. The text I am aiming to scrape is "Melbourne Storm has achieved 4 tries Brisbane Broncos has achieved 2 tries" Despite ...