Safari Mobile: Toggle contents on touch - css

I am adapting a website in order to make it feel native on the iPad.
This website has navigation that shows a drop-down with the sub-navigation on hover.
This works like a charm on the iPad. When you touch it the subnav, it opens and closes again when you click/touch somewhere else.
Now i have the requirement to make it close again when the navigation point is touched again.
I was thinking, i could just set the pointer-events:none on hover & active for the iPad, but this makes the sub-navigation flicker and it does not work...
i have also tried to cover the navigation point with element set with the before selector and setting its pointer events to none, but this does not work...
Any idea, how i could solve this problem using CSS only. (I can not modify the HTML nor the JS)
PS: you can reproduce this on www.macprime.ch for example... (click the main navigation on the top, and try to close the dropdown again)
edit ok i tried almost everything that was possible with CSS only. I don't think its possible. If anyone can tell me why, he/she will get the bounty reward.

You could have a second transparent element that appears above the one you tapped. That way, when the user taps again, they will be selecting the other element and the first will lose its hover status:
<div class="blocker" onclick="void()"></div>
<div class="menuItem" onclick="void()"></div>
<style>
.blocker, .menuItem {
/* use the same position, width, height, etc */
}
.menuItem {
/* make it look pretty */
z-index: 100;
}
.blocker {
z-index: 99;
}
.menuItem:hover {
z-index: 98;
}
</style>
Of course, this will have a negative effect on the desktop, so you will want to do something like:
<style>
.blocker { display: none; }
.touchevents .blocker { display: block; }
</style>
<script>
if('ontouchstart' in document)
document.body.className += ' touchevents';
</script>
UPDATE Added onclick events to make them clickable.
You can see a working demo here: http://fiddle.jshell.net/vfkqS/6/
Unfortunately, I could not find a solution that does not require HTML or JavaScript changes, but I was able to keep them to a minimum.
You would need to make two non-CSS changes total:
Add a JavaScript mechanism for identifying if touch events are supported. See two line example above.
Add one div per menu which is clickable (onclick="void()") and has a unique identifier that can link it to the menu.
You may be able to do those two things with CSS but I'm not sure. Tablet detection would be a little sketchy in CSS and I don't think you can make something that sophisticated with a :before or :after pseudo-selector.

This is an interesting question and similar to one I've had come up recently. How do you marry a standard navigation dropdown that displays on hover with a touch event interface. Using the hover event as a trigger works really well on a desktop. In a world without hover events (tablets and smart phones), not so much.
In my case I landed on the idea of defining the behaviors: click/touch event would do the triggering, hover event would do subtle indications. For more details on this line of thinking see: http://www.markdotto.com/2012/02/27/bootstrap-explained-dropdowns/
For the issue you're trying to overcome I'm wondering if using #media queries in your CSS is a better solution...
#media (max-width: 979px) {
/*
New CSS declarations to show the sub navigation lists
in a more compact way that fits nicely on the iPad.
Something like...
*/
section.nav-overlay {
display: block;
height: 60px;
visibility: visible;
width: 979px; /* Or the max container width */
}
section.nav-overlay ul li {
float: left;
}
/*
Etc. etc. with the additional exceptions.
You get the idea.
*/
}
By doing this you would create more of a native interface on the iPad. However, if going this route is off the table, something like what Brian has above is better. Just wanted to give you an alternative.

Set pointer-events: none on the active state:
nav#mainnavi > ul > li > a:active {
pointer-events: none
}

Related

Styling native Google Chrome Video Controls

Hello I am tired of the boring looking Google Chrome native html5 video player design.
It's getting worse with every time they change it.
Right now it's in a bright white which is completely unsatisfying when you ask me.
So I decided to create a little userstyle to make it dark.
This is how far I came but it's not possible for me to change the color of the little circle.
Any help is welcome.
This is my actual progress:
video::-webkit-media-controls-panel {
background-color: #161618;
}
video::-webkit-media-controls-volume-slider-container {
background-color: cyan;
}
video::-webkit-media-controls-volume-slider {
background-color: #1FB2B0;
}
video::-webkit-media-controls-timeline {
background-color: #1FB2B0;
}
Here is the jsfiddle link for it.
https://jsfiddle.net/cyc1j0nv/7/
I eventually got where I wanted to go (more or less) by applying a filter to the media controls as a whole. Of course, one could also apply filters to each pseudo-element of the controls individually.
video::-webkit-media-controls{
filter: hue-rotate(180deg) brightness(0.9);
}
<h1>Styling video controls</h1>
<video controls src="https://a.desu.sh/zflbzy.webm"><</video>
*Note: it's up to the user to add vendor-prefixes to the CSS as required
There isn't any CSS style to change the little blue circles in the same sense as your example; they're images that are packaged into chrome. Maybe one of the css3 image filter properties would work.
There's also a small caveat to overriding these styles in general: they are internal to chrome, and are subject to change at any time. Pages that depend on them might find that they simply don't work the same way in some future version of chrome.
If you'd like media controls with a custom look on your page, then you might want to take a look at the many javascript media players that give you quite a bit more flexibility. They also work across different browsers.
I succeeded in positioning the controls in a way without overlay the original video screen by:
video::-webkit-media-controls-enclosure {
overflow:hidden;
position: absolute;
bottom:-32px
}
video::-webkit-media-controls-panel {
display: flex !important;
opacity: 1 !important;
}
hide download button by adding:
video::-internal-media-controls-download-button {
display:none;
}
video::-webkit-media-controls-panel {
width: calc(100% + 30px);
}

