What is the precise functioning of CSS Media Query?

Imagine having 2 separate CSS files, desktop.css and ipad.css, both being used on the same HTML page.

In desktop.css, we have a pseudo div defined like this:

div.someClass{float:left;overflow:hidden;height:100px}

Now, if the user resizes the browser to iPad size and ipad.css is applied, what happens?

Do the properties from desktop.css still apply or are they completely replaced by the properties in ipad.css?

For example, if I want to change the overflow property to 'visible' in ipad.css, do I need to explicitly specify it? Or can I simply define it like this within ipad.css:

div.someClass{float:left;height:100px}

Will the default value of overflow: visible be automatically applied to the div?

Answer №1

@testndtv; make sure to include the overflow:visible property in your ipad.css file. This is essential because the media query will only detect the screen resolution and apply the corresponding css styles based on that. Therefore, we need to override any existing properties in the ipad.css from the activated one.

To update your ipad.css, use the following code snippet:

div.someClass{float:left;overflow:visible;height:100px}

Answer №2

The C in CSS stands for Cascading. When the styles from ipad.css are loaded after and have higher specificity, they will take precedence and be applied.

If a property is not defined in ipad.css but is in desktop.css for the same element (assuming you load desktop.css first), it will default to the rules set in desktop.css.

Answer №3

The way you structure your queries will determine the outcome. It is possible to achieve both methods.

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

The use of Angular directives is restricted to one per page

I'm encountering a small issue with my angularJS directive. I want to display 2 photos in different ways using other HTML codes, but I'm running into a problem where only one directive works per page. The second one only works when I comment out ...

Guide on connecting a CSS file with Python

Currently, I am utilizing Python to send a message via HTML. I would like to enhance the style of the message by implementing CSS. However, when attempting to include the style code directly into the HTML, I encountered issues with curly braces {}. Is it ...

What sets apart the process of sending an AJAX request using a web worker versus sending it directly through the DOM?

Are there any benefits to using a web worker for making an ajax request compared to making it directly within the DOM? ...

The content is unclipped with a border-radius and hidden overflow

As I work on incorporating stylistic text inside rounded divs, I encounter a challenge where the text touches the top of the container. While I have successfully managed to customize various content elements such as nested divs and background images, this ...

Is it possible to arrange the final divs on top of the initial ones without any overlap between them?

I have a script for uploading files that displays all previously uploaded images in divs with the class "download". When I use a jQuery script to add more pictures, it puts them in divs with the class "upload". I want these new uploads to be displayed ab ...

Having difficulty choosing a drop-down menu option with AJAX technology

My current project involves creating a page where the database is updated upon a drag-and-drop event. Specifically, I have implemented drag-and-drop functionality on a page, and whenever a div (deal-card) is dragged and dropped into another div (stage-colu ...

Conceal a certain label using CSS styling for its display name

Can I hide this tag using CSS based on Your text? <a href="/workflow/Lists/users1/AllItems.aspx" >Your text</a> I've tried the following code that works properly: a[href='/workflow/Lists/users1/AllItems.aspx']{ display: none; ...

Techniques for retrieving a specific database field using PHP

Currently, I am in the process of retrieving four unique values from my database. The session variables username and usernameto are functioning properly. However, my goal is to obtain two distinct values from both username and usernameto: <?php s ...

Utilizing negative values in lineTo, strokeRect, and fillRect functions

Is it possible to input negative numbers into the drawing primitives of HTML5 canvas? For instance, if I apply a translation of (100,100), would I be able to draw a rectangle or line with coordinates (-25,-25)? Initial testing using lineTo seems inconclus ...

Turning my dual button navigation into tabs to display distinct HTML pages beneath a designated header

body{ background:url(background.jpg); background-size: cover; } h1{ font-family: 'Dancing Script', cursive; font-size: 5em; color: white; text-align: center; margin-top: 25px; margin-bottom: 20px; } h2{ font-size: 18px; color: white; text-align ...

Challenges with Z-index and layering dynamics

I'm having trouble getting z-index to work. I've searched online but can't find a solution. How can I make the .navigation class have a lower z-index than the .mobilenav and .mobilenavclosed classes so that they appear above everything else ...

Using PHP to Populate HTML Elements Depending on the Attribute of the Parent Class

I maintain a personalized TV schedule that I manually update using a static <table>. Each <tr> consists of 5 <td> elements with the following content in this sequence: date, time, competition, match, and TV channel. <table> <t ...

Web Components Vanish Without Warning

I attempted to insert the HTML code for a button into my main index.html file after a specific line, but I encountered a strange issue. While the button displayed correctly, the homepage of my website suddenly vanished without any explanation. Here is the ...

Generating a new dialog box at the exact location of the user's click

I have a canvas element on my website that allows users to select various items. To offer more choices for what can be done with the selected item, I want to create a small popup with a few options. However, I am running into an issue where I cannot positi ...

How do I adjust the Bootstrap 4 column width to match the size of its content?

I am facing the following situation: [![enter image description here][1]][1] What I want is: Number 1: Adjust the column width to fit the content, in this case the image. Number 2: Resize the column width to accommodate the text "Title of Content" ...

What is the best way to toggle between various modals, each with its own unique content, and also update the

I'm looking to toggle between different models and calculate the results in each form separately. I've been trying to avoid copying too many modal codes and came across a sample HERE, but it uses the same ID, so I'm stuck! If you click on ...

Changing the color of a progress bar in Bootstrap based on a specific percentage level

var elem = document.getElementById("progress-bar"); var progress = 75; elem.style.width = 80 + '%'; if (progress > 80) { elem.style.background = "red"; } #myProgress { height: 5px; } #progress-bar { w ...

Where to place the code for HTML Email transmission

Currently, I am facing a dilemma regarding the placement of code in an email. When sending out newsletters that contain styling and images, I am unsure about where to insert the necessary code. Should I attach the images separately? Is it better to incor ...

Integrating a footer into the enhanced search tab slider

I'm struggling to create a sticky footer like the one on w3schools. Even though I used the same code in my material UI demo, it's not functioning properly. I tried debugging by changing the position from fixed to absolute, but it still isn&apos ...

The functionality of AngularJS ng-model is restricted when used in conjunction with ng-include

Looking at the code snippet provided below, I am utilizing ng-include. The ng-model="numLines" establishes a connection between the value in the input box and the function changeNumLines() defined in ng-change, which is triggered whenever there is a change ...