旋转木马不会填充div

时间:2017-07-26 10:39:05

标签: css width carousel

我试图用旋转木马填充div。我得到了它的工作,但旋转木马不会填充整个div的宽度,我似乎无法让它工作。

我做了一个jsfiddle让你看到: https://jsfiddle.net/svdvem97/

我想在侧面填充一点点填充物,但无论我怎么做,旋转木马的宽度都不会改变。

提前致谢。



#wrapper
{
	background: rgba(162,162,162,.1);
}

#banner-wrapper
{
	overflow: hidden;
	padding: 3em 0em;
	background: #E24E2A;
}

#banner
{
	overflow: hidden;
	width: 1000px;
	padding: 0px 100px;
	text-align: center;
	color: rgba(255,255,255,.7);
	border-bottom: 2px solid #E3E3E3;
}

#banner a
{
	color: rgba(255,255,255,.9);
}

#banner .box-left
{
	float: left;
}

#banner .box-right
{
	float: right;
}

#banner h2
{
	margin: 0em;
	padding: 0em;
	font-weight: 400;
	font-size: 1.6em;
	color: #F8F8FF;
}

#banner span
{
	display: block;
	padding-top: 0.20em;
	text-transform: uppercase;
	font-size: 1.2em;
	color: #A2A2A2;
}

.carousel {
    position:relative;
    box-shadow: 0px 1px 6px rgba(0, 0, 0, 0.64); 
    margin-top: 10px;
	margin-bottom: 10px;
}

.carousel-inner {
    position: relative;
    overflow: hidden;
	
}

.carousel-open:checked + .carousel-item {
    position: static;
    opacity: 100;
}

.carousel-item {
    position: absolute;
    opacity: 0;
    -webkit-transition: opacity 0.6s ease-out;
    transition: opacity 0.6s ease-out;
}

.carousel-item img {
    display: block;
    height: auto;
    max-width: 100%;
}

.carousel-control {
    background: rgba(0, 0, 0, 0.28);
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    display: none;
    font-size: 40px;
    height: 40px;
    line-height: 35px;
    position: absolute;
    top: 50%;
    -webkit-transform: translate(0, -50%);
    cursor: pointer;
    -ms-transform: translate(0, -50%);
    transform: translate(0, -50%);
    text-align: center;
    width: 40px;
    z-index: 10;
}

.carousel-control.prev {
    left: 2%;
}

.carousel-control.next {
    right: 2%;
}

.carousel-control:hover {
    background: rgba(0, 0, 0, 0.8);
    color: #aaaaaa;
}

#carousel-1:checked ~ .control-1,
#carousel-2:checked ~ .control-2,
#carousel-3:checked ~ .control-3 {
    display: block;
}

.carousel-indicators {
    list-style: none;
    margin: 0;
    padding: 0;
    position: absolute;
    bottom: 2%;
    left: 0;
    right: 0;
    text-align: center;
    z-index: 10;
}

.carousel-indicators li {
    display: inline-block;
    margin: 0 5px;
}

.carousel-bullet {
    color: #fff;
    cursor: pointer;
    display: block;
    font-size: 35px;
}

.carousel-bullet:hover {
    color: #aaaaaa;
}

#carousel-1:checked ~ .control-1 ~ .carousel-indicators li:nth-child(1) .carousel-bullet,
#carousel-2:checked ~ .control-2 ~ .carousel-indicators li:nth-child(2) .carousel-bullet,
#carousel-3:checked ~ .control-3 ~ .carousel-indicators li:nth-child(3) .carousel-bullet {
    color: #428bca;
}

#title {
    width: 100%;
    position: absolute;
    padding: 0px;
    margin: 0px auto;
    text-align: center;
    font-size: 27px;
    color: rgba(255, 255, 255, 1);
    font-family: 'Open Sans', sans-serif;
    z-index: 9999;
    text-shadow: 0px 1px 2px rgba(0, 0, 0, 0.33), -1px 0px 2px rgba(255, 255, 255, 0);
}

