Make a div occupy remaining width based on % and on px - html

What I wish to achieve is having 1 left that will occupy a minimum of 300px or if the screen is bigger 25% of it, next to it I wish to put another div that will occupy the rest of the screen with the option to add a third div beside those 2 that will shrink the middle one to get a width of 25% or minimum of 300px;
Here is the sample of the div I have created:
.parents{
width:25%;;
min-width:300px;
height:100%;
background-image:url(img/background_parents.jpg);
border-right:3px solid darkgray;
overflow:auto;
}
Now beside this div I need 1 with adjustable width because of the option of adding a third panel with the same width of the one you see above.
I can do this with jquery, but I wonder if there is an option of achieving this through CSS, because I wish to escape the route of constant calculations of the screen width.

Try using media queries to define your width based on the detected device screen. This is my usual setup:
/* Smaller than standard 960 (devices and browsers) */
#media only screen and (max-width: 959px) {}
/* Tablet Portrait size to standard 960 (devices and browsers) */
#media only screen and (min-width: 768px) and (max-width: 959px) {}
/* All Mobile Sizes (devices and browser) */
#media only screen and (max-width: 767px) {}
/* Mobile Landscape Size to Tablet Portrait (devices and browsers) */
#media only screen and (min-width: 480px) and (max-width: 767px) {}
/* Mobile Portrait Size to Mobile Landscape Size (devices and browsers) */
#media only screen and (max-width: 479px) {}

Related

How to use min-width and max-width in CSS media queries with high density mobile device screens

I am doing my first steps in repsonsive design world.
I found out that the most recommended way is to use min-width and max-width to find out the size of the display area, like this:
#media (max-width: 1200px) { ... } /* for desktops */
#media (max-width: 991px) { ... } /* for laptops */
#media (min-width: 768px) and (max-width: 990px) { ... } /* for large tablets */
#media (max-width: 768px) { ... } /* for smaller tablets */
#media (max-width: 500px) { ... } /* for cellphones */
The problem is that newer phones have high density screens. My phone has width of 980px. Therefore it loads wrong CSS which is meant for larger screens.
I tried out max-device-width. It takes into account logical pixels and my phone width is 393 of those. It worked. But max-device-width is deprecated so i don't want to use it.
I found some examples of min-resolution and max-resolution as well.
It is also possible to use JavaScript to determine if the browser is mobile browser, but it doesn't seem to be the correct approach.
So I got kind of confused. Please give me hints what and how should I use to determine if the site is running on a mobile device and how to load the correct CSS for it. How it has to be done in correct and reliable way?
Thank you in advance.
first at all, the way you use it, wouldnt work well. For example:
#media (max-width: 1200px) { ... } /* for desktops */
#media (max-width: 991px) { ... } /* for laptops */
if a screen has the width of 900px, then both media queries would apply. Because 900px is below 1200px and below 991px. For that specific case your media queries should be as follow:
/* for desktops */
#media only screen
and (min-width: 1367px) {
...
}
/* for laptops */
#media only screen
and (min-width: 991px)
and (max-width: 1366px) {
...
}
/* for large tablets */
#media only screen
and (min-width: 769px)
and (max-width: 990px) {
...
}
/* for smaller tablets */
#media only screen
and (min-width: 481px)
and (max-width: 768px) {
...
}
/* for cellphones */
#media only screen
and (max-width: 480px) {
...
}
as you noticed, it should contain min and max width unless its the lwoer or top end (desktop and smartphones) the smallest smartphone size is 320px btw.
Also I changed the media queries to screen only, its just good practise as you want to address screens only.
Screen size:
Notice the difference between Hardware pixels and viewport Pixels. your phone might have something above 900 hardware pixels but onyl half or a quarter of it as viewport pixels.
Hardware pixels are the pixels that a device has physically and viewport pixels the pixels which can bea dressed by css.
The reason is, that the ahdrware pixels are not actually adressable is for sharpness. besides, it owuld be nearly unreadably otehrwise.
Edit: The cheap laptops screen panels have a resolution of 1366 x 768px. so the laptop width should be also set to 1366px.
There is a difference between device pixels and CSS pixels. On many screens they are treated the same, but on high DPI screens there can be several device pixels per CSS pixel. See this page on MDN for more reading.
To control the width in CSS pixels, use the viewport meta tag in your HTML. This tag is generally only interpreted on mobile devices so it shouldn't affect your site on desktop browsers. It specifies the minimum width at which your site will be displayed.
For example, to set your site to display at a minimum width of 500px on mobile, use:
<meta name="viewport" content="width=500, initial-scale=1">
To display the site at the browser's width use:
<meta name="viewport" content="width=device-width">
In addition to the MDN article, the following article may be helpful for setting display widths for tablets.
For responsive design, it's recommended to use Mobile First approach. You start with styling the mobile version and change it while the viewport grows.
With the following media queries you have different problems:
#media (max-width: 1200px) { ... } /* for desktops */
#media (max-width: 991px) { ... } /* will match laptops and desktop because your screen with is underr 991 but also under 1200px */
#media (min-width: 768px) and (max-width: 990px) { ... } /* for large tablets */
#media (max-width: 768px) { ... }
#media (max-width: 500px) { ... }
the correct approach should be
// you start with mobile version
#media (min-width: 500px) { ... } // will match only screen width >= 500px
#media (max-width: 768px) { ... } // will match only screen width >= 768px
#media (min-width: 768px) and (max-width: 990px) { ... } // will match only screen width >= 768px and < 900px (could be tablets also)
#media (min-width: 991px) { ... } // match also ipad on landscape mode
#media (min-width: 1200px) { ... } /* for desktops */

