4

I'm trying to create an alternate design to a site as a fallback. I can't really change how the system is architected. A main stylesheet is loaded, and a second is loaded after it. I have control over the second stylesheet. There's a lot of the CSS that I want to reset, specifically form elements.

However, I'm having difficulty with that. For example with a <button>:

background: rgb(88,222,255);
border-radius: 4px;
border: 1px solid #91d7eb;
box-shadow: 0px 2px 4px 0px rgba(1, 75, 138, .8);
color: #FFF;
cursor: pointer;
font-family: "Graphic-Font";
font-size: 25px;
font-weight: bold;
text-shadow: 0px 1px 3px #014b8a;
padding: 10px 40px;

While I can set background: none, border-radius: none` and so on, what happens is the button has no style, rather than the default browser style. I have to get the form elements to be the default browser style, among many other elements on the page. But I can't seem to get at least the form elements to be unstyled.

For Clarity Simplifying the question: How does one re-style a <button> back to default?

user1337
  • 827
  • 7
  • 18

2 Answers2

1

I would suggest using a CSS reset as a starting point (Eric Meyers' is probably the most famous).

I think you're running into trouble on things where you don't want to set your own style, but return it to the browser default (e.g. you don't want margin:0; on everything, you want the default big margin on the H1, the default smaller one on the p, etc.

You can actually get copies of the user agent stylesheets, modify them to make them more specific, and include them to overwrite. Here is a site that has copies of a lot of default UA stylesheets. A problem here is that every browser uses their own, so unless you browser detect and serve selective stylesheets, it's not going to really look like it normally does for that browser. However, I think that's ok. I'd actually suggest you just pick a browser default you like and set all browsers to look like that, or you can use the W3C's suggestion for default browser styles.

All of this doesn't solve your problem though, because styling form elements is hell. As soon as you apply a style, some browsers will switch the rendering mode for the form element so you can never get it back to the original style. For example, IE7 doesn't support rounded corners, yet their default buttons have rounded corners, because it renders in Windows OS style. But as soon as you give the button a border, or some other style, it loses that nice Windows shaded rounded corner default look, and there's no way to get it back without using an image!

So really, I wouldn't shoot for trying to get browsers to go back to their native default style. I'd use a UA default stylesheet, and then modify it so make a sort of generic, cross-browser, cross-system default. It won't look like the native unstyled code, but it will look close enough.

brentonstrine
  • 21,694
  • 25
  • 74
  • 120
  • You understand my question :) Unfortunately, I can't use browser detection. So if there really is no way to get it to go back to browser defaults, then I guess that's my answer. – user1337 Jul 26 '12 at 18:46
  • The problem is: there are no "standard" button defaults. They're different in very browser, which is why we use a CSS reset to begin with. – Diodeus - James MacFarlane Jul 26 '12 at 18:50
  • Browser detection is possible, but it doesn't really solve your problem, as you're primarily focused on getting form elements to their original default. I don't know of any way to do that in every browser once you've applied styles. I think you might have good luck with Gecko, Presto (Opera) and WebKit rendering engines, but something makes me think Trident (Internet Explorer) won't let you reset it, especially in <7. But again, you can rebuild a "default looking" button with CSS that won't be exactly the default, but still looks default enough. – brentonstrine Jul 26 '12 at 18:51
0

You need to understand how CSS specificity works. You can overwrite any CSS rule, by making it more specific than other rules.

For example:

<div class="content">
    <div class="wrapper"><span>Hello World</span></div>
</div>

CSS:

.content .wrapper span { ... }
.wrapper span { ... }

In this case the first declaration will overwrite the second, because it is "more specific". You can usually just go up the tree one level and specify the wrapping element or the wrapping class to override an inner element's rule. This is really handing on a lot of CMS systems, such as WordPress, where you don't have access to the main stylesheet, or just want to leave it alone and re-skin the parts you want.

Read the article, it's important.

CSS Specificity: Things You Should Know

Diodeus - James MacFarlane
  • 112,730
  • 33
  • 157
  • 176
  • 1
    I don't think that it answers his questions. It seems he knows how to overwrite. He wants to know how to reset all css rules for an element to default. – Sven Bieder Jul 26 '12 at 18:17
  • 1
    Yes, @SvenBieder is right. I understand specificity just fine. I can "unstyle" all of the other elements on the page with relative ease, but the form elements are proving difficult. I need to retore the default browser style, not apply new styles. – user1337 Jul 26 '12 at 18:23
  • They're both sides of the same coin. Essentially you are re-styling it back to default. There are a number of un-resets floating around out there you can grab: http://www.jbcrawford.net/archives/tag/un-reset-css http://www.cssreset.com/scripts/vanilla-css-un-reset/ – Diodeus - James MacFarlane Jul 26 '12 at 18:28
  • 2
    @Diodeus I think you're stil not quite understanding. I just looked at both of those and they do not do what I'm asking. The second doesn't even mention `button` and the first only sets it to `display:inline-block`. Simplifying the question: How does one re-style a ` – user1337 Jul 26 '12 at 18:35