Devs

How to remove and add elements depending on device resolution?

At your request, this article will cover Media Queries, which means using Media Types together with one or more expressions about a media’s characteristics in order to define formatting for different devices. Browsers or applications read the expressions defined in the Query, and if the device in question matches those conditions, the corresponding CSS is applied.

At your request, this article will cover Media Queries, which means using Media Types together with one or more expressions about a media’s characteristics in order to define formatting for different devices. Browsers or applications read the expressions defined in the Query, and if the device in question matches those conditions, the corresponding CSS is applied.

Media Types specify which type of media a certain block of CSS is intended for. HTML was created to be portable—that is, to be read and interpreted by any kind of device. However, each device renders HTML differently due to factors such as screen dimensions (i.e., “resolution”). For example, accessing a site from a desktop will not behave the same way as accessing it from a mobile device, because these are different devices with different browsing contexts.


The challenge with Media Queries today is that more and more devices emerge with varying screen sizes and hardware capabilities similar to desktops, leading them to browse almost like desktop machines. Take the iPhone X as an example: its display quality is superb and its browser renders pages just like a typical desktop browser.

In that case, there’s no need to prepare a layout and CSS specifically for handheld media types on the iPhone—since, although it’s a handheld, it doesn’t behave like one. Yet it also doesn’t behave exactly like a desktop. Even though Safari’s rendering engine is identical to the desktop version, the user’s behavior and navigation patterns still differ. We end up in a middle ground: we can’t provide a completely separate CSS for handheld, nor can we rely solely on a desktop (screen) stylesheet.

Below is how you would define which stylesheet rules should be loaded:


@media screen and (max-width:1024px) {
.small-resolution { display: none; }
}
.small-resolution { display: block; }

Optionally, you can create a separate .css file and host it either on your own server or via my startup’s CDN solution, Blenner SmartCDN. Then, include it in your HTML’s metadata section like this:


Once your CSS file is in place, you simply “call” the class wherever you need the responsive behavior. For example, to apply it to an image wrapped in a custom tag named “C”:



Hope this helps! 😀
Leave your comments below and share with your friends!

Comments

Recommended Posts for You

LGBTQIA+

Check out the full review of Netflix's Heartstopper series and find out if the Heartstopper series delivers everything it promises in full!

Cinema

“One of the most memorable cartoons of the 20th and 21st centuries. Its story, characters and writing are utterly captivating. “Little Bear” is known...

Curiosities

Super Mario World, also known as “Super Mario Bros. 4” in Japan, is without a doubt one of the most popular games of all...

Cinema

“Courage the Cowardly Dog” tells the story of Courage, a dog who’s easily scared and lives on a farm with Muriel and Eustace Bagge...

Cinema

Who doesn’t know this epic cartoon from Hanna-Barbera, Wacky Races, where eleven competitors vied in every episode for the world title of “World’s Wackiest...

Cinema

Sagwa, one of the best cartoons still airing on the Futura channel. In fact, all the shows on Futura are excellent. It tells the...

Cinema

“Do you remember the classic cartoon Timon and Pumbaa? It’s an animated TV series produced by Walt Disney Animation, starring the warthog and meerkat...

Cinema

At the end of the 1930s, animation was at its peak. It was called the “Golden Age” by many film enthusiasts, where classic characters...

Cinema

Woody Woodpecker, one of the most beloved characters of all time. Adored by children, teenagers, and adults alike. The show itself dates back to...

Curiosities

Grand Theft Auto V (GTA V) is known for its vast open-world gameplay, where players can explore, complete missions, or just cause chaos. One...

Others

“Castelo Rá‑Tim‑Bum” premiered in 1994 on TV Cultura, delighting fans of the original “Rá‑Tim‑Bum” who were tired of its reruns, as well as other...

Tech

If you grew up playing console games in the 1980s and 90s and never heard this one, count yourself lucky—very lucky. Here’s the urban...

Cinema

Walt Disney, one of the largest and most influential entertainment giants in the world, has a long history of innovation in animation. From its...

Games

“Nintendo 64” is Nintendo’s third home video game console. Commonly abbreviated as “N64,” it launched on June 23, 1996 (Japan) and on September 29 in the United States....

Games

How about transforming your Minecraft into an even more immersive game? With that in mind, the “Realistico” Mod Pack was developed—a texture pack with...

Games

<iframe width="1665" height="705" src="https://www.youtube.com/embed/Xg5ajToIUoM" title="Just Dance 2016 - Real dancers behind the scenes #1" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>You’ve...

Games

Need For Speed Heat has finally hit the streets and is increasingly reminiscent of the franchise’s golden-era titles, such as Need For Speed Underground...

Games

It's time to talk about Far Cry 4: a new game in the iconic open-world franchise that first arrived over 10 years ago with paradisiacal...

Games

Recently, Plants vs. Zombies Garden Warfare was released—it’s the new game from PopCap, famous for its mobile hits. This time, we have a review...

Devs

The kernel is one of the most fundamental components of any operating system (OS), acting as a bridge between the hardware of a computer...

Copyright © 2025 Juan de Souza - All Rights Reserved. Hosting by TFX.

Exit mobile version