【发布时间】:2016-04-25 20:11:07
【问题描述】:
想要在 Bootstrap 3 中创建一个搜索栏,其中包含仅在有文本时才显示的清晰图标和用户单击以开始搜索的搜索图标。
我很接近:
但是,如您所见,x 字形与搜索栏占据相同的空间。如果我尝试将 x 放在更靠左的位置,它就会消失在搜索栏后面。
我的代码如下:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:this.resources>
<xp:styleSheet href="/cc_CommonSearchBar.css" />
</xp:this.resources>
<div class="input-group" style="width:300px">
<!-- <div class="btn-group">-->
<input id="ccSearchInput" type="text" class="form-control"
placeholder="Search for..." />
<span id="ccSearchClear" class="glyphicon glyphicon-remove-circle" />
<span class="input-group-addon" id="basic-addon2">
<i class="glyphicon glyphicon-search" />
</span>
</div>
<xp:scriptBlock id="scriptBlock1">
<xp:this.value><![CDATA[$(document).ready(function(){
$("#ccSearchInput").keyup(function(){
$("#ccSearchClear").toggle(Boolean(this.value));
});
$("#ccSearchClear").toggle(Boolean($("#ccSearchInput").val()));
$("#ccSearchClear").click(function(){
$("#ccSearchInput").val("").focus();
$("#ccSearchClear").hide();
});
});]]></xp:this.value>
</xp:scriptBlock>
</xp:view>
还有我的 CSS:
#ccSearchInput {
width: 200px;
}
#ccSearchClear {
position:absolute !important;
right:5px !important;
top:0 !important;
bottom:0 !important;
height:14px !important;
margin:auto !important;
font-size:14px !important;
cursor:pointer !important;
color:#ccc !important;;
}
【问题讨论】:
-
你能把生成的 HTML 和必要的 CSS 放到一个 fiddle 中以便于排除故障吗? (jsfiddle.net) - 请记住只添加必要的内容(阅读创建minimal reproducible example)
-
当然。这是我的第一个小提琴,所以让我知道是否不正确。 jsfiddle.net/bryanschmiedeler/jso8663q
-
我添加了一个可能的答案
标签: twitter-bootstrap-3 xpages