Rounded corners for <input type='text' /> using border-radius.htc for IE

前端 未结 6 1475
遇见更好的自我
遇见更好的自我 2020-12-29 03:28

I want to create an input fields with rounded corners.

HTML:

6条回答
  •  时光说笑
    2020-12-29 04:05

    W3C doc says regarding "border-radius" property: "supported in IE9+, Firefox, Chrome, Safari, and Opera".

    Hence I assume you're testing on IE8 or below.

    For "regular elements" there is a solution compatible with IE8 & other old/poor browsers. See below.

    HTML:

    Some text Some text Some text Some text

    CSS:

    .myWickedClass{
      padding: 0 5px 0 0;
      background: #F7D358 url(../img/roundedCorner_right.png) top right no-repeat scroll;
      -moz-border-radius: 10px;
      -webkit-border-radius: 10px;
      border-radius: 10px;
      font: normal 11px Verdana, Helvetica, sans-serif;
      color: #A4A4A4;
    }
    .myWickedClass > .myCoolItem:first-child {
      padding-left: 6px;
      background: #F7D358 url(../img/roundedCorner_left.png) 0px 0px no-repeat scroll;
    }
    .myWickedClass > .myCoolItem {
      padding-right: 5px;
    }
    

    You need to create both roundedCorner_right.png & roundedCorner_left.png. These are work around for IE8 (& below) to fake the rounded corner feature.

    So in this example above we apply the left rounded corner to the first span element in the containing div, & we apply the right rounded corner to the containing div. These images overlap the browser-provided "squary corners" & give the illusion of being part of a rounded element.

    The idea for inputs would be to do the same logic. However, input is an empty element, " element is empty, it contains attributes only", in other word, you cannot wrap a span into an input such as to then use background images like in the previous example.

    Hence the solution seems to be to do the opposite: wrap the input into another element. see this answer rounded corners of input elements in IE

提交回复
热议问题