How do I get rid of sliver that appears between adjacent elements in Safari on iPad? - ios

I have two absolutely positioned adjacent elements that share the same background color. They appear to be one single element on my desktop and laptop, but there's a plainly visible "border" of sorts - a sliver of translucent color - between the two elements when viewed on the iPad.
If I had to guess I'd say it's due to the different method by which vector objects are drawn in the browser in iOS, but that's just a guess based on some vague information I heard in a talk once.
Here's an entire sample page that can show the issue if you can run it on an iPad:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<style type="text/css">
#container {
position: relative;
width: 200px;
height: 40px;
background-color: transparent;
}
#left {
position: absolute;
top: 0;
left: 0;
width: 50px;
height: 40px;
background-color: red;
}
#right {
position: absolute;
top: 0;
left: 50px;
width: 150px;
height: 40px;
background-color: red;
}
</style>
</head>
<body>
<div id="container">
<div id="left"></div>
<div id="right"></div>
</div>
</body>
</html>

The problem only occurs if Safari is scaling the page.
Safari scales elements individually, often resulting in each element having a 1-pixel-wide translucent edge on one or more sides. Then when the scaled elements are placed side by side, the overlapping translucent edges are still not 100% opaque, so some of the background leaks through.
The problem isn't limited to absolutely-positioned elements; it applies to all adjacent elements (except images, it seems).
For instance, if a table is styled with td { background-color:black } there will sometimes be subpixel slivers of background showing between the table cells. Even two adjacent spans exhibit the problem.
My solution is to restructure the page so that adjacent elements of the same color are wrapped in a container, and the background is applied to the container. This is a lot of work. In your case, a quick fix would be to overlap the divs by 1 pixel.
I do consider this to be an iPad bug. None of my Windows browsers (including Safari) have this problem when zooming a page.

Related

WebRTC: Safari Blocks Video Picture-in-Picture?

I'm working on a WebRTC UI that shows the user's video in a small element located in front of the video of the person to whom the user is speaking.
Here's a working codepen:
https://codepen.io/VikR/pen/GXoXRp
CSS
#pipContainer {
position: relative;
top: 0;
left: 0;
width: 250px;
}
#otherCallerVideo {
position: relative;
top: 0;
left: 0;
width: 100%;
}
#myVideo {
width: 30%;
position: absolute;
bottom: 0;
right: 0;
transform: rotateY(-180deg);
z-index: 1000;
}
HTML
<p id="status">Loading room information...</p>
<div id="start">
<button onclick="start(event)">Start</button><br/>
</div>
<div id="pipContainer">
<video id="otherCallerVideo" playsInline="true" autoPlay></video>
<video id="myVideo" playsInline="true" autoPlay muted></video>
</div>
This works fine in Chrome and Firefox, but Safari OS X and IOS, don't seem to permit it. The user's video disappears. I've tried a lot of different ways, using z-index and different kinds of positioning, but I haven't yet found a way to get this to work in Safari.
Is it possible to do this in Safari?
I got this working. Here's an updated CodePen.
https://codepen.io/VikR/pen/Wgwwoa
The key was putting this overflow code in the video container:
#pipContainer {
position: relative;
width: 300px;
height: 300px;
border: 5px solid black;
overflow: scroll;
-webkit-overflow-scrolling: touch;
}
This was a tough one to track down. Googling "safari z-index video elements" reveals many people having difficulty with this with posts from 2011 to 2018 coming up on the first page of results. Many of the fixes that work in other cases didn't seem to work in this case, possibly because I am overlaying one video element on top of another. The fix that worked was found here.
Note 1: overflow: 'hidden' also works, and has the added benefit of hiding the scrollbars.
Note 2: I have the impression that it may not be possible to change the video dimensions via javascript. In my app I currently set them on the HTML render by reference to screen.height.

IOS Safari on Ipad vertical center in absolute positioned container

