How to apply max-width style for Firefox/IE/Chrome - css

I am using the css style max-width:236px which produces exact view for chrome/IE but not in Firefox. In order to produce the same thing for Firefox I need to give max-width:219px; in this case IE/chrome is not working. How can I give the two different values in max-width properties for cross browser issue. Your suggestions are valuable. Thank you.
// IE/Chrome is good
textboxwidth {
max-width: 236px;
}
// FireFox is good
textboxwidth {
max-width: 219px;
}

Add box-sizing: border-box; to your style.
Firefox's default TextBox includes more padding than IE/Chrome. box-sizing: border-box; changes the width to include padding, as opposed to the standard method of adding the two together to get absolute width.
EDIT: Paulie_D posted the same answer in the comments above, just to give additional credit where it's due.

Related

delete white space between border top and content (background colour) [duplicate]

What’s the default margin that HTML sets for its <body> tag? I noticed that there’s some automatic margin, but I’m wondering if anyone knows how much it is (and whether it’s in px or %, etc.).
In most major browsers, the default margin is 8px on all sides. It is defined in pixels by the user-agent-stylesheet your browser provides.
Some browsers allow you to create and use your own user-agent-stylesheet, but if you are developing a website, I would recommend staying away from changing this, since your users most likely will not have a modified stylesheet and would then see a different page than you do.
If you want to change it, you can just do this:
body {
margin: 0px;
padding: 0px;
...
}
But if you have a large project and want to be more complete, use normalize.css. It resets a lot of default values to be consistent across browsers.
According to W3School's CSS reference,
the default properties and values for a body tag are,
body{ display : block; margin : 8px; }
And one can quickly get the computed details of any element by accessing the Computed Pane in the Chrome Dev tools.
css default values
https://www.w3schools.com/cssref/css_default_values.asp
body{ display : block; margin : 8px; }
* {
margin: 0;
padding: 0;
}
The body can also be reset using the asterix tag.

Can't get rid of the padding on the right [duplicate]

What’s the default margin that HTML sets for its <body> tag? I noticed that there’s some automatic margin, but I’m wondering if anyone knows how much it is (and whether it’s in px or %, etc.).
In most major browsers, the default margin is 8px on all sides. It is defined in pixels by the user-agent-stylesheet your browser provides.
Some browsers allow you to create and use your own user-agent-stylesheet, but if you are developing a website, I would recommend staying away from changing this, since your users most likely will not have a modified stylesheet and would then see a different page than you do.
If you want to change it, you can just do this:
body {
margin: 0px;
padding: 0px;
...
}
But if you have a large project and want to be more complete, use normalize.css. It resets a lot of default values to be consistent across browsers.
According to W3School's CSS reference,
the default properties and values for a body tag are,
body{ display : block; margin : 8px; }
And one can quickly get the computed details of any element by accessing the Computed Pane in the Chrome Dev tools.
css default values
https://www.w3schools.com/cssref/css_default_values.asp
body{ display : block; margin : 8px; }
* {
margin: 0;
padding: 0;
}
The body can also be reset using the asterix tag.

How to avoid the borders/margins that arise from the body tag?

