我正在尝试获取下面显示的用户界面,并且在数字下方需要一个与图像完全相同的边框:
但我使用下面显示的代码获得了不同的结果。有人可以帮我设计一下吗?
<!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/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style>
.input-number{
margin: 0 15px;
width: 50px !important;
}
</style>
</head>
<body>
<div style="width:150px;padding:50px;">
<div class="input-group">
<span class="input-group-btn">
<button type="button" class="btn btn-default btn-number" disabled="disabled" data-type="minus" data-field="quant[1]">
<span class="glyphicon glyphicon-minus"></span>
</button>
</span>
<input type="text" name="quant[1]" class="form-control input-number" value="1" min="1" max="10">
<span class="input-group-btn">
<button type="button" class="btn btn-default btn-number" data-type="plus" data-field="quant[1]">
<span class="glyphicon glyphicon-plus"></span>
</button>
</span>
</div>
</div>
</body>
</html>
&#13;
答案 0 :(得分:2)
试试这个:
.input-number{
width: 50px !important;
text-align: center!important;
font-weight: bold!important;
font-size: 25px!important;
height: 40px!important;
border:none!important;
border-bottom: solid 2px #ccc!important;
box-shadow: none!important;
position:relative;
}
.input-container{
position: relative;
height: 40px;
display: block;
margin: 0 15px;
}
.input-container:before{
content: "";
position: absolute;
bottom: 0;
left: 0;
width: 2px;
height: 10px;
background-color: #ccc!important;
z-index:10;
}
.input-container:after{
content: "";
position: absolute;
bottom: 0;
right: 0;
width: 2px;
height: 10px;
background-color: #ccc!important;
z-index:10;
}
.btn-number{
border-radius: 50%!important;
background-color: #ccc!important;
color: #fff!important;
outline: none!important;
font-size: 25px!important;
padding: 3px!important;
width: 40px;
height: 40px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div style="width:150px;padding:50px;">
<div class="input-group">
<span class="input-group-btn">
<button type="button" class="btn btn-default btn-number" disabled="disabled" data-type="minus" data-field="quant[1]">
<span class="glyphicon glyphicon-minus"></span>
</button>
</span>
<span class="input-container">
<input type="text" name="quant[1]" class="form-control input-number" value="1" min="1" max="10">
</span>
<span class="input-group-btn">
<button type="button" class="btn btn-default btn-number" data-type="plus" data-field="quant[1]">
<span class="glyphicon glyphicon-plus"></span>
</button>
</span>
</div>
答案 1 :(得分:2)
您只需将输入字段类型设置为“数字”,即可自动为您添加增量和减量按钮。 这是代码示例:
<input type="number" class="form-control" id="input1" placeholder="enter amount">
答案 2 :(得分:0)
您必须为btn
和input-number
类提供样式:
.btn{
height: 50px;
width: 50px;
border-radius: 50%,
background-color: #ccc;
}
.btn .glyphicon {
color: #fff;
}
.input-number {
margin: 0 15px;
width: 50px !important;
border: none;
}
.input-number: after {
content: '';
position: absolute;
bottom: 0;
height: 3px;
width: 50px;
background-color: #fff;
left: 50% - 50px;
}
答案 3 :(得分:0)
input.btneg {
border-radius: 5cm;
width: 40px;
position: relative;
margin-right: -30px;
height: 0.8cm;
}
input.btpos {
border-radius: 5cm;
width: 40px;
position: relative;
margin-left: -30px;
height: 0.8cm;
}
<input type="button" class="btneg " value="-">
<input type="text" name="noq1" id="noq1" min="1" max="15" value="12">
<input type="button" class="btpos " value="+">
答案 4 :(得分:0)
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<!------ Include the above in your HEAD tag ---------->
<div class="container">
<div class="row">
<h2>Simple Quantity increment buttons with Javascript </h2>
<div class="col-lg-2">
<div class="input-group">
<span class="input-group-btn">
<button type="button" class="quantity-left-minus btn btn-danger btn-number" data-type="minus" data-field="">
<span class="glyphicon glyphicon-minus"></span>
</button>
</span>
<input type="text" id="quantity" name="quantity" class="form-control input-number" value="10" min="1" max="100">
<span class="input-group-btn">
<button type="button" class="quantity-right-plus btn btn-success btn-number" data-type="plus" data-field="">
<span class="glyphicon glyphicon-plus"></span>
</button>
</span>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function(){
var quantitiy=0;
$('.quantity-right-plus').click(function(e){
// Stop acting like a button
e.preventDefault();
// Get the field name
var quantity = parseInt($('#quantity').val());
// If is not undefined
$('#quantity').val(quantity + 1);
// Increment
});
$('.quantity-left-minus').click(function(e){
// Stop acting like a button
e.preventDefault();
// Get the field name
var quantity = parseInt($('#quantity').val());
// If is not undefined
// Increment
if(quantity>0){
$('#quantity').val(quantity - 1);
}
});
});
</script>