CSS3 Strange bahaviour border Safari iOS and iPad - html

I have a very strange problem rendering on iOS Browser Safari (not Safari Desktop, not Chrome Desktop and not Chrome Mobile).
I have some divs, which are draggables by the user. When the use make a "preview" of the content, in iOS Safari Mobile the text is "wrapper" because it not has enough space to paint it, something like this:
Lorem Ipsum Text
Lorem Ipsum <- problem break line not enough space by the border.
Text
The divs:
<div class="text-perfect-correction" style="opacity: 1; font-family: Lato; left: 594px; top: 386px; font-size: 50px; color: rgb(0, 0, 0); width: 472px; height: 103px; position: absolute; display: block;">
<div style="display:inherit;" class="text-div" spellcheck="false">
<p>
<span style="color:#696969"><strong>Lorem ipsum text</strong></span>
</p>
</div>
</div>
The css classes are like this:
.text-perfect-correction {
border-width: 6px;
border-color: transparent;
border-style: dotted;
padding: 5px;
margin: -11px;
}
.text-div {
-webkit-line-break: after-white-space;
display: inline;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
-o-user-select: none;
user-select: none;
}
I use the perfect-correction-class because I show some buttons when you click div and a border to show the user which div is selected.
In all the other browsers, I see all correctly:
Lorem impsum text
Lorem impsum text <- No break line
Are any issue about it?
Thanks!!

The problem is not iOS-specific - it's that you're making risky assumptions.
First, let's look at what you've done:
Give the parent element an exact with of 472px
Set font size to 50px
Set font-family to Lato
Assume that your text will always fit on one line with these measuremenets
The problem is that different rendering engines won't always render fonts identically, there might be slight differences, e.g. resulting in a few pixels more width on iOS. Pushing font size to the limit in one browser and just assuming that everything will look ok in others is quite dangerous.
On top of that, there might have been issues with loading Lato making the browser fall back to a different font, which might use more horizontal space.
I copied your code into a JSFiddle, and because Lato isn't imported (and not on my computer), it will render in default sans-serif. In Chrome, the text fits into one line, but on Firefox it breaks after ipsum, too.
Solutions
There are a few approaches to make sure your text will remain on one line.
Prevent line breaks
You can use CSS to prevent white spaces from wrapping, meaning that the whole text will be forced to one line:
.text-div {
white-space: nowrap;
}
JSFiddle
Ellipsis
In addition to above, you can cut off overflowing text with an ellipsis (...):
.text-div p span strong {
display: block;
overflow: hidden;
text-overflow: ellipsis;
}
JSFiddle
Make text smaller
Of course, you can also just reduce font size, so you have enough error margin to prevent problems with slight differences in rendering.

Well I am aware that iOS is a hard browser to design for but from what I can tell your margins may be messing you up. class="text-perfect-correction" has left: 594px; and width: 472px;, and the font size is at 50px, so depending on what iPhone you are viewing it on, there may be a size/margin problem. Test it with less px. That is the problem that I personally have had the most with iOS.
idev101.com
iPhone Design tips

Related

Cursor size does not match text size when user is typing in input

I've set a font-size on all of my input elements and also a line-height of 1.25. For some reason, on mobile web (currently trying with Android Chrome) the blinking cursor is much shorter than the text itself, and results in the text getting cut in the middle when the user is actively entering input. The actual text itself ends up being fine after the user exits the input (doesn't get cut off). How can I make sure that the cursor matches the real size of the text? I attached a picture for reference.
On desktop web browsers (Windows, Mac + Chrome, Safari, Firefox) it's totally fine and I don't experience this issue, although apparently on Firefox Linux the same issue pops up.
Code so far:
.input-class {
background-color: #eeeeee;
border-color: transparent;
border-radius: 10px;
box-sizing: border-box;
padding-left: 0.5rem;
line-height: 1.25 !important;
vertical-align: middle;
width: 100%;
}
.input-class::placeholder {
overflow: visible;
}
.input-class:focus {
outline: none;
}
input {
box-sizing: content-box;
font-size: 1rem;
padding: 0.5rem;
}
<input type="text" class="input-class">
Any comments are appreciated!
I found the issue after doing Remote Debugging with Chrome - highly recommend this in the future if you're also facing some similar issues on mobile. The custom font that I was using was not playing nicely with inputs and textareas on Chrome. I switched to a more common font and the issue went away.

