[英]create and use a CSS form in <Style>, not in <Body> with HTML
[英]How to create a tagging style with css, html and jquery?
我在表单中有一个input[type=text]
元素和一个用于选定元素的div。
我需要创建自己的自定义标签插件容器,而我的问题是标签容器的CSS样式和布局以及外观。
这是我的实际阶段(非常差): http : //jsfiddle.net/db8upk61/1/
挑战
有很多插件可以做到这一点,但是,您需要这样做。
您可以创建一个模拟输入的容器,并且可以在该容器内将带有边框白色的真实输入放入,我举了一个例子,看一下:
CSS代码:
.input-select-tag{
background-color: #FFFFFF;
boder: 1px solid #F1F1F1;
height: 36px;
width: 450px;
}
.selected-tags{
padding: 2px;
}
.button{
float: left;
padding: 5px;
margin-left: 2px;
}
.input{
float: left;
border: #FFFFFF;
margin-left: 2px;
padding: 5px;
}
.clear{
clear: both;
}
HTML:
<form class='form-horizontal well'>
<div class='control-group'>
<div class='input-select-tag'>
<div class='selected-tags'>
<span class='alert button alert-info'>tag1 <a href="javascript:;" title='remove' >x</a></span>
<span class='alert button alert-info'>tag2 <a href="javascript:;" title='remove' >x</a></span>
</div>
<input type='text' name='selectTags' class='input' size="40"/>
<div class='clear'></div>
</div>
</div>
</form>
希望能帮助到你。
var i = 7; $("input").focus(function(e) { // set cursor position if (!this.value.length) { this.value = $.map(Array(i * $(".alert").length), function() { return " " }).join(" ") } }).change(function(e) { // append new "tag" $(".alert").first().clone().text(function(i, text) { return text.replace(/tag1/, e.target.value) }).appendTo($(".alert").parent()); $(this).val("").focus() }).closest("form").submit(function(e) { e.preventDefault() })
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> <form class='form-horizontal well'> <div class='control-group'> <div class='selected-tags'> <span class='alert alert-info'>tag1 <a href="javascript:;" title='remove' >x</a></span> <span class='alert alert-info'>tag2 <a href="javascript:;" title='remove' >x</a></span> </div> <label>Tags</label> <br> <input type='text' name='selectTags' /> </div> </form> <style> .control-group { position: relative; } .alert { position: relative; top: 47px; font-size: 12px; padding: 2px; margin: 2px; } input { white-space: pre; width: 100%; } </style>
jsfiddle http://jsfiddle.net/db8upk61/2/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.