is it good practice to use vh and vw for applying padding,margin,width and height for each element on website

huangapple go评论59阅读模式
英文:

is it good practice to use vh and vw for applying padding,margin,width and height for each element on website

问题

  1. 对于制作响应式布局,使用这种逻辑是一个好的做法吗?因为我看到流行的网站使用基于像素的尺寸。
  2. 这个逻辑是否适用于字体大小?
  3. 这个逻辑可能会引发哪些问题。
英文:

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.

  1. Is it a good practice to use this logic for making layout responsive?As I have seen that popular websites use pixel based dimensions?
  2. Can this be used for font-size?
  3. 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.

huangapple
  • 本文由 发表于 2020年1月6日 19:14:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/59611088.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定