我正在使用bootstrap和hover.css来创建list-group,其中list-group-items是按钮。问题是我无法将这些项的宽度设置为仅填充其父项的空间。
编辑:问题实际上并不是按钮超出了容器。它就是列外的容器
在我的html中,我目前有:
<div class="col-md-4">
<div class="list-box">
<div class="container">
<h1>Some title</h1>
<div class="list-group">
<button type="button" class="list-group-item hvr-sweep-to-left" ng-repeat="project in currentUser.projects">
{{Something}}
</button>
</div>
</div>
</div>
</div>
我的css目前有:
.list-box
{
background-color: #FFFFFF;
border-color: #000000;
display: block;
}
.list-group-item
{
display: block;
width: 100%;
}
这是我正在使用的hover.css
/* Button Effect - Sweep To Left */
.hvr-sweep-to-left {
display: block;
vertical-align: middle;
-webkit-transform: translateZ(0);
transform: translateZ(0);
box-shadow: 0 0 1px rgba(0, 0, 0, 0);
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
-moz-osx-font-smoothing: grayscale;
position: relative;
-webkit-transition-property: color;
transition-property: color;
-webkit-transition-duration: 0.3s;
transition-duration: 0.3s;
}
.hvr-sweep-to-left:before {
content: "";
position: absolute;
z-index: -1;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: #4393b9;
-webkit-transform: scaleX(0);
transform: scaleX(0);
-webkit-transform-origin: 100% 50%;
transform-origin: 100% 50%;
-webkit-transition-property: transform;
transition-property: transform;
-webkit-transition-duration: 0.3s;
transition-duration: 0.3s;
-webkit-transition-timing-function: ease-out;
transition-timing-function: ease-out;
}
.hvr-sweep-to-left:hover, .hvr-sweep-to-left:focus, .hvr-sweep-to-left:active {
color: white;
}
.hvr-sweep-to-left:hover:before, .hvr-sweep-to-left:focus:before, .hvr-sweep-to-left:active:before {
-webkit-transform: scaleX(1);
transform: scaleX(1);
}
/* Button Effect - Sweep To Right */
.hvr-sweep-to-right {
display: block;
vertical-align: middle;
-webkit-transform: translateZ(0);
transform: translateZ(0);
box-shadow: 0 0 1px rgba(0, 0, 0, 0);
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
-moz-osx-font-smoothing: grayscale;
position: relative;
-webkit-transition-property: color;
transition-property: color;
-webkit-transition-duration: 0.3s;
transition-duration: 0.3s;
}
.hvr-sweep-to-right:before {
content: "";
position: absolute;
z-index: -1;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: #4393b9;
-webkit-transform: scaleX(0);
transform: scaleX(0);
-webkit-transform-origin: 0 50%;
transform-origin: 0 50%;
-webkit-transition-property: transform;
transition-property: transform;
-webkit-transition-duration: 0.3s;
transition-duration: 0.3s;
-webkit-transition-timing-function: ease-out;
transition-timing-function: ease-out;
}
.hvr-sweep-to-right:hover, .hvr-sweep-to-right:focus, .hvr-sweep-to-right:active {
color: white;
}
.hvr-sweep-to-right:hover:before, .hvr-sweep-to-right:focus:before, .hvr-sweep-to-right:active:before {
-webkit-transform: scaleX(1);
transform: scaleX(1);
}
/* Back Pulse */
@-webkit-keyframes hvr-back-pulse {
50% {
background-color: rgba(32, 152, 209, 0.75);
}
}
@keyframes hvr-back-pulse {
50% {
background-color: rgba(32, 152, 209, 0.75);
}
}
.hvr-back-pulse {
display: inline-block;
vertical-align: middle;
-webkit-transform: translateZ(0);
transform: translateZ(0);
box-shadow: 0 0 1px rgba(0, 0, 0, 0);
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
-moz-osx-font-smoothing: grayscale;
overflow: hidden;
-webkit-transition-duration: 0.5s;
transition-duration: 0.5s;
-webkit-transition-property: color, background-color;
transition-property: color, background-color;
}
.hvr-back-pulse:hover, .hvr-back-pulse:focus, .hvr-back-pulse:active {
-webkit-animation-name: hvr-back-pulse;
animation-name: hvr-back-pulse;
-webkit-animation-duration: 1s;
animation-duration: 1s;
-webkit-animation-delay: 0.5s;
animation-delay: 0.5s;
-webkit-animation-timing-function: linear;
animation-timing-function: linear;
-webkit-animation-iteration-count: infinite;
animation-iteration-count: infinite;
background-color: #2098d1;
background-color: #2098d1;
color: white;
}
答案 0 :(得分:1)
我不确定你在寻找什么。但是,如果您希望列表项填充其父项,则可以使用此解决方案:
body{width:100%;}
.container
{ background-color: red;
border-color: #000000;
display: block;
padding: 0;
}
h1{font-size:large;}
.list-group-item
{
display: block;
width: 100%;
}
答案 1 :(得分:0)
我将bg颜色更改为红色只是为了检查尺寸/配件。 Jsbin链接here你在追求什么或没有?
body {
width: 100%;
}
.container {
background-color: red;
border-color: #000000;
display: block;
}
h1 {
font-size: large;
}
.list-group-item {
display: block;
width: 100%;
}
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<div class="col-md-4">
<div class="container">
<h1>Some title</h1>
<div class="list-group">
<button type="button" class="list-group-item hvr-sweep-to-left" ng-repeat="project in currentUser.projects">
{{Something}}
</button>
<li class="list-group-item">Coffee</li>
<li class="list-group-item">Tea</li>
<li class="list-group-item">Milk</li>
</div>
</div>
</div>
</body>
</html>