我正在尝试将清除按钮附加到输入搜索中,但是我得到的结果确实很奇怪,尤其是:
我怀疑此问题与我正在使用“ Black Dashboard PRO”的主题有关
<form>
<div class="input-group">
<input id="customer-search" type="text" class="key form-control" placeholder="Search">
<span class="input-group-addon">
<div>
<button class="clear btn btn-default" type="button" title="Clear">
<span class="tim-icons icon-simple-remove"></span>
</button>
</div>
</span>
</div>
</form>
这是主题使用的按钮的css:
`.btn:not(:disabled):not(.disabled) {
cursor: pointer;
}
button, html [type="button"], [type="reset"], [type="submit"] {
-webkit-appearance: button;
}
.btn {
cursor: pointer;
}
.btn, .navbar .navbar-nav > a.btn {
border-width: 2px;
border: none;
position: relative;
overflow: hidden;
margin: 4px 1px;
border-radius: 0.4285rem;
cursor: pointer;
background: #344675;
background-image: linear-gradient(to bottom left, #344675, #263148, #344675);
background-size: 210% 210%;
background-position: top right;
background-color: #344675;
transition: all 0.15s ease;
box-shadow: none;
color: #ffffff;
}
.btn-default {
color: #ffffff;
background-color: #344675;
border-color: #344675;
box-shadow: 0 4px 6px rgba(50, 50, 93, 0.11), 0 1px 3px rgba(0, 0, 0, 0.08);
}
.btn {
display: inline-block;
font-weight: 600;
text-align: center;
white-space: nowrap;
vertical-align: middle;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
border: 1px solid transparent;
padding: 11px 40px;
font-size: 0.875rem;
line-height: 1.35em;
border-radius: 0.25rem;
transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}`
答案 0 :(得分:1)
删除'.btn,.navbar .navbar-nav> a.btn'的边距
{{1}}
答案 1 :(得分:0)
我想您只需要删除该按钮上的边距即可查看演示
.btn:not(:disabled):not(.disabled) {
cursor: pointer;
}
button, html [type="button"], [type="reset"], [type="submit"] {
-webkit-appearance: button;
}
.btn {
cursor: pointer;
}
.btn, .navbar .navbar-nav > a.btn {
border-width: 2px;
border: none;
position: relative;
overflow: hidden;
margin: 4px 1px;
border-radius: 0.4285rem;
cursor: pointer;
background: #344675;
background-image: linear-gradient(to bottom left, #344675, #263148, #344675);
background-size: 210% 210%;
background-position: top right;
background-color: #344675;
transition: all 0.15s ease;
box-shadow: none;
color: #ffffff;
}
.btn-default {
color: #ffffff;
background-color: #344675;
border-color: #344675;
box-shadow: 0 4px 6px rgba(50, 50, 93, 0.11), 0 1px 3px rgba(0, 0, 0, 0.08);
}
.btn {
display: inline-block;
font-weight: 600;
text-align: center;
white-space: nowrap;
vertical-align: middle;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
border: 1px solid transparent;
padding: 11px 40px;
font-size: 0.875rem;
line-height: 1.35em;
border-radius: 0.25rem;
transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}
.no-margin{
margin: 0;
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h4>your default code with issue</h4>
<form>
<div class="input-group">
<input id="customer-search" type="text" class="key form-control" placeholder="Search">
<span class="input-group-addon">
<div>
<button class="clear btn btn-default" type="button" title="Clear">
<span class="tim-icons icon-simple-remove">X</span>
</button>
</div>
</span>
</div>
<h4>after removed margin from button</h4>
<div class="input-group">
<input id="customer-search" type="text" class="key form-control" placeholder="Search">
<span class="input-group-addon">
<div>
<button class="clear btn btn-default no-margin" type="button" title="Clear">
<span class="tim-icons icon-simple-remove">X</span>
</button>
</div>
</span>
</div>
</form>
</div>
</body>
</html>
答案 2 :(得分:0)
更改HTML和
在跨度input-group-append
<div class="input-group">
<input id="customer-search" type="text" class="key form-control" placeholder="Search">
<span class="input-group-append">
<button class="clear btn btn-default" type="button" title="Clear">
<span class="tim-icons icon-simple-remove">X</span>
</button>
</span>
</div>