Text-area with em not working in IE and Opera

旧城冷巷雨未停 提交于 2019-12-23 00:30:07

问题


This is my first attempt to make a complete webpage layout in 'em' measurements. I am building a live preview markdown editor.

This page works perfectly in Firefox and chrome, but in IE(i have IE9) and Opera(updated last night) The text-area shoots the boundary significantly. In Opera, the border of textarea is also not showing rounded corners. ( text area is showing rounded corner but not its border)

This is css for the textarea

#pad {
    background-color:#BBBB99;
    background-image:url("../img/edit.png");
    border-color:rgba(32, 32, 52, 0.39);
    border-radius:1em 1em 1em 1em;
    font-size:1.3em;
    height:33.3em;
    margin:0.3em;
    outline:medium none;
    padding:0.9em 0.7em;
    resize:none;
    width:26em;
    text-align: left;

}

and this is the html snippet

<div class='container'>
  <div id='left'>
    <textarea id = 'pad' wrap="on" ></textarea>
  </div>

  <div id='right'>
    <div id='preview'></div>
  </div>
</div>

I have set 'font: 100%' in the body. Here is the link of demo if you need to check it.


回答1:


I think the problem is caused by the changing of the font-size in #pad.

When you set a base font-size, for example 18px, then all the child elements treat 1em as 18px. However, if you change the font-size in one of the children to 1.2em then all the child elements nested within that child will start treating 1em as 22px:

body {
    font-size: 18px;
}

.parent {
    font-size: 1em;   /* 18px */
}

.child {
    font-size: 1.2em  /* 22px */
}

.child > .child {
    font-size: 1em;   /* 22px */
}

What I think is happening in Internet Explorer is that the font-size is being changed to 1.2em before the width of #pad is calculated. So the width in Firefox and Chrome is 26 * 18px where as in IE the width is 26 * 22px.

To get around this, I would set the width as a percentage instead of a fixed em measurement.

Edit

In regards the the rounded corners issue in Opera; it seems that Opera does not take kindly to the fact that neither the border-width nor border-style have been set.

Try changing border-color to border: 1px solid rgba(32, 32, 52, 0.39); and see if that resolves your issue.




回答2:


for special css3 features, use vendor prefixes for each browser :
instead of border-radius:1em 1em 1em 1em; use :

-webkit-border-radius:1em;
-moz-border-radius:1em;
-o-border-radius:1em;
-ms-border-radius:1em;
border-radius:1em;


来源:https://stackoverflow.com/questions/11171977/text-area-with-em-not-working-in-ie-and-opera

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!