【问题标题】:Html element top position varies on high resolution and device pixel ratioHtml 元素顶部位置因高分辨率和设备像素比而异
【发布时间】:2017-09-21 09:30:12
【问题描述】:

我需要将第二个元素定位在第一个元素旁边。所以我将顶部值设置为 100%。当设备像素比为 1.5 时,第二个元素的起点是变化的。

机器:联想 YOGA 500, 比例:150%, 分辨率:1920 * 1080, 浏览器:Firefox 除外

.wrap {
    background-color: #fff;
    border: 1px solid #ef36d8;
    position: absolute;
    top: 70px;
}

.content {
    width: 100px;
    height: 100%;
    padding: 5px;
}

div {
    box-sizing: border-box;
}

.arrow {
    position: absolute;
    width: 16px;
    height: 8px;
    left: 50px;
    top: 100%;
    background-color: #fff;
    border: 1px solid #ef36d8;
    border-top: 1px solid #fff;
}
<div class="wrap">
  <div class="content">Content area</div>
  <div class="arrow"></div>
</div>

仅当设备像素比为 1.5 时才会出现此问题。

箭头类元素起始位置因设备像素比而异。我需要删除红色突出显示元素的边框顶部

请指导我解决这个问题?

先谢谢了

【问题讨论】:

  • 请添加你想要的截图
  • @Santhoshkumar 错误截图添加

标签: javascript css html screen-resolution


【解决方案1】:

绝对是一个有趣的问题。我能够删除该额外行的唯一方法是在箭头内放置另一个稍小的 div 框:

HTML

<div class="wrap">
  <div class="content">Content area</div>
  <div class="arrow"></div>
  <div class="secondary-arrow"></div>
</div>

CSS

.wrap {
    background-color: #fff;
    border: 1px solid #ef36d8;
    position: absolute;
    top: 70px;
}

.content {
    width: 100px;
    height: 100%;
    padding: 5px;
}

div {
    box-sizing: border-box;
}

.arrow {
    position: absolute;
    width: 16px;
    height: 8px;
    left: 50px;
    top: 100%;
    background-color: #fff;
    border: 1px solid #ef36d8;
    border-top: 1px solid #fff;
}

.secondary-arrow {
    position: absolute;
    width: 14px;
    height: 7px;
    left: 51px;
    top: 100%;
    background-color: #fff;
}

【讨论】:

  • 感谢我尝试了上述解决方案,不幸的是它不起作用
  • 尝试将最高值调整为较小的值,例如 98% 或其他值。我没有你的确切设备,但使用 Chrome 的设备模拟器它看起来可以工作。我在这个 codepen 中做到了,codepen.io/carfen/pen/RLRdaM.
猜你喜欢
  • 2011-04-09
  • 2013-09-25
  • 1970-01-01
  • 1970-01-01
  • 2012-07-25
  • 1970-01-01
  • 2012-02-03
  • 2014-01-11
  • 1970-01-01
相关资源
最近更新 更多