英文:
is it good practice to use vh and vw for applying padding,margin,width and height for each element on website
问题
- 对于制作响应式布局,使用这种逻辑是一个好的做法吗?因为我看到流行的网站使用基于像素的尺寸。
- 这个逻辑是否适用于字体大小?
- 这个逻辑可能会引发哪些问题。
英文:
I have a general question regarding use of vw and vh in angular/ionic application.As per suggestion from senior team member we are using below logic to calculate values of margin/padding in vh and vw. Screens are designed using 360*640 dimensions on zeplin.
$screen-height: 640;
$screen-width: 360;
@function viewport-height($element) {
@return ($element/$screen-height * 100vh);
}
//funtion to calculate element viewport width
@function viewport-width($element) {
@return ($element/$screen-width * 100vw);
}
below logic is used whenever we need to add margin/padding respectively.
.top-margin{
margin-top:viewport-height(40);//40 px margin is as per the zeplin design
}
.left padding{
padding-left:viewport-width(15);//15 px left padding is as per the zeplin design
}
I have below queries.
- Is it a good practice to use this logic for making layout responsive?As I have seen that popular websites use pixel based dimensions?
- Can this be used for font-size?
- Any possible issues this logic can create.
答案1
得分: 2
像素是静态值,可能对某些尺寸有效,但会在不同的尺寸/视图(移动-桌面)中引发问题并妨碍设计。
对于响应式网页设计,必须遵循以下设计实践:
1- 无捏合缩放:通过正确应用视口来解决。
2- 无水平滚动:使用相对大小和定位,而不是绝对定位来解决。
3- 字体大小处理:使用 em 和 rems 而不是像素。
4- 布局:使用媒体查询、Flexbox、Bootstrap 等。
英文:
Pixels are static values which may work for certain dimensions but will cause problems and hinder design at different dimensions/views(mobile-desktop) <br>
For responsive web design it is a must to follow certain design practices :
1- No Pinch Zoom: Solved by applying viewport correctly.<br>
2- No Horizontal Scrolling: Solved by using relative sizing and positioning and instead of absolute positioning.<br>
3- Font-size Handling: Use em and rems instead of pixels.<br>
4- Layout: Use Media Queries,Flexboxes, Bootstrap etc.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论