<div id="wrapper" class= "container">
	<div id="banner" class="container">
		<div class="carousel">
			<div class="carousel-inner"> 
				<input class="carousel-open" type="radio" id="carousel-1" name="carousel" aria-hidden="true" hidden="" checked="checked">
					<div class="carousel-item">
						<img src="https://fakeimg.pl/2000x300/0079D8/fff/?text=Test">
					</div>
				<input class="carousel-open" type="radio" id="carousel-2" name="carousel" aria-hidden="true" hidden="">
					<div class="carousel-item">
						<img src="https://fakeimg.pl/2000x300/DC5732/fff/?text=Test">
					</div>
				<input class="carousel-open" type="radio" id="carousel-3" name="carousel" aria-hidden="true" hidden="">
					<div class="carousel-item">
						<img src="http://fakeimg.pl/2000x300/289672/fff/?text=Test">
					</div>
				<label for="carousel-3" class="carousel-control prev control-1">‹</label>
				<label for="carousel-2" class="carousel-control next control-1">›</label>
				<label for="carousel-1" class="carousel-control prev control-2">‹</label>
				<label for="carousel-3" class="carousel-control next control-2">›</label>
				<label for="carousel-2" class="carousel-control prev control-3">‹</label>
				<label for="carousel-1" class="carousel-control next control-3">›</label>
				<ol class="carousel-indicators">
					<li>
						<label for="carousel-1" class="carousel-bullet">•</label>
					</li>
					<li>
						<label for="carousel-2" class="carousel-bullet">•</label>
					</li>
					<li>
						<label for="carousel-3" class="carousel-bullet">•</label>
					</li>
				</ol>
			</div>
		</div>
	</div>
</div>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:0)

为#banner类添加了样式

<div id="wrapper" class= "container">
	<div id="banner" class="container">
		<div class="carousel">
			<div class="carousel-inner"> 
				<input class="carousel-open" type="radio" id="carousel-1" name="carousel" aria-hidden="true" hidden="" checked="checked">
					<div class="carousel-item">
						<img src="https://fakeimg.pl/2000x300/0079D8/fff/?text=Test">
					</div>
				<input class="carousel-open" type="radio" id="carousel-2" name="carousel" aria-hidden="true" hidden="">
					<div class="carousel-item">
						<img src="https://fakeimg.pl/2000x300/DC5732/fff/?text=Test">
					</div>
				<input class="carousel-open" type="radio" id="carousel-3" name="carousel" aria-hidden="true" hidden="">
					<div class="carousel-item">
						<img src="http://fakeimg.pl/2000x300/289672/fff/?text=Test">
					</div>
				<label for="carousel-3" class="carousel-control prev control-1">‹</label>
				<label for="carousel-2" class="carousel-control next control-1">›</label>
				<label for="carousel-1" class="carousel-control prev control-2">‹</label>
				<label for="carousel-3" class="carousel-control next control-2">›</label>
				<label for="carousel-2" class="carousel-control prev control-3">‹</label>
				<label for="carousel-1" class="carousel-control next control-3">›</label>
				<ol class="carousel-indicators">
					<li>
						<label for="carousel-1" class="carousel-bullet">•</label>
					</li>
					<li>
						<label for="carousel-2" class="carousel-bullet">•</label>
					</li>
					<li>
						<label for="carousel-3" class="carousel-bullet">•</label>
					</li>
				</ol>
			</div>
		</div>
	</div>
</div>
PageA -> PageB -> PageC

答案 1 :(得分:0)

1)您将此padding:0 100px; #banner定义为width:1000px

2)您使用#banner { width: 100%;<----------------------Changed padding: 0;<-----------------------Changed max-width:1000px;<-----------------Changed //more code... } ,如果宽度浏览器小于1000px,则创建滚动,因此请使用width:100%和max-width:1000px;

#wrapper {
  background: rgba(162,162,162,.1);
}

#banner-wrapper {
  overflow: hidden;
  padding: 3em 0em;
  background: #E24E2A;
}

#banner {
  overflow: hidden;
  width: 100%;
  max-width:1000px;
  padding: 0px;
  text-align: center;
  color: rgba(255,255,255,.7);
  border-bottom: 2px solid #E3E3E3;
}

#banner a {
  color: rgba(255,255,255,.9);
}

#banner .box-left {
  float: left;
}

#banner .box-right {
  float: right;
}

#banner h2 {
  margin: 0em;
  padding: 0em;
  font-weight: 400;
  font-size: 1.6em;
  color: #F8F8FF;
}

#banner span {
  display: block;
  padding-top: 0.20em;
  text-transform: uppercase;
  font-size: 1.2em;
  color: #A2A2A2;
}

.carousel {
  position:relative;
  box-shadow: 0px 1px 6px rgba(0, 0, 0, 0.64); 
  margin-top: 10px;
  margin-bottom: 10px;
}

