代码之家  ›  专栏  ›  技术社区  ›  kouwschottel

旋转木马无法填充div

  •  0
  • kouwschottel  · 技术社区  · 7 年前

    我想用旋转木马填充一个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>
    2 回复  |  直到 7 年前
        1
  •  0
  •   M0ns1f    7 年前

    将样式添加到#banner类

    #wrapper
    {
    	background: rgba(162,162,162,.1);
    }
    
    #banner-wrapper
    {
    	overflow: hidden;
    	padding: 3em 0em;
    	background: #E24E2A;
    }
    
    #banner
    {
    	overflow: hidden;
      /* set width to 100% */
    	width: 98%;
      /* delete the padding */
      /* added margin */
      margin :0 1%;
    	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>
        2
  •  0
  •   Ehsan    7 年前

    1) 您定义了 padding:0 100px; #banner 向右。

    width:1000px

    #banner {
        width: 100%;<----------------------Changed
        padding: 0;<-----------------------Changed
        max-width:1000px;<-----------------Changed
        //more code...
    }
    

    #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>