Weird CSS stretching issue in iOS7 Safari and Chrome

╄→гoц情女王★ 提交于 2021-02-06 19:56:04

问题


Since upgrading to iOS 7 on multiple iPhones and iPads, we've seen something very strange happening to part of the UI on our website.

The pink box in the image attached is within an absolutely positioned parent and it has two white divs positioned absolutely within it, each with differing opacities. The pink circle is just a div that has border-radius set to make it a circle. There are no images at all in this layout.

For some reason, the browser is intermittently stretching the pink div, but I can't think of anything that would cause it - and I'd have no idea how to achieve this effect if I wanted to!

I presume it's a bug in the browser(s), but I don't know how to fix it.

I haven't included any code as it's all really, really straightforward and there's nothing in there that would cause this (and indeed it works in iOS6). Just hoping someone has seen this before?

Any ideas?

Update In response to comment by cimmamon here's the code:

<div class="col" style="left: -3920px; width: 280px;">
<div class="periods">
    <div class="period3"></div>
    <div class="period2"></div>
    <div class="period1"></div>
    <div class="nodeline colBk">
        <div class="node colBrd"></div>
    </div>
</div>
<div class="inner">
    <div class="group first">
        <div class="branch colBk"></div>
        <a class="story">
            <div class="strip colBk"></div>
            <div class="caption">
                <div class="text">
                    <p class="title">Test</p>
                </div>
            </div>
        </a>
    </div>
</div>

And the CSS that applies to the 'periods' container and children:

.tls .col { display: inline-block; position: absolute; top: 0; }
.periods { height: 72px; overflow:hidden; position: relative; border-left: 1px solid #fff; }
.period2 { height: 30px; opacity: 0.6; background-color: #fff; position: absolute; width: 100%; }
.period1 { height: 25px; opacity: 0.72; top: 30px; background-color: #fff; position: absolute; width: 100%; }
.nodeline { height: 61px; }
.colBk { background-color: #dd545c; }
.nodeline { height: 61px; }
.node { position: absolute; margin-left: -15px; left: 50%; bottom: 0px; width: 17px; height: 17px; border-radius: 50%; border: 6px solid #dd545c; background-color: #f9f9f9; }
.colBrd { border-color: #dd545c; }

It's such a strange bug - there's nothing in the CSS that could cause this that I can see.

Any suggestions on what CSS I could add that might force it to render correctly? You'd think the height alone would be enough but obviously not.

Fiddle here


回答1:


I've had this problem, and it's also now in Safari 7.

Here's a simplified version of what was happening in my case

HTML

<ul>
  <li>
    <a> Some text </a>
  </li>
  <li>
    <a> Some  other text </a>
  </li>
</ul>

I then had some javascript (in my case the bootstrap tooltip) which was adding in an element which made the html

<ul>
  <li>
    <a> Some text </a>
    <div style="position: absolute" class="tooltip"> Some content here </div>
  </li>
  <li>
    <a> Some  other text </a>
  </li>
</ul>

The new div was briefly displaying before the whole ul would get stretched down over the top of the new div.

This has got to be a bug in safari, but adding the following CSS to the inserted div works as a workaround.

.tooltip {
  -webkit-transform: translateZ(0);
  -moz-transform: translateZ(0);
  -ms-transform: translateZ(0);
  -o-transform: translateZ(0);
  transform: translateZ(0);
}

This forces the inserted div to be rendered in a new composite layer which seems to prevent Safari screwing up.

Hopefully this is enough for you to reach a solution but let me know if not and I can flesh this answer out a bit more.




回答2:


Try using backface-visibility:

-webkit-backface-visibility:hidden;

it caused my headings to stretch, once removed the world was and is a happier place

tested on iOS 6 & iOS 7 & Android 4.2 +




回答3:


Another apparent workaround that avoids creating additional compositing layers is to add perspective to the elements that are in a GPU-composited context. (In this case, that's the elements with opacity.) Note that if you're positioning things in 3D space with translate3d, this will have a visual impact, and may not be an effective workaround.

.period1, .period2, .period3 {
  -webkit-perspective: 1px;
  perspective: 1px;
}



回答4:


maybe this fixes the issue:

add height:17px; to .node so your css should look like

.node {
    background-color: #F9F9F9;
    border: 6px solid #DD545C;
    border-radius: 50% 50% 50% 50%;
    bottom: 0;
    height: 17px; /*new*/
    left: 50%;
    margin-left: -15px;
    position: absolute;
    width: 17px;
}

jsFiddle



来源:https://stackoverflow.com/questions/19169089/weird-css-stretching-issue-in-ios7-safari-and-chrome

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!