How to avoid pixel distortion in HTML elements in varying display settings?

In certain situations html elements that use pixels are not always rendered as imagined, a simple example is when a person adjusts the browser zoom to about "100%", so depending on the position and zoom one element of height equal to the other seems to be a smaller pixel.
One example is the StackOverflow site menu itself, example with "175%" zoom:
Note that the third menu bar appears larger than the others and that the spacing of the first and second bars also appears larger.
This is not just about "zoom", I tested it on a colleague's notebook with Windows10 and GeForce® GTX 1050 card (of course I understand that in part modern computers render with the "integrated card") and it uses in the Windows display settings for the operating system all the value of 125%:
Using this, I realized that the same problem occurs (even with 100% zoom in the browser).
The only displays that I noticed that the problem does not occur are those of retina displays (and similar "technologies"), because they use a higher "pixel density".
But the question is NOT about monitors, displays and market technologies, the question is how to avoid the problem on normal screens when the user adjusts something (like example in Windows10 with 125% on display settings), noting that it varies with resolution and even the monitor and is "unpredictable".
I tried to work with other units of measure (em, pt, rem, %), but the problem persisted.
So here goes my question:
How to prevent pixel rendering on elements from being distorted in display settings that may vary?
An example that the problem occurs (chance adjust the source of the "OS" or the zoom):
*, ::after, ::before {
box-sizing: border-box;
}
body {
background-color: #007bff;
}
.v-navbar-toggle {
vertical-align: middle;
position: relative;
cursor: pointer;
display: inline-block;
background: none;
outline: 0;
border: none;
padding: 10px 8px;
color: #fff;
margin: 0;
}
.v-icon-bar {
background-color: currentColor;
overflow: hidden;
display: block;
width: 24px;
height: 2px;
border-radius: 1px;
}
.v-icon-bar+.v-icon-bar {
margin-top: 4px;
}
<button class="v-navbar-toggle">
<i class="v-icon-bar"></i>
<i class="v-icon-bar"></i>
<i class="v-icon-bar"></i>
</button>
Note: I also noticed that working with svg (depends on how you use it) or icon-fonts works a lot better compared html+css, but what I am trying to solve are problems with simple "html elements".

iOS7 Safari - anchor changes width first time it is tapped

I have a button class anchor CSSed as follows:
.button {
display: inline-block;
width: 8.0em;
text-align: center;
text-decoration: none;
background-color: #840;
letter-spacing: 1px;
line-height: 2.2em;
padding: 0.5em 0.2em;
border: 4px solid #420;
}
See below for an example with FAQ tapped.
It doesn't happen reliably, but typically only the first time a button is tapped, sometimes when you go back the button is back to normal, other times it is wider, other times it looks larger (meaning width, height and font are larger), other times all the buttons look smaller!
If you want to try it out, you need to use Safari on an iPhone -- iMac and iPad seem to work okay.
I had a similar situation lately on the iPhone (well itouch but it is using the same iOS) I had a paragraph that for some unknown reason the text was reflowing and becoming bigger than the heading text. But rotating the device the text reflowed and changed size. I fixed it with this:
-webkit-text-size-adjust: 100%;
I found this answer originally here:
Fix font size issue on Mobile Safari (iPhone) where text is rendered inconsistently and some fonts are larger than others?
Hope that works for you.

Absolute Block Nested in Relative Block Appears Lower in IE8

