Note that there are some explanatory texts on larger screens.

plurals
  1. POCSS percentage width resize based on window
    primarykey
    data
    text
    <p>This probably was answered somewhere, but I can't find it :s</p> <p>My question is about dynamic resizing of divs based in percentages.</p> <p>Please look at code example below for the examples and possible solutions I made. I ask if there is a better way to do resizing?</p> <p>More detailed explanation:</p> <p>Say I am writing a plugin that people can insert in their pages. <em>(Imagine login form)</em>. I go ahead and design the plugin's divs. I use media queries to achieve desired look for different devices. I work on a div straight inside of a 'body' element. I use <strong>percentages</strong> for design (I like percentages). Say I set div to <strong>80% width</strong>.</p> <p>Now I give this plugin to the user. User goes ahead and puts the plugin's div inside of another div that is <strong>100px</strong> in width. Now everything looks awful. <em>(80% of 100px is not a lot [80px])</em>. And of course I want user to put my plugin inside of whatever small-width divs that he have.</p> <p>The solutions I saw so far to this problem was to create a holder div of certain width - say hardcode 300px. <em>(ex - jQuery UI's Datepicker div; Meteor's login widget div)</em>. And then code to it always knowing the 300px width that I set before is not going to change.</p> <p>But I don't know how good of a solution this is.</p> <p>Moreover if I decide to go with hard-coding width, my plugin would need width of ~ 1000px. Because I want div to resize with <strong>media queries</strong>. And if I go with hard-coding width (say holder div of 1000px width) and put it on a page, the page will have <strong>horizontal scrolling</strong>. And you cannot simply hide holder div (parent div) and have child to show at the same time. So this requires setting position:relative for holder (parent) div, putting it outside of window, and use same for child div - position:relative with same offset in opposite direction of parent offset.</p> <p>I hope I am being clear so far and have not confused you!</p> <p>A code example to illustrate what I am talking about: <strong><a href="http://jsbin.com/ifawez/18/edit" rel="nofollow">http://jsbin.com/ifawez/18/edit</a></strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload