我有带有span类的按钮,我遇到一个问题,要显示特定按钮上方的每个span类。喜欢这张图片。我怎么能这样做?
.label{
position: absolute;
top: 2.5rem;
}

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://use.fontawesome.com/f574067864.js"></script>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<hr>
<div class="container">
<button class="btn btn-default" type="submit">Button</button>
<span class="label label-success">4</span>
<button class="btn btn-default" type="submit">Button</button>
<span class="label label-success">5</span>
<button class="btn btn-default" type="submit">Button</button>
<span class="label label-success">6</span>
</div>
</body>
</html>
&#13;
谢谢...
答案 0 :(得分:2)
试试这个
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://use.fontawesome.com/f574067864.js"></script>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<style>
.sub-btn{
position: relative;
}
.sub-btn span{
position: absolute !important;
right: 0;
top: -15px !important;
}
</style>
<body>
<hr>
<div class="container">
<button class="btn btn-default sub-btn" type="submit">Button <span class="label label-success">4</span></button>
<button class="btn btn-default sub-btn" type="submit">Button <span class="label label-success">5</span></button>
<button class="btn btn-default sub-btn" type="submit">Button <span class="label label-success">6</span></button>
</div>
</body>
</html>
答案 1 :(得分:1)
在按钮内添加span
<div class="container">
<button class="btn btn-default" type="submit">Button<span class="label label-success">4</span></button>
<button class="btn btn-default" type="submit">Button<span class="label label-success">5</span></button>
<button class="btn btn-default" type="submit">Button<span class="label label-success">6</span></button>
</div>
并添加此css
.btn {
position:relative;
}
.btn>.label {
position: absolute;
top: -15px;
right: 0;
}
答案 2 :(得分:1)
你想要的吗?的被修改强>
.label{
position: absolute;
top: 2.5rem;
}
.button-label{
margin-left:-25px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://use.fontawesome.com/f574067864.js"></script>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<hr>
<div class="container">
<button class="btn btn-default" type="submit">Button</button>
<span class="label button-label label-success">4</span>
<button class="btn btn-default" type="submit">Button</button>
<span class="label button-label label-success">5</span>
<button class="btn btn-default" type="submit">Button</button>
<span class="label button-label label-success">6</span>
</div>
</body>
</html>