Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

怎么绘制出0.5px的线条 #36

Open
sweetXiaoyan opened this issue Dec 30, 2019 · 0 comments
Open

怎么绘制出0.5px的线条 #36

sweetXiaoyan opened this issue Dec 30, 2019 · 0 comments
Labels
css css以及css3相关内容

Comments

@sweetXiaoyan
Copy link
Contributor

sweetXiaoyan commented Dec 30, 2019

怎么绘制出0.5px的线条

scale方法

<style>
.hr.scale-half {
    height: 1px;
    transform: scaleY(0.5);
}
</style>
  <p>1px + scaleY(0.5)</p>
  <div class="hr scale-half"></div>

viewport

利用动态的改变<viewport>让网页的像素区域和屏幕的像素区域重合,这样就很轻松的去写1px的边框,并且它会等于屏幕本身的1px。

/当 devicePixelRatio = 2 输出:

<meta name="viewport" content="initial-scale=0.5, maximum-scale=0.5, minimum-scale=0.5, user-scalable=no">

//当 devicePixelRatio = 3 输出:

<meta name="viewport" content="initial-scale=0.3333333333333333, maximum-scale=0.3333333333333333, minimum-scale=0.3333333333333333, user-scalable=no">

svg+background

svg 单独是这样:

<svg xmlns='http://www.w3.org/2000/svg' width='100%' height='1px'>
    <line x1='0' y1='0' x2='100%' y2='0' stroke='#000'></line>
</svg>

设置 background 为svg文件:

<style>
.line.svg {
    height: 1px;
    background: url("data:image/svg+xml;utf-8,<svg xmlns='http://www.w3.org/2000/svg' width='100%' height='1px'><line x1='0' y1='0' x2='100%' y2='0' stroke='#000'></line></svg>");
}
</style>
<p>svg+background</p>
<div class="line svg"></div>
@koala-coding koala-coding added the css css以及css3相关内容 label Dec 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
css css以及css3相关内容
Projects
None yet
Development

No branches or pull requests

2 participants