Div And Textarea Behave The Same Except In Firefox - What To Do?
.highlighter {
background-color: #eee;
color: #f0f;
-moz-box-sizing: border-box;
-moz-padding-end: 1.5px;
-moz-padding-start: 1.5px;
}
Setting these properties ensures that
- In Firefox, the padding set on the
div
does not increase the width of thediv
, and - that, in Firefox,
1.5px
of padding will be set on both the right and the left hand side of thediv
.
Update
After some time of using 2px
and still very occasionally experiencing some wrapping inconsistencies, I decided to give 1.5px
a go, and for now that seems to have ironed out the occasional inconsistencies.
Solution 2:
This has to do with the font size being used. Since the unit used is point (pt)
, the size calculated is different enough in the browsers to cause the incorrect line wrap.
Try these styles instead:
* {
font-family: sans-serif;
font-size: 12px;
font-weight: normal;
}
body {
font-size: 1em;
}
You might have to make changes in the container sizes to accomodate the change in font-size.
Solution 3:
Okay, couple of things going on here. Generally, the safest cross-browser displayed element you'll find is the pre
tag. It assumes that what you're feeding it is "pre-formatted," hence the name. This will benefit us in a couple ways:
- As far as I know, there is no default styling done by any major browser done on the
pre
element. - The
pre
element will retain leading/trailing whitespace, tabs and other special characters in a box.
Replace the span.highlighter
with pre.highlighter
That'll get us started. The second thing we'll want to look at is the overlaid colors creating some rather bizarre stacking effects in Firefox. The text looks out of focus in FF20, and I can only imagine that letting a browser decide how that looks would be a catastrophe going forward.
Set the color of the textarea
to transparent
.
Now we're there. I'm seeing consistent wrapping in IE10/9, FF20, and Chrome 26.
Post a Comment for "Div And Textarea Behave The Same Except In Firefox - What To Do?"