I know there are several approaches to scale my website. But I couldn't even find a smart way to scale my page based on a base-width.
Say, I have optimised my mobile-site for a specific width and for all other widths the page is scaled. I may set my basic-width to 640px - if the visitors viewport is 640px, the elements are not scaled. If the visitors viewport is 1000ox, the element should be scaled by factor 1.5625 (1000px/640px). What is a smart way to achieve this. Yes, I could run JS to get the viewport and calculate the width, but I would prefer a CSS solution - like setting a parameter and multiply width within the classes.
Thanks and regards :)
Here's a wee list of what you should consider using in css.
Media Queries : These can help you to adjust fixed a width to whichever size is required for the user.
https://www.w3schools.com/css/css_rwd_mediaqueries.asp
Use percentages : By using percentages instead of a fixed width the object you apply it on adjusts to the screen of the user.
https://www.w3schools.com/cssref/pr_dim_width.asp
Use min-width & max-width : This allows you to set a minimum or maximum width it can help making it easier to adjust the website to the used screen size.
https://www.w3schools.com/cssref/pr_dim_min-width.asp
https://www.w3schools.com/cssref/pr_dim_max-width.asp
I hope that helps you out a little bit :)
this is a good one to play around with: https://www.w3schools.com/cssref/playit.asp?filename=playcss_width&preval=50%25
Related
On one of my sites I use ZURB foundation for layouting as it really helpful to make the website responsive, however, I need to set to set an absolutely minimum width to be 700px. Meaning that the browser should not do any scaling after the screen is smaller than 700px.
What is the correct way to do it?
Any help or guidance is much appreciated.
For small screen sizes, Foundation uses a max-width of 40em, which is equivalent to 640px. In the Foundation css file, you'll need to find all instances of media queries that define a max-width of 40em, and change the value to 43.75em, which translates to 700px. To maintain consistency, I would suggest sticking to using em.
The "medium" media queries kick in when the window width is greater than or equal to 40.0625em (641px), so you'll have to change these to 43.813em (701px).
Here's an interesting article that explains why Foundation uses em and why it's a good idea to use it in general: Zurb em use
Another website that allows you to convert em to px and vice-versa: px to em conversion
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
I am designing html/css interface for a 1920x1080 touchscreen. It will always be that resolution, never changing. Should I set width and height to those dimensions and code from there, or should I code in percents at whatever size resolution I'm at and then allow it to adjust to a bigger screen? I am looking for the solution what poses the least roadblocks.
Never assume that anything will always be the same resolution. Regardless of what you're coding for now, there will be next generation devices, and they will be different. So unless your project has a very short lifetime (maybe a temporary web site), my recommendation is to code to current standards. Also, in my experience, coding in ems and percentages is usually faster than coding in individual pixels of a project. If your touchscreen is 1920x1080, and you set a body width of 100%, there is functionally no difference between that value, and setting the body width to 1920px. However, using the percentage approach, you retain more flexibility should the device resolution or browser behavior change.
The best solution (atleast for me) has been described by you as the usage of percentage values.
So if you use percentage values then the code will take care of its content's size in any screen size. But you might want to use this:
#media only screen and (max-width: 1900) {
// css properties here..
}
But the media query will take alot of code lines to make the site able to render itself. So that is why using % is my preference.
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
I am not a CSS expert and I want to make a design that will look good in all browsers and resolutions. I noticed that some websites make their design (width, height, margin, padding) with percentage, not pixels, and I am doing all my design with percentage too. Does this approach have any problems?
Please advise me.
You won't have any problems using this approach, both percentage and pixels work fine depending on your needs. If you need a fluid site, then percentage might be your best option. And ems for the fonts, so the user can modify its display if necessary.
Couple of expert's opinions on this:
https://kyleschaeffer.com/css-font-size-em-vs-px-vs-pt-vs-percent
http://webdesign.about.com/cs/typemeasurements/a/aa042803a.htm
And here's an interesting twist: Percentage + pixels:
http://www.cssplay.co.uk/boxes/outside.html
I guess you should have a look at this:
http://kyleschaeffer.com/best-practices/css-font-size-em-vs-px-vs-pt-vs/
It depends on your needs, I tend to use em instead of pixels or percentages. Also I've noticed that IE does not "eat" percentages too well but ems are working great.
To have the site scale depending on the resolution or the size of the browser window, percents will be your best bet. The only problem you may run into is difficulty reading content if the resolution is very low or the size browser window is small, in which case the content may jumble up and make it difficult to read. using percentages rather than pixels will make the site liquid and will adjust according to resolution and scale of the window.