Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Changing Appearance Of Element With CSS

DZone's Guide to

Changing Appearance Of Element With CSS

· Web Dev Zone
Free Resource

Learn how to build modern digital experience apps with Crafter CMS. Download this eBook now. Brought to you in partnership with Crafter Software

I've recently just found this interesting CSS property that allows you to style any element you want as a browser default element.

Each browser has there own default styling for the standard HTML elements you can find on a page, for example a button in Chrome will look different than a button in Firefox.

With this CSS property you apply this to any HTML element and it will look like the default element in that browser. You can now style that anchor tag link to look exactly like that button, or make a paragraph look like a textbox.

All you have to do is use the CSS property -appearance.

This is currently only supported in webkit and firefox browsers so you need to prefix the property with the browser prefixes.

.lookLikeAButton{
     -webkit-appearance:button;
     -moz-appearance:button;
}
.lookLikeAListbox{
     -webkit-appearance:listbox;
     -moz-appearance:listbox;
}
.lookLikeAListitem{
     -webkit-appearance:listitem;
     -moz-appearance:listitem;
}
.lookLikeASearchfield{
     -webkit-appearance:searchfield;
     -moz-appearance:searchfield;
}
.lookLikeATextarea{
     -webkit-appearance:textarea;
     -moz-appearance:textarea;
}
.lookLikeAMenulist{
     -webkit-appearance:menulist;
     -moz-appearance:menulist;
}

Then you can use these CSS classes in the HTML.

<p class="lookLikeAButton">This is a paragraph
<p class="lookLikeAListbox">This is a paragraph
<p class="lookLikeAListitem">This is a paragraph
<p class="lookLikeASearchfield">This is a paragraph
<p class="lookLikeATextarea">This is a paragraph
<p class="lookLikeAMenulist">This is a paragraph

There different elements you can change the appearance to can be found here.
http://css-infos.net/property/-webkit-appearance

In the demo I change paragraphs to these different elements.

Demo

Crafter is a modern CMS platform for building modern websites and content-rich digital experiences. Download this eBook now. Brought to you in partnership with Crafter Software.

Topics:

Published at DZone with permission of Paul Underwood, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}