Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

conditional statement for screen resolution?

I would like to use a conditional statement to attach a different stylesheet for:

if the clients resolution is <= 1024*768

I'm pretty sure this is possible, but have never seen the code for it before?

ps. I am not looking for a javascript solution

like image 416
Haroldo Avatar asked Jul 07 '10 12:07

Haroldo


People also ask

What is conditional statement?

Conditional Statement Definition A conditional statement is represented in the form of “if…then”. Let p and q are the two statements, then statements p and q can be written as per different conditions, such as;

How do you test a second condition in a conditional statement?

To test a second condition we can add ElseIf statements to a simple If..Then..Else. An If statement is allowed to be followed by multiple ElseIf statements each consisting of a conditional statement. Once the code reaches the conditional expression, it evaluates either to True or False.

What happens if the condition evaluates to true in C++?

If the condition evaluates to true, execute a certain set of actions and if the condition evaluates to false then perform another set of actions. Set of statements are executed only if the condition is true. If.. Then…Else block will be executed. based on which the statements will be executed. Placing an If statement inside another if statement.

How to remember logical connector conditional statement?

Points to remember: 1 A conditional statement is also called implications. 2 Sign of logical connector conditional statement is →. Example P → Q pronouns as P implies Q. 3 The state P → Q is false if the P is true and Q is false otherwise P → Q is true.


1 Answers

Typically people don't "attach another stylesheet" for screen resolution because you could resize the browser after page load, changing the resolution, and you don't want file loading every time you do.

This will do the trick, in one CSS file:

Ex:

/* css as usual */
.this-class { font-size: 12px; }

/* condition for screen size minimum of 500px */
@media (min-width:500px) {

  /* your conditional / responsive CSS inside this condition */

  .this-class { font-size: 20px; }

}

This should change the font size to 20px when the @media query condition is true, in this case when the screen is over 500px.

As you size your browser up and down you will see the conditional CSS rules take effect automatically, no JS needed.

like image 107
OG Sean Avatar answered Oct 18 '22 10:10

OG Sean