Ugh. I really, really hate cross-browser compatibility... I'm working on a Wordpress site for a client to create a popup box that appears just below the item I'm hovering over (using a custom shortcode). I have top set to 16px, and it works fine in Firefox. However, in IE8, it appears a lot further down. Even if I set top to "0", it still appears BELOW the containing blog, instead of at the top of it.
I also have a related issue, in that the font size in IE8 is about 2 pixels smaller. There is a <sup></sup> tag before this, as well, but removing it doesn't change much--the font size is still smaller in IE8.
Here is the page:
http://www.medicalmarcom.com/services/
Every question mark along the left side has a popup that appears when hovering over it (kinda like a tooltip). I need to make it work in FF, IE, Safari, and Chrome. The only one it doesn't work in is IE. Thankfully, he didn't mention IE6, so I'm not worrying about it unless he singles it out.
Here is the HTML:
<span class="questions"><sup>(
<div class="popup_content"><span class="popup">?</span>
<div class="popup_inside" style="display: none;">We’ll ask questions to understand your business, objectives, competitive situation, and positioning statement.<br />
<span style="color:#15398c"><em>Read More >>></em></span></div>
</div>
)</sup></span>
CSS:
.popup_content {
display: inline;
position: relative;
}
.popup_inside {
background-color: #FFF;
border: 1px solid #000;
text-align: left;
font-size: 12px;
color: #000;
width: 300px;
padding: 2px;
line-height: 1.5;
left: 0;
top: 16px;
z-index: 1001;
position: absolute;
display: none;
}
.popup {
position: relative;
z-index: 1000;
}
Ok, this is due to how ie8 is rendering the sup tag, I believe. It considers its baseline the same as the rest of the text, rather than above it. If you want to do this with just css, I'd consider rolling your own superscript class.
Here's a fiddle of something that seemed to work for me.
As an alternative solution, it seems to be rendering correctly in IE7, you could force IE8 into IE7 Compatibility Mode. Drop this line at the top of your <head>. I don't know what this will do to IE9, but it's worth a shot.
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />

Position of text in a submit button