Media query not confined to just tablet and smaller screen sizes

I believe I have formatted my media query incorrectly as it is not only working for the devices I wish to target (Small laptop screen and tablets) but is also being applied to my desktop screen size.
Do I need the extra set of {} being used here?
/* Medium devices (landscape tablets, 992px and up) */
#media only screen and (min-width: 992px) {
.wpb_text_column.wpb_content_element.vc_custom_1565090087252.DANSpace {
padding-bottom: 220px !important;
}
}
The problem is that you've set a minimum width but not a maximum width. This means that whatever is inside the mobile query will be applied whenever the users width is above 992px.
To target everything below that you would need to change it to max-width like so:
#media only screen and (max-width: 992px) {
.wpb_text_column.wpb_content_element.vc_custom_1565090087252.DANSpace {
padding-bottom: 220px !important;
}
}
You can also target between certain widths by doing the following:
#media (min-width: 576px) and (max-width: 992px)

Scaling webpage on desktop at different resolutions

I have a webpage which has a fixed layout.
It was built using standard size of 1280x800.
Since it doesn't need to be mobile compatible, and not accessed by the public, it was built using fixed size elements.
The problem is, I need it to scale automatically according to browser size.
I managed to do it with the viewport metatag, but that works only for mobile browser (which I do not need...)
e.g. How can the page display correctly, when opened in Chrome on a desktop with 1024x768 resolution, without the need to manually zoom out in the browser?
Thanks!
Replace every px with a vw based on the ratio of the width to the size at 1280x800.
So if you had a div with width: 1280px you would replace it with width: 100vw.
Set your font-size on the body in this way to get the text to scale, and use em or rem to size larger text.
If your font size was 16 at 1280x800, then you would want font-size: 1.25vw.
Use CSS media queries to achieve different styles at different screen widths (responsive). Here is an example of some different media queries.
/* Smaller than standard 960 (devices and browsers) */
#media only screen and (max-width: 959px) {
}
/* Tablet Portrait size to standard 960 (devices and browsers) */
#media only screen and (min-width: 768px) and (max-width: 959px) {
}
/* All Mobile Sizes (devices and browser) */
#media only screen and (max-width: 767px) {
}
/* Mobile Landscape Size to Tablet Portrait (devices and browsers) */
#media only screen and (min-width: 480px) and (max-width: 767px) {
}
/* Mobile Portrait Size to Mobile Landscape Size (devices and browsers) */
#media only screen and (max-width: 479px) {
}

BreakPoints in Foundation FrameWork

// Small screens
#media only screen { } /* Define mobile styles */
#media only screen and (max-width: 40em) { } /* max-width 640px, mobile-only styles, use when QAing mobile issues */
// Medium screens
#media only screen and (min-width: 40.063em) { } /* min-width 641px, medium screens */
#media only screen and (min-width: 40.063em) and (max-width: 64em) { } /* min-width 641px and max-width 1024px, use when QAing tablet-only issues */
// Large screens
#media only screen and (min-width: 64.063em) { } /* min-width 1025px, large screens */
#media only screen and (min-width: 64.063em) and (max-width: 90em) { } /* min-width 1025px and max-width 1440px, use when QAing large screen-only issues */
// XLarge screens
#media only screen and (min-width: 90.063em) { } /* min-width 1441px, xlarge screens */
#media only screen and (min-width: 90.063em) and (max-width: 120em) { } /* min-width 1441px and max-width 1920px, use when QAing xlarge screen-only issues */
// XXLarge screens
#media only screen and (min-width: 120.063em) { } /* min-width 1921px, xxlarge screens */
Above is Foundation Framework Standard Break Points.
For Mobile it is Seen the break Point is max-width of 640, What if Design Provided to me for mobile is greater than 640 & same is Case for Destkop & tablet. Does it make a sense in changing the Foundation breakpoints wrt to design provided? An answer with proper reasoning would be helpful.
Of course that make sense, you can adapt the framework to your project needs; most of time you can use the existing breakpoints (what Zurb have defined according to their most-of-time scenarios), but you can adapt if your project has specific needs, you can do it.
What I'd recommend to you, is not to use the basic foundation package (precompiled), but use any "sass customizable" version instead (you can do that trough a lot of package managers), so you'll have full control of the framework, through customizing variables.
In Foundation's settings file, section d., you can edit the media query ranges (a.k.a. the breakpoint ranges), next time you compile the framework, you'll have the breakpoints just as you need them.

media queries : limit some css styles according to the screen size

when I write some style in layout.css it applies in every screen size and in /* #Media Queries
section, you have these sections:
/* Smaller than standard 960 (devices and browsers) */
/* Tablet Portrait size to standard 960 (devices and browsers) */
/* All Mobile Sizes (devices and browser) */
/* Mobile Portrait Size to Mobile Landscape Size (devices and browsers) */
so none of these do what I want.
Where should I write large screen specific css codes?
suppose you have a div like <div claas="example"> </div>
now write a css for .example which will be applied for those screen which are larger than range you mentioned in your media query
.example{
/*..for larger screen style goes here....*/
}
#media screen and (max-width: 1400px) {
.example {
/*...now give style for those screen which are less than 1400px...*/
}
}
#media screen and (max-width: 1300px) {
.example {
/*...now give style for those screen which are less than 1300px...*/
}
}
in the above you code you mention three different styles for
>1400px screen size
for 1300 to 1400px screen size
<1300px screen size
EDIT::
"/* Larger than standard 960 (devices and browsers) */"
.example{
/*..style for larger than 960px....*/
}
#media screen and (max-width: 960px) {
.example {
/*..style for lesser than or equal to 960 px...*/
}
}