Polymer paper-fab display square mask in mobile

I have a paper-fab on my index page and it is displaying right until I tap on it. I say tap because this behavior only occours in mobile environment (in the chrome mobile view or on my Nexus 5).
This is the active button (on tap):
Note that the background is light gray. This square around the button is what I want to remove. The button is perfectly round. But this thing appears when tapped.
I tested other applications, like Topeka, and the active button (on tap) displays right:
But aparently there's nothing in special between my paper-fab and Topeka's one.
Here's the element declaration and the CSS:
<paper-fab icon="add" id="add-button"></paper-fab>
paper-fab#add-button {
position: relative;
background-color: #3F51B5;
display: block;
margin-bottom: 15px;
}
Is there something wrong?
Thank's in advance.
Your silver bullet is:
body {
-webkit-tap-highlight-color: rgba(0,0,0,0);
}
I suggest also that you attended to specify shim-shadowdom parameter for your style declaration:
<style shim-shadowdom>
BTW, you might want to compare your code against official paper-fab docs rathen than topeka.
Hope it helps.

Underline transition in menu

I have a menu with a lava-lamp like underline that looks like this:
The underline slides between links when clicking on them. Try a jsfiddle HERE.
My only problem is that if you click outside the menu the underline reverts back to it's original state (18%). But I want the underline to stay on the last clicked link when you click outside the menu.
I've tried :visited but it doesn't do anything.
You can actually do this with pure css using The :target pseudo class.
Here is an updated working fiddle
Note: You'll need a modern browser to use this method. (IE9+)
Also, take a look at this article which shows some clever ways to simulate click events with css (one of them being the :target pseudo class.
You may be able to do this through CSS, I really don't know.
But why don't you just use these 3 lines of JS (jQuery) and replace the Style-definition by this:
$('.ph-line-nav').on('click', 'a', function() {
$('.ph-line-nav a').removeClass('active');
$(this).addClass('active');
});
nav a:nth-child(1).active ~ .effect {
left: 18%;
/* the middle of the first <a> */
}
nav a:nth-child(2).active ~ .effect {
left: 43.5%;
/* the middle of the second <a> */
}
Seen in this jsFiddle: Click me!

Styling a phone number in CSS that has been altered with the Skype plugin

We have a phone number at the top of our website, for customers to call us of course. I have the Skype plugin, which is handy and I've noticed other users have it too. But it throws off the design completely. I noticed the html of the webpage is altered with css styles. Is there a standard way to alter the appearance of the Skype phone numbers?
UPDATE: The phone number is altered with this span tag added around it:
<span class="skype_pnh_print_container_1359399953">
Then there's a ton of span tags after this which is the Skype menu when you hover your mouse over the phone number (hidden initially). I could override styles with this class, but I want to make sure I do this the proper way so that it works with different (newer) versions of Skype and all browsers (Skype might work differently in other systems?). Isn't there some official way of dealing with this?
body span.skype_pnh_container {
/* "body" is not really necessary */
/* here, but it increases CSS */
/* specificity – just in case ... */
display: none !important;
visibility: hidden !important;
}
body span[class^="skype_pnh_container"] {
/* override the 'skype' styling */
color: red!important;
background-color: green!important;
}
body span[class^="skype_pnh_print_container"] {
display: inline !important;
}
copy pasted from the net
Also, according to http://forum.skype.com/index.php?showtopic=78380 you can prevent it with the following META tag:
<meta name="SKYPE_TOOLBAR" content="SKYPE_TOOLBAR_PARSER_COMPATIBLE" />
Carry on
Here's how I styled the Skype links:
a[href^="skype:"] {
color: white;
}
Personally, I don't see any additional markup like extra Skype span tags, so the above CSS code should work for any Skype call links.

Z-index problems in IE Quirks mode

I'm working on this site: http://stdionis.org.uk/
When the site is viewed in IE 9 or below, the drop down menus on the home page appear underneath the slideshow (It's a google slideshow), however when you go to another page, the drop-downs appear on top of images.
I've set the z-index of the drop-down div to 9999, and I've tried setting the z-index of the slideshow to zero, but I can't seem to make it work.
The CMS we are using doesn't directly allow access to the HTML code of the page (don't ask...) so I can only use CSS or javascript to make changes. Hence why i can't change the doctype to make it display in standards mode.
Not looking for a clean solution necessarily, any crazy javascript hacks would be much appreciated.
try this -
.t_horizontal * { z-index: 1000 !important; }
or
.t_horizontal table { z-index: 1000 !important; }
if even not working then - try using jQuery -
$(document).ready(function(){
$('.t_horizontal *').css('z-index','1000 !important');
});
NOTE: menu is using table which is not proper way to build menu.
Have you tried:
#ctlHeaderModules {
position: relative;
z-index: 2;
}
#frm1 {
position: relative;
z-index: 1;
}
Both of these two elements are on the same level and when I inspect them in Chrome I dont see any of these properties being applied, its worth a shot.
There is also this plugin: http://archive.plugins.jquery.com/project/TopZIndex

Resources