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

How to insert pictures into input with css

藏色散人
Release: 2022-12-30 11:11:29
Original
8635 people have browsed it

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>
Copy after login

2. Set the outer div positioning to relative

.search{
    position: relative;
}
Copy after login

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;
}
Copy after login

4. Add margin-left attribute to input.

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

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!

Related labels:
css
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template