Positioning background image on form element with CSS sprites

前端 未结 1 615
没有蜡笔的小新
没有蜡笔的小新 2021-01-19 14:13

I am trying to get a magnifying glass as the background for my input element. The magnifying glass icon is part of a CSS sprite that looks like this:

1条回答
  •  [愿得一人]
    2021-01-19 14:55

    You declared background-position two times. The first one at the end of the background short-hand property, the second one on the next line. Solution: Split all single background rules like this (additionally, 0 -24px is the correct value):

    #search-form input[type="text"] {
        background-image: url('http://i.stack.imgur.com/MFpLm.png');
        background-repeat: no-repeat;
        background-position: 0 -24px;
        border: 1px solid #a9e2ff;
        padding: 3px;
        width: 200px;
        font-size: 1em;
        padding-left: 20px;
    }
    

    And now you can face the real problem with your design: other sprites will be visible in the input area if there are no sufficient space between them.

    0 讨论(0)
提交回复
热议问题