CSS hover menus with Microsoft Surface (touch device)

If you have a css hover menu you may notice that it doesn't play well with Microsoft Surface IE with either a touch pen or finger. A long press shows the menu but on releasing the menu hides again.

This is because the touch device is unaware that the hover menu is supposed to remain visible after the hover intent has ended. iOS and other touch operating systems handles this logically but the powers to be seem to require websites to be "touch optimised".

Here's what you need to do:

<nav>
	<ul>
		<li>
			<a>Hover menu</a>
			<ul>
				<li><a href="http://example.org">Item 1</li>
				<li><a href="http://example.org">Item 2</li>
				<li><a href="http://example.org">Item 3</li>
			</ul>
		</li>
	</ul>
</nav>

You'll need to make sure that your hover anchor has an href on it to make it "touchable" on certain devices, you can do this with either href="#" or href="javascript:void" , then you need to add aria-haspopup="true" to tell the device that after the user releases the tap, whatever was visible should remain visible until another interaction.

<nav>
	<ul>
		<li>
			<a aria-haspopup="true" href="#">Hover menu</a>
			<ul>
				<li><a href="http://example.org">Item 1</li>
				<li><a href="http://example.org">Item 2</li>
				<li><a href="http://example.org">Item 3</li>
			</ul>
		</li>
	</ul>
</nav>

Graceful degradation Helvetica Neue font family

Here's the tested and proven method of using Helvetica Neue fonts on your website. No Helvetica? No problem, degrades to Arial and Sans Serif for safety.

body {
	font-family: "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, sans-serif; 
	font-weight: 300;
}

On webkit browsers the font (along with others) may appear to have spare pixels around the lettering, making it look "fuzzy". To fix this we can tell webkit browsers to smooth the text with antialiasing:

body {
	-webkit-font-smoothing: antialiased;
}

This font stack originally appeared on CSS Tricks and has been modified slightly for compatibility with devices.

Disable text selection with CSS

Cross browser CSS to correctly disable user selection of elements.

-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;

Although you should not need to interfere with normal selection behavior or conflict with a user's expectations when it comes to text selection, there are a few scenarios in which this property. For example:

  • Navigation buttons in which you do not want the user to accidentally select the text of the button instead of clicking it. (Some browsers e.g. Safari actually let you select the text of normal buttons).
  • This may be necessary for embedded devices. i.e. a device where a browser is used for rendering the UI.
  • There are also legal issues where 3rd party content is being legally republished but a clause in the license requires web publishers to prevent text from being easily copied and pasted.

A JavaScript option should be avoided due to the inconsistencies of browsers.