简体   繁体   中英

How can I use CSS or JS to make some text inputs display a help icon inside the input?

I don't much like external help icons, as they hinder consistent layout, and would much prefer to place the help icon inside inputs marked with eg a with-help class. They would look something like this:

输入带有内部帮助图标

I would also much prefer that the 'icon' be an SVG shape. Is that possible with CSS, or would I need JS to add the SVG shape to all such inputs?

Have a look at below code. change the value of border-width: 0 30px 30px 0; to change the size of triangle, and change text-indent:16px; to align question mark.

 .help{ position:relative; display:inline-block; } input{ padding:10px; } .help a:before{ content: "?"; position:absolute; top:0; right:0; display:block; width: 0; height: 0; border-style: solid; border-width: 0 30px 30px 0; border-color: transparent #007bff transparent transparent; text-align:right; text-indent:16px; color:#fff; } 
 <div class="help"> <input type="text" > <a href=""></a> </div> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM