Tag Archives: css

Remove rounded corners from input elements on mobile webkit browsers

Mobile Safari is probably the best browser solution for iOS devices. The browser offers many advanced features and some eye-candy form elements to interact with. These eye-candy form elements already have some default webkit-only styles and can make your life a bit harder if you want to style them differently. Anyway, cutting a long story short, if you don’t want input elements to have rounded corners, just use the CSS rule shown below:

See the Pen Remove rounded corners from input elements on mobile webkit browsers by John Tsevdos (@tsevdos) on CodePen

How to style placeholder text

The placeholder attribute is one of the most useful HTML5 attributes, because with just a tiny attribute you provide a better user experience to the end user, you make your code more semantic and all of this is achieved without writing a single line of javascript. But this super easy and time saving attribute is a bit difficult to style. The typical input styles don’t apply to our placeholder! No worries though, in webkit-based and gecko-based browsers you can apply the below rules and style your placeholders.

See the Pen How to style placeholder text by John Tsevdos (@tsevdos) on CodePen

Note 1: Don’t try to combine the selectors because it won’t work! If a browser doesn’t understand a selector it invalids all the following rules and this will always be true in our case, since webkit-based browsers won’t understand the :-moz-placeholder selector while the gecko-based brosers won’t understand the ::-webkit-input-placeholder!

See the Pen How to style placeholder text by John Tsevdos (@tsevdos) on CodePen

Note 2: For some reason the placeholder attribute inherits all the input stytles (ex. color, background etc.) in gecko-browsers (tested in Firefox 14). If you encounter this problem just make your selector more specific.

See the Pen JviFh by John Tsevdos (@tsevdos) on CodePen

Conditional CSS for Firefox/Gecko browsers

Last year I posted how to add conditional comments for webkit-based browsers. This time I found a really cool hack on how to do the very same thing for Firefox/Gecko-based browsers (from Chris Coyier). The solution is again very simple and it’s based on a media query that only Firefox/Gecko-based browsers will parse.

See the Pen Conditional CSS for Firefox/Gecko browsers by John Tsevdos (@tsevdos) on CodePen

Responsive media (images and videos) using only CSS

There’s no reason to explain everything from scratch, there are plenty of posts on this topic, but if you are building a responsive layout, don’t forget to apply these media rules to your CSS file.

See the Pen Responsive media (images and videos) using only CSS by John Tsevdos (@tsevdos) on CodePen

With the above styling rules we ensure that all of our media files (images and videos) are ready for responsive layouts. The first two rules are very easy to understand and probably the safest and simplest way to publish media online (since we are talking about pure HTML5 elements). The final two rules are for embedded media (objects, embeds and iframes), that we simply wrap into a container/wrapper element (with a class of video). I first read of this technique on a post entitled “CSS: Elastic Videos” and personally I believe that it’s the best solution for responsive video embeds. I’m usually against Javascript solutions/alternatives, like for example FitVids.JS, since it’s a pure presentational (CSS) issue and not a functional (Javascript) one.

So if you’re building a responsive layout, try treating your media with the pure CSS approach. It’s the fastest, simplest and cleanest way to achieve responsive media

How to load styles and scripts on a WordPress theme

WordPress provides two useful functions to help you keep the head section on your header.php template file clean. The wp_enqueue_style will help you load your styles and the wp_enqueue_script will help you load your scripts. Both take the same parameters (name, source, dependencies, version, media – only for wp_enqueue_style – and in_footer – only for wp_enqueue_script) and the official WordPress documentation explains everything in great detail. Below I’ll demonstrate a simple way to use them, the same way it works on my latest free WordPress theme, Ambrosia.

These two functions “live” into the functions.php file. So let’s load the styles first. We only have to create an include function (for example ambrosia_load_styles()) that will load all the files using one or multiple wp_enqueue_style functions. To be more  specific, we’ll only load styles in our wordpress theme and not at the admin area (!is_admin()). Then an action hook will run the include function (ambrosia_load_styles()), just before the header.php template file is loaded. It’s simpler than it sounds, have a look at the below code.

It’s much more simple to load script files. We only include our scripts using the wp_enqueue_script function (again excluding the admin area).

Don’t forget that you can create dependencies on both CSS and javascript files, and of course load your javascript files on your footer area (after the page content is fully loaded).

Unfortunately, wp_enqueue_style and wp_enqueue_script functions don’t support any conditional comment mechanism, so if you have Internet Explorer (IE) only styles and scripts, you have to include them manually to your header.php file.

That’s all you need to know, so next time you’re building a theme, keep your header.php file clean by doing all the dirty work into the functions.php file!

Safari’s HTML5 search input

The safest and easiest way to upgrade your markup to HTML5 is to use the new form input types. They will appear as ordinary text inputs on older browsers, and at the same time they’ll save you tons of work on form validation, and as a bonus they’ll assist your users in filling them (by providing more in-browser features, alternate keyboard layouts and more). This blog theme uses a search input to search the site.

<input id="s" name="s" type="search" />Check out this Pen!

It works great, but unfortunately, Safari’s default search input generates a close button (x) into the input field (while you type). Supposedly this will help the users to view recent search keywords, but if they they decide that they don’t need help, they can just click it and remove everything from list and the input field. I didn’t need this in-browser style for my search input, so after an investigation, I discovered the below solution.

input[type="search"] {
  -webkit-appearance: textfield;
}Check out this Pen!

This rule will transform your search input (with the strange close button) into a typical text field input that you can style properly.

Conditional CSS for Webkit-based browsers

On a recent project I had to find a way to apply CSS only on webkit-based browsers. We are all, more or less, very familiar with IE’s conditional comments, but what about other browsers? For webkit-based browsers, the solution is fairly simple. We only need to add our CSS statements into a “special” media query, that only webkit-based browsers will parse :

@media screen and (-webkit-min-device-pixel-ratio:0) {  
/* CSS Statements that only apply on webkit-based browsers (Chrome, Safari, etc.) */  
  body { background:#ccc; }  
}Check out this Pen!

Nice ‘n easy ;-)

CSS3 PIE : My new favorite IE enhancement

IE sucks big time, period! Even version 8 doesn’t support many useful CSS rules such as border radius and box shadow, both standard things for 2010. For those who already use all the nice CSS3 features that IE doesn’t support, try CSS3 PIE. The installation is easy (you only need to upload one file and that’s it) and after that, you’ll finally force IE to support many CSS3 features such as border-radius, box-shadow, border-image, multiple background images, linear backgrounds, rgba as well as some other features. Give it a try, it’s not bad at all (plus you keep all the behavior into your CSS file, you don’t need to write/code/attach any Javascript code).