Home >Web Front-end >CSS Tutorial >How to insert pictures into input with css

How to insert pictures into input with css

藏色散人
藏色散人Original
2021-01-11 09:44:198646browse

Css method to insert pictures in input: first set the child element in the div containing the input; then set the outer div positioning to relative; then set the span positioning to absolute; finally add the margin-left attribute to the input That’s it.

How to insert pictures into input with css

The operating environment of this tutorial: windows7 system, HTML5&&CSS3 version, Dell G3 computer.

Recommended: css video tutorial

css insert pictures into input

1. Set in the div containing input Child element

<div class="search">
    <span></span>
    <input type="text">
</div>

2. Set the outer div positioning to relative

.search{
    position: relative;
}

3. Set the span positioning to absolute, and set the width, height and background image

.search > span{
    position: absolute;
    display: inline-block;
    width: 20px;
    height: 20px;
    background: url(./search.png) no-repeat;
    background-size: 80% 80%;
    background-position: center;
}

4. Add margin-left attribute to input.

.search > input{
    width: 100%;
    padding-left: 20px;
}

5. Rendering

How to insert pictures into input with css

The above is the detailed content of How to insert pictures into input with css. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn