CSS parameter scaling based on screen size - css

Is there an automated way to scale height and width of elements defined in CSS based on screen sizes?
These days there are so many different screen sizes in the market, it is quite onerous to create separate CSS for each. Wondering if a same CSS can be used with an automatic scaling based on screen size. Say for example, the original CSS is built for 1200x800 screen size. If the page is opened on an screen half of this size, all css element in which height and width is defined in pixels, should automatically reduce to half. I understand it will not look good when the page is opened in a very small screen because everything will look tiny. However, the requirement basically is to automatically adjust the app screen to laptop, desktop and tablet screens.
For example, I have a div and inside that div there are 5 buttons (created using CSS). On smaller screens the button row wraps into two lines making it look very bad. This is just an example. Most other screen elements behave similarly.

As commented and approved by OP :
You have multiple approaches available, among them media-queries (million links around but here's one : http://css-tricks.com/logic-in-media-queries) and another one I like a lot, viewport units (see here for example : http://css-tricks.com/the-lengths-of-css Viewport Percentage Lengths). You are basically describing what is called Responsive Design (http://en.wikipedia.org/wiki/Responsive_web_design) --- Have Fun ^^
Maybe try this for responsive design without css 3 : http://responsejs.com

Media-queries are the way to go. As for the old browsers(IE <10), this is a great webpage with "polyfills" for those:
https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-Browser-Polyfills

Related

Shiny UI distorted when minimized

So Im making a website and I have included a .css file to be able to move things more freely. I have made some items with position:relative and others I have used the absolutePanel(). I want to keep my layout as it is but when the window is resized it looks horrible. Any suggestions?
You should try to be a bit more specific on your question.
Some general tips though are instead of using pixels for the sizes of divs etc.(static design) use either percentages, vh & vw (view height and view width of the window that are being displayed respectively) or media queries #media (responsive design). To make your life a lot easier with responsive design though check out Bootstrap, and especially its grid layout system.

In Responsive Website if we adjust the font size based on screen resolution. Is it a good practice?

Would like to know if adjusting the font size of the element on the webpage based on windows size is a bad or good in Responsive web designing.i.e. using http://simplefocus.com/flowtype/ for example.
There seems to be lot of confusion this area because if we have a paragraph which has 5 lines when shown on 1024px screen can become two line in 1600px screen which will result lot of space between elements and which make the screen elements scattered.
Please guide the right approach be followed.
Regards,
Sameer

Increase JUST font size in css for mobiles, without setting a viewport

Normally when I am creating a responsive site, I do the normal thing of setting a viewport to the device width, and creating different layouts for different screen resolutions.
But I'm doing a few tweaks to an old site that has big chunky buttons, default font sizes and a simple layout, and actually it looks quite usable when viewed as a desktop-style fixed-width layout, even on small mobile devices.
Rather than specifying a viewport and completely rewriting all the css to make a series of mobile-friendly versions, I'd really like to just increase the main body element font size a little more for viewing on a screen that is physically small: for this particular layout, this would be very usable - if I could work out how to do it!
Is this what -webkit-text-size-adjust: is for? It seems like it should be an easy thing to tweak, but all my googling turns up full responsive design approaches, which are overkill for this particular small task.
A way to make it is to detect the screen width with javascript using the window.screen.width property, and then apply the styles that you want from there.
Here's an example using jquery, however the same can be achieved with native javascript if you don't want to use a library http://jsfiddle.net/UXV7Z/
You can apply as many filters in resolution as you need, just like you would using media queries
DONT use javascript for such a simple task to accomplish with modern CSS, just use:
font-size: calc(80px - 3vw);
and adjust the values accordingly. That will icrease the size on smaller devices and decrease it on wider devices, which makes sense for buttons and footers and what not, but if you want to decrease the size on smaller width screens for text like large titles that overflow just use:
font-size: calc(25px + 0.35vw);
Once again adjust the values to fit your needs. And see here to view the browser support for the CSS calc() function. All modern updated browsers support it

What's the point on using % units in responsive design?

I'm redesigning my site because looks awful on different resolutions (apart devices), most guides and tutorials rely on % and em than fixed values. I'm still learning this so I'm reading everything around.
Thought this would solve the question with different display sizes but again: we have to craft some more CSS for fix some specific issues.
If I need to add media-queries for extra display sizes, why use % then? Do use % really reduce coding? Is ok need to add some extra css for some sizes or am I doing something wrong?
Thanks for any advice!
The purpose of using em sizes is to allow the base your design off of the user's choice of font size. I may use a larger font size because I have a huge monitor and poor eye sight, while someone else might prefer a smaller font. By using em units, your design will accommodate both of our font preferences and resize accordingly instead of forcing the font size to a given standard (eg. "12 point font").
In a similar manner, percent (%) units allow your design to respond to different browser sizes. Used in conjunction with em units, this will allow text-based elements to respond to arbitrary font size choices, and layout elements to respond to arbitrary browser sizes.
It is perfectly acceptable to design a single responsive design for all media types. Media queries are intended when you want different display styles on different devices, not to "support" different display sizes. An example would be to use serif fonts on print media and sans-serif fonts on display media, since usabilities studies have shown that these font faces are preferred for these sorts of media.
Furthermore, it allows you to do custom styling for some situations like mobile devices, where you may want to consider that the user has a limited amount of bandwidth and maybe cut down on extra images. Or if you want to display your content in a completely different layout for the microscopic screen afforded by certain phones.
% allows your site to be responsive to the user's method of viewing. Let's say you have a div that's at 100%. It'll fill the entire section, regardless if it's on a phone or desktop.
It should be okay to add extra CSS for sizes as well. As far as I know, you can have some elements display in % and some with a fixed px value, although they might conflict depending on how the page is setup or what it is being viewed with.
For example.
Your website header have the width of 950px; But in a mobile device, it may fit at 450px;
So, you use media-query to reposition some elements and handle some size issues and set the header width to 450px;
But, if you use % values, you can set your header div to have 100% of width base in its parent. So you can only change the body or some container div width, the all childs going to adapt.
Diana,
I am glad I came across this question. I literally just uploaded my first responsive design which is 90% based off of percentages when it comes to font-size and widths.
Check out the below:
http://www.noxinnovations.com/portfolio/responsive/
Obviously, it doesn't look amazing, and the image looks way out of place... But do me a favor and resize your browser window, by slowly making it smaller and smaller. I did that by setting a percentage width!
Trust me, I tried doing this responsive design test with pixels, and it didn't turn out too well. The percentage width ensures that regardless of the resolution and or pixel dimensions (per se) the design will always cater to the size of the screen. Also, I did not have to use one CSS3 Media Query, but I would highly suggest using CSS3 Media Queries only when you need them.
In my opinion, I should probably have a Media Query for a larger screen.
I hope this helps you as much as it has helped me!
Thank you,
Aaron

How can effectively use dynamic CSS in a mobile browser?

I am trying to develop a mobile version of my web application and I am having trouble getting it to look good on multiple browsers. I figure if I use some device capability detection I can dynamically generate widths and font-sizes based on a particular devices screen size. The problem is that it seems like a mobile browser doesn't treat 1px of CSS width equal to 1px of screen width. On an iPhone with a screen width of 320px, a body tag that is 320px wide takes up only about a 1/4th of the page. With no real frame of reference, it makes it hard for me to say "On a screen of 320px wide, make the font 16px" or something along those lines. Is there some general rule of thumb I can use to calculate the real browser width in CSS, or some calculation using multiple device capabilities that will help me generate dynamic CSS more effectively?
Thanks,
Mike
Try defining sizes and font weights in relative units. I would give % and em a go. Many mobile browsers try to scale everything down so that they render normal websites nicely. You may find you need specialy meta tags or the like to controll these browsers.

Resources