简体   繁体   English

为什么HR标签不在Internet Explorer和Microsoft Edge浏览器上的中间屏幕

[英]Why HR tag not middle screen on internet explorer and microsoft edge browser

I tried to move hr in center screen on internet explorer and microsoft edge but It's moved to right. 我试图在Internet Explorer和Microsoft Edge的中心屏幕上移动hr,但它已移至右侧。

Internet Explorer IE浏览器

Preview Image 预览图片

Google Chrome 谷歌浏览器

Preview Image 预览图片

HTML 的HTML

<div style="width: 100%; height: 100vh; background-color: rebeccapurple">
    <hr style="
    width: 80%;
    height: auto;
    position: relative;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
">
</div>

Addition to that why scroll showing in internet explorer 此外,为什么在Internet Explorer中滚动显示

Instead of positioning it relative, do it like that: 与其相对定位,不应该那样做:

<div style="width: 100%; height: 100vh; background-color: rebeccapurple">
    <hr style="
    width: 80%;
    height: auto;
    display: block;
    margin: 0 auto;
">
</div>

To vertically align you could give the div display: flex , flex-direction: column and justify-content: center , but generally it's not required to vertically align a hr. 要垂直对齐,可以给div display: flexflex-direction: columnjustify-content: center ,但是通常不需要垂直对齐hr。 Instead give it a margin top and bottom. 而是给它一个顶部和底部的边距。

You should put into consideration normal transform property (and -ms for old browsers) 您应该考虑正常的转换属性(对于旧的浏览器,则为-ms)

-moz-transform:    translate(-50%, -50%);
-o-transform:      translate(-50%, -50%);
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);

and for the scrollbar, try adding 对于滚动条,请尝试添加

@-ms-viewport { width: device-width; }
overflow-y: hidden;

UPDATE: So I did three things: 更新:所以我做了三件事:

  1. Add overflow:hidden; 添加溢出:隐藏; to the div 到div
  2. Change 100vh to 100% 将100vh更改为100%
  3. Changed left: 50%; 左移:50%; to left: 40%; 左:40%;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM