如何在后跟span标签时选择输入标签?

时间:2018-02-26 03:55:54

标签: jquery html css

我想在input后面选择一个span代码:

HTML:

<input type="text"/>
<span>
    ...
</span>

CSS:

input [followed span] {
    padding:5px; (set input padding, only when followed by span)
}

1 个答案:

答案 0 :(得分:2)

使用此css:

.wrapper {
    position: relative;
}

input {
    padding-left: 48px;
}

.wrapper span {
    position: absolute;
    left: 2px;
}

HTML:

<div class="wrapper">
    <input type="url" placeholder="e.g. www.google.com" />
    <span>http://</span>    
</div>

来源:Display span over input with HTML+CSS