The position of the text on the search submit button on my blog is very low in Firefox 4, but not Chrome 10 or IE9. I've tried almost everything, and nothing works except lowering the font size of the text, which isn't an optimal solution as the text will be too small.
Screenshots
Firefox 4 on Windows 7:
Google Chrome 10.0.648.204 on Windows 7:
The relevant HTML:
<form method="get" class="searchform" action="http://eligrey.com/blog">
<input type="search" placeholder="search" name="s" />
<input type="submit" value="🔍" title="Search" />
</form>
The relevant CSS rule (from http://eligrey.com/blog/wp-content/themes/eligrey.com/style.css):
.searchform input[type="submit"] {
font-family: "rfhb-lpmg";
color: #ccc;
font-size: 3em;
background-color: #959595;
text-align: center;
border: 1px solid #888;
height: 34px;
width: 42px;
line-height: 34px;
-webkit-border-bottom-right-radius: 4px;
-webkit-border-top-right-radius: 4px;
-moz-border-radius-bottomright: 4px;
-moz-border-radius-topright: 4px;
border-bottom-right-radius: 4px;
border-top-right-radius: 4px;
-webkit-background-clip: padding-box;
-moz-background-clip: padding-box;
background-clip: padding-box;
-webkit-transition-property: border, background-color, box-shadow;
-webkit-transition-duration: 0.2s;
-moz-transition-property: border, background-color, box-shadow;
-moz-transition-duration: 0.2s;
}
rfhb-lpmg is just a custom font I made which implements U+2767 rotated floral heart bullet and U+1F50E right-pointing magnifying glass with simplistic glyphs.
I've deduced that the main trouble is the line-height property.
Both browsers attempt to vertically center all text on buttons. In combination with the height property, however, if there is not enough room to render the full standard line-height (glyph padding grows quite large with large font sizes), both browsers will pin the glyph to the top of the button, trimming the bottom.
Normally, the line-height would help adjust this, and in Chrome, in your example, this was successful. However, in the case of button and input type="submit" elements, Firefox ignores line-height altogether, so it can't be used in this way to "fix" the positioning of the character. Using the extreme example below, we can see that the text has been pushed out of visbility in Chrome, while it still stays right in the (vertical) center in Firefox.
<!doctype html>
<html>
<body>
<style type="text/css">
input {
border:1px solid black;
line-height:1000px;
height:40px;
}
</style>
<input type="submit" value="Test"/>
</body>
</html>
Firefox:
Chrome:
When a button element is left to the native style (remove the border), line-height is ignored by both browsers (weirdly, Chrome also ignores the height but Firefox does not). As soon as the button is custom-styled, Chrome picks up the line-height but Firefox does not.
So what can you do?
If you still want to make use of CSS fonts...
First of all, make sure your font renders the glyphs in the same vertical-alignment that a standard font displays a basic full-height character, like H. (It appears you've done this for the most part, since your page looks significantly better than the screenshots in the question.)
Second, you'll notice that if you use a font like Arial, and display an H (at the same font size), it's also low. This is because the built in standard line-height of the font gives it quite a bit of room above the character. This indicates that you may have some success if you can edit the font to trim this, thereby giving the character enough room to not be trimmed at the bottom by the browser.
Probably less ideal to you, but still an option, you can use other elements, either in combination with or in place of the button/submit element, to get the character into place.
Alternative option
I'm not sure what your goal is in using CSS fonts, but often it is for some form of progressive enhancement/graceful degradation. In this case, although (as you said in the comments) the special character is a standardized Unicode "right-pointing magnifying glass", it still will not have any meaning to the user if it doesn't render.
Given that the benefit of graceful degradation is to allow simpler technologies to display your website without appearing broken, the use of this character seems suspect — without CSS fonts or a native font with this character, it will render as 🔍 a ?, or simply a blank box.
A better option for graceful degradation, given this problem, would be to simply use a background-image. Make the text of the button "Search", hide the text (through CSS), and apply the background image, and then you have actual graceful degradation, and a fancy character for better browsers.
A background image could also (obviously dependent on the files themselves) have other benefits, such as faster load and render times (for instance, if a developer wanted to use a single character from a full-character-set font).
FF4 sets it's own styles on input elements. You can check all of them if you paste this in your URL field:
resource://gre-resources/forms.css
Alternatively you can see this styles if you check Show user agent CSS from Style tab dropdown if you have Firebug instaled.
Check solution here: How to reset default button style in Firefox 4 +
I came to the same conclusion as Renesis, though I wasn't sure whether Firefox wasn't respecting line-height or vertical-align. Here is the outline to a different solution that allows you to continue to use your fancy glyph. Since you are using pixel-sizes for your button, try something along these lines (simplified html). This might be overkill, and a background-image would almost certainly be more appropriate, but anyway.
The simplified html:
<div class="searchform">
<input type="search" placeholder="search" name="s" />
<span><input type="submit" value="🔍" title="Search" /></span>
</div>
And the simplified css:
// hide the border and background for the submit button
.searchform input[type="submit"] {
border: none;
background: transparent;
}
// give the span the properties that the submit button has now
span {
position: relative;
width: 30px; // or whatever
height: 30px; // or whatever
}
// absolutely position the submit button
.searchform input[type="submit"] {
position: absolute;
margin-top: -15px; // half the span height
margin-left: -15px; // half the span width
top: 50%;
left: 50%;
bottom: 0;
right: 0;
}
I had been facing a similar problem when using CSS inside buttons. The text was offset by 1 pixel in firefox, and rest of the browsers it was just fine. I used "padding" property specific to Firefox, in the following way
The original code in which the input button's text was one pixel lower in Firefox
.mybutton {
height:32px; background-color:green;
font-size:14px; color:white; font-weight:bold;
border:0px; -moz-border-radius:16px; border-radius:16px;
}
and after adding the Firefox specific padding after the above css, it was perfect in Firefox
#-moz-document url-prefix() {
.mybutton { padding-bottom:1px; }
}
In your case, may be you need a bit more padding-bottom, and probably padding-top in negative too (-1px or -2px).
I came across this when I was looking for a solution to this problem, but since I never really found anything other than a hint at changing the padding bottom I wanted to share that I found adjusting the padding-bottom for just firefox worked great.
Every other browser allowed for enough line-height control to adjust the text positioning.
/* This gets picked up in firefox only to adjust the text into the middle */
#-moz-document url-prefix() {
input[type="button"],
input[type="submit"],
button.btn {
padding-bottom: 6px;
}
}
I had something like this happen earlier this week - I found out that you have to apply certain ccs elements to the 'parent' element instead of the 'child'. So basically try some of the css like vertical-align: in the .searchform div.
Meanwhile, I'm having trouble with my search icon at smartemini.com. It works in aaaaallllll browsers except ie9. :(
I ran into the same.
I was able to solve my issues, pushing padding from the bottom (!)
padding: 0 0 2px 0; /* total height: 36px */
height: 34px;
or, in a bigger picture, if you fancy consistent input['..'] and anchor button, use distinct overriding tweaking for the latter for full control.
/* general button styling for input and anchor buttons */
.buttonXS, .buttonS, .buttonM, .buttonL {
display: block;
font-size: 14px;
line-height: 14px; /* just a precaution, likely ignored in FF */
padding: 0 0 2px 0; /* total height: 36px */
height: 34px;
...
}
/* distinct vertical align for anchor buttons */
a.buttonXS, a.buttonS, a.buttonM, a.buttonL {
padding: 12px 0 0 0; /* total height: 36px */
height: 24px;
}
(the 'T-shirt-sizes' lead to different background-offsets and widths elsewhere)
What you're seeing here is how differently browsers render text inside button elements when space is tight. Chrome centers the test vertically, while Firefox top-aligns it.
On top of that, you're using a home-made font, that might have some latent issues when it comes to vertical-height/leading/etc.
I note that when I add any other character to the input's value - the magnifying glass drops down even further in Firefox. This suggests that tweaking the font somehow (like vertical-position, or cropping away top/bottom white-space) might help.
If that fails you should change your <input type="submit"/> into a <button type="search" title="Tooltip">Label</button> element, and see if styling the button is any easier than styling the input.
If the problem still remains, you'll need to switch tactics and wrap your button in a <div class="btnwrap" />.
.searchform .btnwrap {
display: inline-block;
overflow: hidden;
height: 32px;
border: 1px solid #888;
/* plus the border-radius styles */
}
.searchform button {
/* all the original button styles, except the border */
height: 50px;
margin: -9px 0; /* (32-50)/2 = -9 */
}
(BTW, You can alternatively inner-wrap button text in a <span/> and do similar negative-margin hack to that, although I suspect that getting the vertical-centering is easier with the button inside adiv.)
That said, you really should just use a good old fashioned background image replacement - it will both render and load faster. :-)
Good luck!
This problem only happens on Firefox 4/Win7 with DirectWrite enabled render mode (which is enabled by default). Firefor4 GDI render mode is working properly.
It might caused by the vertical-align attribute is baseline. But the baseline of U1F50D sin't on the lowest point. Maybe you should try to move the font points a little higher, set the lowest point's y point to 0.
lots of anwsers here... i think this is the simplest way to do this :
.searchform input[type="submit"]
{
height: 35px;
line-height: 35px;
font-size: 2em;
}
Hope this helps =D
I have found that a combination of padding and line-height does the trick. As stated Firefox ignores line-height.
Make sure you set a larger bottom padding than top padding. Fiddle around with it a bit and you will be able to vertically align the text in Firefox.
You will then see that this pushes the text too close to the top of the element in Webkit. Now use a large line-height to align it properly in Webkit and voila!
I have tested this on a Windows 7 machine running Firefox 7, Chrome 16, Safari 5.1 and IE9.