.carousel-inner {
  position: relative;
  overflow: hidden;
  
}

.carousel-open:checked + .carousel-item {
  position: static;
  opacity: 100;
}

.carousel-item {
  position: absolute;
  opacity: 0;
  -webkit-transition: opacity 0.6s ease-out;
  transition: opacity 0.6s ease-out;
}

.carousel-item img {
  display: block;
  height: auto;
  max-width: 100%;
}

.carousel-control {
  background: rgba(0, 0, 0, 0.28);
  border-radius: 50%;
  color: #fff;
  cursor: pointer;
  display: none;
  font-size: 40px;
  height: 40px;
  line-height: 35px;
  position: absolute;
  top: 50%;
  -webkit-transform: translate(0, -50%);
  cursor: pointer;
  -ms-transform: translate(0, -50%);
  transform: translate(0, -50%);
  text-align: center;
  width: 40px;
  z-index: 10;
}

.carousel-control.prev {
  left: 2%;
}

.carousel-control.next {
  right: 2%;
}

.carousel-control:hover {
  background: rgba(0, 0, 0, 0.8);
  color: #aaaaaa;
}

#carousel-1:checked ~ .control-1,
#carousel-2:checked ~ .control-2,
#carousel-3:checked ~ .control-3 {
  display: block;
}

.carousel-indicators {
  list-style: none;
  margin: 0;
  padding: 0;
  position: absolute;
  bottom: 2%;
  left: 0;
  right: 0;
  text-align: center;
  z-index: 10;
}

.carousel-indicators li {
  display: inline-block;
  margin: 0 5px;
}

.carousel-bullet {
  color: #fff;
  cursor: pointer;
  display: block;
  font-size: 35px;
}

.carousel-bullet:hover {
  color: #aaaaaa;
}

#carousel-1:checked ~ .control-1 ~ .carousel-indicators li:nth-child(1) .carousel-bullet,
#carousel-2:checked ~ .control-2 ~ .carousel-indicators li:nth-child(2) .carousel-bullet,
#carousel-3:checked ~ .control-3 ~ .carousel-indicators li:nth-child(3) .carousel-bullet {
  color: #428bca;
}

#title {
  width: 100%;
  position: absolute;
  padding: 0px;
  margin: 0px auto;
  text-align: center;
  font-size: 27px;
  color: rgba(255, 255, 255, 1);
  font-family: 'Open Sans', sans-serif;
  z-index: 9999;
  text-shadow: 0px 1px 2px rgba(0, 0, 0, 0.33), -1px 0px 2px rgba(255, 255, 255, 0);
}

<div id="wrapper" class= "container">
  <div id="banner" class="container">
    <div class="carousel">
      <div class="carousel-inner"> 
        <input class="carousel-open" type="radio" id="carousel-1" name="carousel" aria-hidden="true" hidden="" checked="checked">
          <div class="carousel-item">
            <img src="https://fakeimg.pl/2000x300/0079D8/fff/?text=Test">
          </div>
        <input class="carousel-open" type="radio" id="carousel-2" name="carousel" aria-hidden="true" hidden="">
          <div class="carousel-item">
            <img src="https://fakeimg.pl/2000x300/DC5732/fff/?text=Test">
          </div>
        <input class="carousel-open" type="radio" id="carousel-3" name="carousel" aria-hidden="true" hidden="">
          <div class="carousel-item">
            <img src="http://fakeimg.pl/2000x300/289672/fff/?text=Test">
          </div>
        <label for="carousel-3" class="carousel-control prev control-1">‹</label>
        <label for="carousel-2" class="carousel-control next control-1">›</label>
        <label for="carousel-1" class="carousel-control prev control-2">‹</label>
        <label for="carousel-3" class="carousel-control next control-2">›</label>
        <label for="carousel-2" class="carousel-control prev control-3">‹</label>
        <label for="carousel-1" class="carousel-control next control-3">›</label>
        <ol class="carousel-indicators">
          <li>
            <label for="carousel-1" class="carousel-bullet">•</label>
          </li>
          <li>
            <label for="carousel-2" class="carousel-bullet">•</label>
          </li>
          <li>
            <label for="carousel-3" class="carousel-bullet">•</label>
          </li>
        </ol>
      </div>
    </div>
  </div>
</div>  
sizeof(c = a+b);