【问题标题】:Setting an Input Box Background设置输入框背景
【发布时间】:2012-06-06 07:43:54
【问题描述】:

我要创建一个具有以下背景的输入框

到目前为止,在我的代码中,我有下面的代码,但它没有显示 -> 正确的程序是什么?

我还必须制作这个按钮的几个变体,它们如下:

  • 按钮黑色区域上的十字 - 我只是要使用带有类的 <span> 标记并将图形设置为该类 -> 这是一个好方法吗?

  • 左侧曲线后的回形针图标 -> 我打算和上面一样 -> 这是一个好方法吗?

HTML:

<div class="innerTo">
        <form action="#" method="get">
           <label for="recipients">TO: </label>
              <input type="search" name="recipients" id="recipients" placeholder="Recipients Names">
    </form>
    </div>

CSS:

.innerBar .innerTo{
    width:200px;
    padding:5px 0 0 15px;
    display:block;
    float:left;
}
.innerBar .innerTo label{
    margin:0 15px 0 0;
    font-size:14px;
    font-weight:bold;
    color:#666666;
}
.innerBar .innerTo input[type=search] {
    color: red;
}
.innerBar .recipients{
    background-image:url('../images/searchBGpng.png') no-repeat;
    width:192px;
    height:27px;
}

【问题讨论】:

    标签: css forms layout input


    【解决方案1】:

    如果您喜欢,我已经为您的表单创建了新代码,然后继续并将其应用于您的 html 代码

    你可以这样做

    HTML 代码

    <form action="#" method="get">
               <label for="recipients">TO: </label>
                  <input type="search" name="recipients" id="recipients" placeholder="Recipients Names">
        <input type="submit" value="">
        </form>
    

    Css 代码

    label{
    float:left;
        margin:25px 0 0 0px;
        padding:0;
    }
    
    input[type="search"], input[type="submit"]{
    margin:20px 0 0 0px;
        padding:0;
         line-height:28px;
        height:28px;
        background: url("http://i.stack.imgur.com/0Vlc5.png") no-repeat 0 0;
        border: 0 none;
        float:left;
    }
    
    input[type="search"]{
    width:152px;
        padding-left:15px;
    }
    
    input[type="submit"]{
    background-position:-167px 0;
        width: 30px;
        cursor:pointer;
    }
    

    现场演示链接在这里http://jsfiddle.net/AL6vb/4/

    现在根据您的布局更改代码,这只是演示......

    【讨论】:

      【解决方案2】:

      Fiddled:

      <div class="input-container">
          <input type="text" value="aaaaaaaaaaaaaaaaaa"/>
      </div>
      
      .input-container {
          background: url(http://i.stack.imgur.com/0Vlc5.png) no-repeat;
          width:197px;
          height:28px;
      }
      .input-container input{
          height:28px;
          line-height:28px;/*results in nice text vertical alignment*/
          border:none;
          background:transparent;
          padding:0 10px;/*don't start input text directly from the edge*/
          width:148px;/*full width - grey on the side - 2*10px padding*/
      }
      

      如果您打算以不同的宽度重复使用它,您应该查找sliding doors technique

      【讨论】:

      • 谢谢 o.v.我是否为我的变体找到了正确的方法?
      • @JessMcKenzie:看看你如何选择使用type="search",你应该可以使用伪元素而不是硬编码跨度等。出现的第一个链接之一:coding.smashingmagazine.com/2011/07/13/…跨度>
      • @JessMcKenzie:另外 - 不是浮汤的忠实粉丝 - 我个人会在容器上设置 position:relative,并将图标绝对定位(你甚至可以定位图标 使用这种方法的容器元素外部,例如left:-20px;)
      • 将 line-height 设置为输入字段的全高后,插入符号在 Windows 上的 Chrome 中看起来会很奇怪。任何想法如何避免这种情况?
      • @damd: 嗯...定义“奇怪”,或者添加截图 + Chrome 版本#?
      猜你喜欢
      • 2012-07-09
      • 1970-01-01
      • 2014-12-03
      • 2014-07-29
      • 1970-01-01
      • 2013-02-09
      • 2021-09-22
      • 1970-01-01
      • 2023-03-25
      相关资源
      最近更新 更多