I'm new to CSS. I've got a deceptively simple problem. This is a fiddle of a simple page.
http://liveweave.com/c6j68I
The objective is to show a fixed 900px white div centered against a coral background.
I've tried to achieve this using two divs maked #outerWrapper and #wrapper.
However, the whole page still seems to have a white background, which seems to be connected to the body tag. (Please use the fullscreen mode to see it).
If I give the body the background color of the #outerWrapper, again, the color appears on the top and bottom of the page too, which is undesired. (Please uncomment the CSS of body to see this.)
I've tried using the article tag; using negative margins; and changing dimesions of the body tag. Nothing seems to work.
In simple terms, a want a 'columned' look: coral-white-coral; instead of the 'boxed' look I currently have.
Please help.
Just add a style for the body in your CSS and set the margin to 0px, like so:
body {
margin: 0px;
}
Because most major browsers, the default margin is 8px on all sides. It is defined in pixels by the user-agent-stylesheet your browser provides.
If you want to change it, you can just do this, add it on your css
* {
padding:0;
margin:0;
}
Want to be more complete?
use normalize.css. It resets a lot of default values to be consistent across browsers.
Try adding the following
<style>
body,html {height:100vh; width:100vw; padding:0; margin:0;}
</style>
Body has default margins set by the browser (most browsers set default styles to different elements and they can vary depending on the browser) as seen below in developer console.
Note: In most browsers you can open the developer console by pressing F12 on your keyboard:
Just set the following css to avoid it:
html, body {
margin: 0;
padding: 0;
}
Demo: http://liveweave.com/EzWH0o

IE10 removes padding on input with right alignment

I've come across some IE10 wierdness regarding padding in a right aligned inputfield.
Check this fiddle http://jsfiddle.net/fhWhn/
::-ms-clear, ::-ms-clear{
display: none;
}
This removes the "IE10 icons" but what do I do if I want to keep these and keep my padding?
Is there another, smarter, way of keeping the padding after onblur?
I ran in to this same problem. To get padding back, just set the value of the textbox on blur.
My simple solution:
$("input[type='text']").blur(function (evt){
var $element = $(this);
$element.val($element.val());
});
A possible workaround is to use the style direction: rtl; on your input, which will move the × to the left-hand side of the element. However, the behavior of using right-to-left may not be ideal for your case.
JustinStolle's answer is the best approach, I think.
Example:
input[type="text"].field-al-right{
text-align:right;
direction:rtl;
}
Edit: Eric's solution worked for me and is much nicer, but I'm leaving this answer here in case some future version of IE needs a different fix
New IE, New IE-specific rendering issues...
I've been debugging the same behaviour. The only thing I've found that works so far is:
Removing focus from the input (even explicitly setting the “padding-right” per element has no effect while it has focus)
Setting the padding-right value to a different value to the correct value (setting it to the correct value triggers no change, presumably because the layout system knows the computed CSS value hasn’t changed so decides no re-draw is necessary)
Waiting for a re-draw (instantly – or even after a timeout of 1 or 2 milliseconds - setting the property again to the correct value results in no change, presumably because no re-draw has taken place as per above)
Setting the property to the correct value (e.g. using $this.css("padding-right", ""), which removes any per-element value and allows the computed CSS value to take over).
However this is of course undesirable as it involves removing focus from the input when the user may be in the middle of typing.
have you try adding 'box-sizing' to your css?
* {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
padding: 0;
margin: 0;
}

margin-top not working with :before

I have inserted content using the :before pseudo-element for a class. I was trying to position this content using margin-top but firefox is simply ignoring the property. The code follows:
.bef {
line-height: 2em;
white-space: nowrap;
font-size:24px;
display: block;
}
.bef:before {
display: block;
margin-top:2em;
padding: 0;
color: #666666;
content:"Hello";
}
Does anybody know why Firefox may be ignoring the margin-top property?
EDIT: Although margin-top is being totally ignored, margin-bottom:-Xem is working and I am able to move the :before element around
It appears that Darko Z is right.
http://jquery.nodnod.net/cases/577
Hypothetically, the first two test cases (separated by <hr>) should render identically, which they do in Gecko (via FF3.5/Mac), but Webkit (via Safari4/Mac) renders the :before and :after segments as inline. The third test case seems to imply that Webkit currently requires the triggering element to be block in order for the generated content to be block.
The spec isn't clear on what the correct behavior is. It may be worth raising a question on www-style to see which rendering engine's behavior is correct, then filing a bug with the incorrect rendering engine to get it fixed in future versions. Feel free to use my code as a test case.
try making .bef display block also? just a guess that the containing element of the :before needs to be block so it can listen to the margin-top...

Resources