3

I am having an issue while switching a design between devices. I know that css3 @media queries are use to handle on the bases of device width, orientation etc.

As far as concern with the device size css media queries are working perfectly fine when am on large screen size or on mobile screen size.

e.g

This is the design for mobile screen size.

enter image description here

and this is the design for large screen enter image description here

the media queries are working fine to switch the design. But i want to show the mobile screen design on desktop screen when the parent div size is small e.g equals to mobile screen size?

In the below situation i need to shown the mobile screen design on desktop screen size. enter image description here

I googled it but didn't find any luck. I also try with different options of media queries. Is there any way to resolve this issue?

Sorry I forget to mention that am using foundation framework for responsive design.

Faheem Alam
  • 515
  • 4
  • 20
  • You can use emulator of google chrome or resize window size (maybe) @media less than would work when resizing windows – frunkad Feb 12 '15 at 08:06
  • are you using device-width or screen-width? – atmd Feb 12 '15 at 08:10
  • Similar to Darshan's answer, in Firefox you can get responsive design mode from the developer tools. Press F12, and on the top right part there is a button called "Responsive Design Mode" – Suppen Feb 12 '15 at 08:10
  • How about [this](http://filzhut.net/projects/responsive-switch/)? – balintpekker Feb 12 '15 at 08:10
  • the responsive design working perfectly fine. I need to show the mobile screen design on large screen. Is there any way to show the small screen size design on the bases of parent div width? – Faheem Alam Feb 12 '15 at 08:12
  • there is no Issue of switching design between mobile screen and desktop screen size. I want to show the small screen size on large screen size? Do you guys get my point? – Faheem Alam Feb 12 '15 at 08:15
  • Use iframe with small size. – Petroff Feb 12 '15 at 08:16

4 Answers4

3

Media queries target the screen. Let's suppose you have the following structure:

<div id="foo">
    <div id="bar">
    </div>
</div>

If you check the width with media query, you are essentially checking the screen width. However, if you check the width:

function isLarge(element, limit) {
    return element.width() >= limit;
}

and you add a class based on the size:

function addSizeClass(element, limit) {
    element.addClass(isLarge(element, limit) ? "large" : "small");
}

and you call the function for the parent of your element:

addSizeClass($("#bar").parent(), 700);

then, you can design .large and .small, like this:

.large div {
    /*your rules*/
}

.small div {
    /*your rules*/
}
Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175
2

You can not link your media queries to the div size.

The usual way to handle this is to link them to screen-width, and set the div width to some percentage of the screen width.

Now, you only need to do some math ..

The basic issue here is that you should do a variable/responsive design for all your page, not only the list

vals
  • 61,425
  • 11
  • 89
  • 138
  • how about using iframe ( as mention by @Petroff in comment )? is this a good way ? – Faheem Alam Feb 12 '15 at 08:19
  • 2
    Using an iframe is a good way if it doesn't create problems in the way you handle your page. But quite probably it will give you problems somewhere. Anyway, Petroff answer is more related to doing it in a development scenario that in production – vals Feb 12 '15 at 08:36
  • you are right i try using iframe and it raise issue with angular scope. I think i have to go with your solution. – Faheem Alam Feb 12 '15 at 08:46
  • YAY! i fix the issue. The only solution is by making calculation. If you dont want to got into maths then creating a parent class and copy the small screen css with in it. So that on large screen when you mention the parent class it will react as a mobile design. – Faheem Alam Feb 12 '15 at 09:02
0

I have not used foundation framework. But in media query you can give condition of screen max width :

@media screen and (max-width: 320px) {

// write your code here of css for mobile device

}

Now , suppose if u want make differentiate with mobile device or large device you can use width property for both of them in css.

So that you can make margin between

name : Collette Simko

Events by Collete

MONTS_MIND_Hacker
  • 1,727
  • 2
  • 9
  • 9
-1

You can always use an iframe to display the page on your development version, instead of altering your browser settings. Might make it easier for universal testing as well.


JavaScript

function iframe( ) {
    try { return window.self !== window.top; }
    catch( e ) { return true; }
}

if ( !iframe( ) ) {
    theParent = document.getElementsByTagName( "body" )[ 0 ];
    theIframe = document.createElement( "iframe" );
    theIframe.className = "smallScreen";
    theIframe.src = "http://example.com/"; // Replace the address with your site address
    theParent.insertBefore( theIframe, theParent.firstChild );
}

CSS

iframe.smallScreen {
    position: absolute;
    z-index: 1000;
    border: 1px solid #000000;
    height: 800px;
    width: 500px;
    right: 500px;
    top: 50px
}

We use this technique at work when doing Facebook applications, works very well for testing and no need to resize your window all the time – can see both sizes simultaneously and everything works on both ends.

If you are using jQuery, you might as well do something like the following (use the CSS code above in conjunction with this).


JavaScript (jQuery implementation)

function iframe( ) {
    try { return window.self !== window.top; }
    catch( e ) { return true; }
}

if ( !iframe( ) )
    $( "body" ).prepend( '<iframe class="smallScreen" src="http://example.com/" />' ); // Replace the address with your site address

Frame detection picked from this Stack Overflow answer.

Not exactly bulletproof, depends which libraries you use, but certainly worth a shot and works for the most part.

Community
  • 1
  • 1
ascx
  • 473
  • 2
  • 13
  • The question is not about testing a responsive design (did you know most browsers offer developer tools for that?), but about switching the design depending on the size of a surrounding div. – amon Feb 12 '15 at 09:08