I have two containers which are positioned absolutely one below the other like so:
<header>
<div class="vcenter">
...
</div>
</header>
<div id="wrapper">
...
</div>
CSS:
header {
position: absolute;
top: 0;
height: 70%;
}
.vcenter {
position: relative;
margin-top: -50px;
top: 50%;
}
#wrapper {
position: absolute;
width: 100%;
top: 70%;
}
I'm centering .vcenter vertically with relative positioning. This works fine in all major browsers. Only on IOS Safari on the Ipad it's bugging. Check out the site I'm working on. .vcenter is the container of the logo.
I'm inspecting it through Xcodes IOS-Simulator and also checked on an real Ipad. Is this possibly an IOS Safari Bug? Does somebody have a workaround? I want to keep my header dynamically resizing vertically (height: 70%)...
Thanks in advance for your thoughts.
Desktop Screenshot (how it should be):
IOS-Simulator Ipad Screenshot (how it should't be):
I can't really explain it, but using position: absolute seems to fix your problem:
.vcenter {
position: absolute;
margin-top: -50px;
top: 50%;
width: 100%; /* needed to add to fix horizontal positioning */
}
I think it has something to do with using absolute positioning and percentages on the header. If you inspect the height of the html & body, they aren't actually as tall as your content - so maybe computing a 50% positioning for the vcenter is getting messed up. Not sure...
Have you tried using the transform solution? It generally covers your bases for things like iOS rendering issues (of which there are several more than just this scenario).
Write your class like this (it'll break for IE9 and below, but that's what browser shimming is for and you can use your existing code for the shim using Modernizr)
.vcenter {
position: relative;
top: 50%;
transform: translateY(-50%);
}
That should render .vcenter at the vertical center for all modern browsers as well as iOS Safari.

Absolute positioned div won't stay in place

Okay so I have these divs called "latestWorkTitle" which are positioned absolute and are placed on top of the corresponding image to show its title.
However, I can't get this properly to work. The titles don't show at the corresponding image and when I resize my browser window everything shifts and so on.
I tried creating this jsbin http://jsbin.com/uhoxef/1 with a part of my code to illustrate how it should look like and what is going wrong. Even all the titles go on top of each other in the code while they should be on top of the corresponding images... I'm just basically totally lost at this.
I think the HTML was confusing itself. I also made the thumbnail class the relative layer. HTML renders as we read, from left to right. So putting the title before the image causes the image to show on top and cover the text.
HTML:
<div class="thumbnail">
<a href="portfoliodetail.php?id=10">
<img src="http://www.hlnarchitects.com/img/plain_red.png" />
<div class="latestWorkTitle">title1</div>
</a>
</div>
CSS:
.thumbnail {
position: relative;
overflow: hidden;
float: left;}
.portfolioOverview img {
width: auto;
height: auto;}
.latestWorkTitle {
text-align: right;
font-size: 11px;
text-transform: uppercase;
background: yellow;
position: absolute;
padding: 6px;
top: 0;
left: 0;}
For this to work, each thumbnail class needs to be the relative start for each individual layer. So the thumbnail class is set to relative.
Any object set to absolute (.latestWorkTitle) within this layer will start from the top and left position of the relative object.
You'll need to adjust some details to taste but I hope this helps.

How do sprites work in jqmobile?

I think I have a reasonable understanding of how css sprites work, but I am baffled by how JQ Mobile is doing it. As a sample I put together a really basic version:
<style>
#id {
display: block-inline;
width: 16px;
height: 16px;
background-image: url("http://code.jquery.com/mobile/1.0b1/images/icons-18-white.png");
background-position: -576px 50%;
background-color: rgba(0,0,0,0.4);
}
</style>
<div style="border: 1 solid black; padding: 5px">
<span id="id"> </span>
</div>
Which is a stripped down of how jqm is doing it. What I don't get is that if you load that png file into an image editor it is completely white, and I can't see any of the images in there. I am also completely confused as to why the y for background position is 50%.
Can anyone help me understand?
The sprite you're talking about has many white icons on a transparent background. If you use lightweight free tool like IrfanView, you'd see it like this:
background-position: -576px 50%; means the background would be placed at the position of -576 from left and 50% from top, which I think is where the home icon is. Although perhaps the 50% bit won't matter in this case as the height is set to 16px but maybe it matters for some other weird mobile browsers.

How to center align the maximum-scale viewport zoom for iphone

When I set a maximum scale and when I rotates orientations back and forth, the web page isn't centered on the phone.
So using this code
<meta name="viewport" content="width=device-width; initial-scale=0; maximum-scale=2;">
How can I mimic the CSS effect of margin: 0 auto;.
For people arriving here from Google, you should also look at the following page on Apple[1].
The viewport tag is quite helpful.
[1]: http://developer.apple.com/library/IOS/#documentation/AppleApplications/Reference/SafariWebContent/UsingtheViewport/UsingtheViewport.html Using the ViewPort
You will need to have a wrapper inside of another wrapper to get this to work. The outside one will have the following CSS:
#wrapper {
min-width: 320px;
max-width: 480px;
}
And the inside one will have the following:
#inside-wrapper {
min-width: 300px;
max-width: 460px;
margin: 0 auto;
}
You can still use margin: 0 auto;

Resources