In an effort to become mobile friendly I have implemented a media query kindly suggested by @cch. It hides the "aside" (sidebar) effectively, but fails to expand the "article" (main) into the resulting empty space in all browsers and on all devices. What am I doing wrong?
CSS followed by HTML below:
@media screen and (max-width: 750px) {
aside { display: none; }
article { width: 100%; }
}
#main {
width: 58%;
float: left;
margin-left: 2%;
}
#sidebar {
float: left;
width: 34%;
margin-left: 4%;
}
<article id="main">
<h2>The Advanced ON-SITE Advantage</h2>
<p>As a service for maintaining shades, shutters, blinds, and drapes through occasional cleaning and repair, you can be confident we're supremely qualified. </p>
<p>Correct identification of the many fabrics and coatings used in draperies, shades and top treatments is critical to safe, yet effective, cleaning of these items. Advanced On-Site is certified to do just that. It's why we're able to <a href="guarantee.html">guarantee</a> against shrinkage or damage.</p>
<p><span class="centered">
<figure>
<img src="images/cleaninstall.jpg" width="400" height="225">
<figcaption>Flawless cleaning and installations</figcaption>
</figure>
</span> Likewise, window coverings installed by Advanced On-Site do not suffer from poor funtionality due to improper installation. Only the best materials and fasteners are used, and great care is taken to ensure that every component enjoys the complete freedom of movement imperative to long life.</p>
</article>
<aside id="sidebar">
<h2>Tip</h2>
<p>Window coverings are often damaged through incorrect operation. The following suggestion will increase life expectancy.</p>
<blockquote>
<p><strong>Never let go of a cord until you know it has come to rest:</strong></p>
<p>Shades and blinds with modern retractable mechanisms typically use control cord assemblies. These incorporate hard connectors that can damage delicate components on impact. With traditional cord-lock mechanisms, the cord should not be released until its "catch" is engaged. This prevents the bottom-heavy shade from crashing onto the sill.</p>
</blockquote>
<p>Even when the foregoing is observed, sun damage and simple wear may render the occassional repair necessary. If that happens call us.</p>
</aside>
Thanks in advance,
Dave
Media Query Not Working on Mobile Devices If media queries work on desktop and not on mobile devices, then you most likely haven't set the viewport and default zoom. Note: You only need to add one of the code lines above, and usually, the first one does the job.
Media Query for Desktop Not Working You may notice that, although your queries work on mobile devices, they don't work on a desktop computer with a reduced browser window.
Depending on how you layout your site you may need to use more or less queries, as you only need a query for each seperate layout/design of the site. A good choice for basic use would be Smartphone, Tablet, Standard Screen, HD Screen or 4.
Selector #main
has higher specificity than article
, so the width is still 58% even when the media query matches.
Chose a selector with higher specificity for the formatting of article inside the media query; or, if you want one with the same, place the media query below the general formatting.
Also, aside from what CBroe said, make sure you add the following meta tag to ensure consistent results across a range of devices:
<meta name="viewport" content="width=device-width, initial-scale=1">
You can find more about this here:
https://css-tricks.com/snippets/html/responsive-meta-tag/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With