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

[css] 第37天 不使用border画出1px高的线,在不同浏览器的标准和怪异模式下都能保持效果一样 #137

Open
haizhilin2013 opened this issue May 22, 2019 · 10 comments
Labels
css css

Comments

@haizhilin2013
Copy link
Collaborator

第37天 不使用border画出1px高的线,在不同浏览器的标准和怪异模式下都能保持效果一样

@haizhilin2013 haizhilin2013 added the css css label May 22, 2019
@rocky-191
Copy link

用border-image是否可以实现

@yxkhaha
Copy link

yxkhaha commented May 23, 2019

 <div style="width: 100%;height: 1px;"></div>
 <hr size="1">

@tzjoke
Copy link

tzjoke commented May 28, 2019

我不知道不用border怎么搞,期待楼主公布答案~不过楼上的肯定不对,hr这个标签跨浏览器行为完全不同,就这么一个size属性绝对不行

@Konata9
Copy link

Konata9 commented Sep 16, 2019

能想到的方法就是使用 divheight 进行模拟。

.border {
  width: 100%;
  height: 1px;
  background: blue;
}
<div class="border"></div>

@sajiaHLX
Copy link

既然是css那么就用css的方法啊!
.box::after{ content: ""; display: block; width: 100px; height: 1px; background-color: black; }

@blueRoach
Copy link

height: 1px; background-color: red;

@qiqingfu
Copy link

box-shadow

@hou499
Copy link

hou499 commented Aug 19, 2020

.box1 {
    height: 38px;
    width: 100%;
    box-shadow: 0 1px 0 0 #000;
}

.box2 {
    background-color: #000;
    height: 1px;
}

.box3:after{
    content: '';
    display: block;
    height: 1px;
    background-color: #000;
}

hr {
    height: 1px;
    border-width: 0;
    color: #000;
    background-color: #000;
}
<div class="box1">
    <br>
    box-shadow
</div>

<br>
height: 1px;
<div class="box2"></div>

<br>
:after{... height: 1px;}
<div class="box3"></div>

<br>
hr
<hr>

不太明白标准和怪异模式的区别以及怎样设置,这四条线在各浏览器下都是1px,IE9以下不支持box-shadow,IE8以下不支持伪元素,IE5下第二条线是为什么会变成这样子有没有大佬能解下惑...

@MrZ2019
Copy link

MrZ2019 commented Oct 26, 2020

能想到的方法就是使用 divheight 进行模拟。

.border {
  width: 100%;
  height: 1px;
  background: blue;
}
<div class="border"></div>

@an31742
Copy link

an31742 commented Nov 23, 2023

.line {
position: relative;
}

.line::before {
content: "";
position: absolute;
left: 0;
top: 0.5em; /* 调整这个值以控制线的位置 /
width: 100%;
height: 1px;
background-color: black; /
线的颜色 /
transform-origin: 0 0;
transform: scaleY(0.5); /
调整这个值以控制线的粗细 */
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
css css
Projects
None yet
Development

No branches or pull requests