设置响应式HTML背景

时间:2017-09-18 07:01:37

标签: html css twitter-bootstrap twitter-bootstrap-3

美好的一天,我有一个带有两个背景图片的简单网页。所以这是我的CSS

body{
      background:
            url('<?=base_url();?>/assets/header_bg.png')no-repeat ,
            url('<?=base_url();?>/assets/footer_bg.png')no-repeat;    
          background-size: contain;

      background-position: 100px -30px, 0px 98%;
      -webkit-background-size: contain;
      -moz-background-size: contain;
      -o-background-size: contain;
    }

这是结果(我只会采用顶部和页脚部分)

热门主页:

enter image description here

关于页面的顶部:

enter image description here

然后问题,家庭底部:

enter image description here

关于底部:

enter image description here

如您所见,about页面中的bg图像未满。对此有何解决方案?

顺便说一句,我正在使用codeigniter。这是我的整页

我的主要

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Lesfemmes</title>
  <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <link rel="stylesheet" href="<?=base_url();?>assets/fontawesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="<?=base_url();?>assets/css/flexslider.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <style>

html{
  height: auto;
  width:  auto ;
}

@font-face {
    font-family: Bookcustom;
    src: url('<?=base_url();?>assets/fonts/gothamfamily/Gotham-Book.otf');
}

@font-face {
    font-family: Boldcustom;
    src: url('<?=base_url();?>assets/fonts/gothamfamily/Gotham-Bold.otf');
}

@font-face {
    font-family: Forquote;
    src: url('<?=base_url();?>assets/fonts/gothamfamily/ufonts.com_baskerville-italic.ttf');
}


.navbar{
    font-family: Bookcustom;
    font-size: 16pt;
}

      @media (min-width: 768px){
    .navbar-nav{
        float:none;
        display: table;
        table-layout: fixed;
    } 


}
.fixed-bottom {
    margin-bottom: 0;
}


.navbar.transparent.navbar-inverse .navbar-inner {

    border-width: 0px;
    -webkit-box-shadow: 0px 0px;
    box-shadow: 0px 0px;
    background-color: rgba(0,0,0,0.0);
    background-image: -webkit-gradient(linear, 50.00% 0.00%, 50.00% 100.00%, color-stop( 0% , rgba(0,0,0,0.00)),color-stop( 100% , rgba(0,0,0,0.00)));
    background-image: -webkit-linear-gradient(270deg,rgba(0,0,0,0.00) 0%,rgba(0,0,0,0.00) 100%);
    background-image: linear-gradient(180deg,rgba(0,0,0,0.00) 0%,rgba(0,0,0,0.00) 100%);
  }

.navbar.transparent ul.nav a:hover 
{ 
  background-color: transparent; !important; 
  color: #efa0c0
}

#topnavbar{
  top: 15px;
}


.navbar a {
    color: black;
    font-family: Bookcustom;
    font-size: 16pt;
}


.navbar .navbar-nav {
    display: inline-block;
    float: none;
}

.navbar .navbar-collapse {
    text-align: center;
}


h3.subjudul{
  font-family: Boldcustom;
  font-size: 16pt;
}

h3.thumbnail{
   font-family: Boldcustom;
  font-size: 16pt;
}

blockquote{
  border: none;
    border-bottom: 1px solid #ccc;
    border-top:1px solid #ccc;
  }
.navbar-bottom {
    margin-top:40px;
    padding-bottom: 10px;
    font-family: Bookcustom;
    font-size: 16pt;

}

.back-to-top {
    cursor: pointer;
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 10;
    padding: 5px 10px;
    display: inline-block;
    -moz-border-radius: 100px;
    -webkit-border-radius: 100px;
    border-radius: 100px;
    -moz-box-shadow: 0px 0px 2px #888;
    -webkit-box-shadow: 0px 0px 2px #888;
    box-shadow: 0px 0px 2px #888;
}
.back-to-top:hover {
    cursor: pointer;
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 10;
    background-color: black;
    opacity: 1;
} 
.fa-arrow-up:hover {
  color: white;
}
.fa-arrow-up {
  color: black;
}
table th.fit {
    white-space: nowrap;
    width: 1%;
}


div.c-wrapper{
    width: 100%;
    margin: auto;
}
.carousel-inner{
  width:100%;

}
.peopleCarouselImg img {
  width: auto;
  height: 225px;
  max-height: 225px;
}
.subscribe{
  bottom: 45px;
}
.carousel-control{
    top: 50%;
    bottom: 50%;
}
.carousel-inner > .item > img {

  height: 400px;
  margin: 0 auto;
  padding-left: 115px
}

.quotecontent{
font-family: Forquote; 
font-style: italic;
font-size: 24pt;
}

.quoteautor{
    font-family: Bookcustom;
    font-size: 14pt;
    text-align: right;
}

.about{
  padding-top: 80px;
   font-family: Bookcustom;
}
.abouttext{
  padding-top: 60px;
   font-family: Bookcustom;
}
.youtubeabout{
  margin-top: -350px;
  position: relative;
  float: right;
  padding-right: 50px;
}

.box{
  padding-top: 100px;
  background:#F9D7E8;
  padding:15px;
  width:300px;
  height:200px;
   position:relative;
     margin-left: 110px;
     margin-top: 120px;
}
.box-inner{
  border:1px solid #000;
  height:100%; 
}
.box p {
  font-family: arial;
  font-size: 12px;
  font-weight: bold;
  line-height: 140%;
  margin: auto;
  position: absolute;
  right: 3px;
  text-align: right;
  text-transform: uppercase;
  top: 50%;
  -webkit-transform: translateY(-50%);
  transform: translateY(-50%);
  width: 113px;
  background: #f9d7e8;

}
.box p::before {
  background: #000;
  bottom: -2px;
  content: "";
  height: 1px;
  left: auto;
  position: absolute;
  right: 18px;  
  width: 35px;
  z-index: -1;
}
#bottomnavbar{

   margin-bottom: -20px;
}
body{

    background:
        url('<?=base_url();?>/assets/header_bg.png')no-repeat ,
        url('<?=base_url();?>/assets/footer_bg.png')no-repeat;    
      background-size: contain;

  background-position: 100px -30px, 0px 98%;
  -webkit-background-size: contain;
  -moz-background-size: contain;
  -o-background-size: contain;
}
</style>
 </head>
 <body>
 <div class="container-fullwidth">
 <a id="back-to-top" href="#" class="back-to-top" role="button" data-placement="left"><i class="fa fa-arrow-up fa-2x"></i></a>
 <div class="asheader">
  <div id="Intro" class="col-md-offset-5 col-md-5">
    <img src="<?=base_url();?>assets/logo_hitam.png" width="200px" height="50px">
  </div>


    <nav id="topnavbar" class="navbar transparent col-md-offset-2 col-md-9">
        <div class="navbar-header">
            <button type="button" data-target="#navbarCollapse" data-toggle="collapse" class="navbar-toggle">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>

        </div>
        <!-- Collection of nav links, forms, and other content for toggling -->
        <div id="navbarCollapse" class="collapse navbar-collapse">
            <ul class="nav navbar-nav">
                <li><a href="<?=base_url();?>">Home</a></li>
                <li><a href="<?=base_url();?>about">About Us</a></li>
                <li><a href="<?=base_url();?>product">Product</a></li>
                <li><a href="<?=base_url();?>promo">Events</a></li>
                <li><a href="<?=base_url();?>competition">Competition</a></li>
                <li><a href="<?=base_url();?>ladiesroom">Ladies Room</a></li>
                <li><a href="<?=base_url();?>help">Need Help?</a></li>
            </ul>
        </div>
        <!--- -->
    </nav>
    <div class="row content container-fluid">
      <?php $this->load->view($include);?>
      </div>
      <nav id="bottomnavbar" class="navbar navbar-static-bottom navbar-inverse col-md-12 fixed-bottom">
        <div class="navbar-header">
            <button type="button" data-target="#navbarCollapse" data-toggle="collapse" class="navbar-toggle">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>

        </div>
        <!-- Collection of nav links, forms, and other content for toggling -->
        <div id="navbarCollapse" class="collapse navbar-collapse">
            <ul class="nav navbar-nav">
                <li class="active"><a href="#">Home</a></li>
                <li><a href="#">About Us</a></li>
                <li><a href="#">Product</a></li>
                <li><a href="#">Promo</a></li>
                <li><a href="#">Competition</a></li>
                <li><a href="#">Ladies Room</a></li>
                <li><a href="#">Need Help?</a></li>
            </ul>
        </div>
        <!--- -->
    </nav>
    </div>
</div>
 <script  src="assets/js/jquery.flexslider.js"></script>
 <script>

 $(document).ready(function(){
   $(window).resize(function() {
    if ($(window).width() < 960) {
      $('.navbar').removeClass('transparent');
      $('.navbar').toggleClass('navbar-default');
    }
    else {
      $('.navbar').toggleClass('transparent');
      $('.navbar').removeClass('navbar-default');
    }
    })
})
 $(document).ready(function() {
              $('.slide_thumb').flexslider({
                animation: "slide",
                controlNav: false,
                animationLoop: false,
                slideshow: false,
                itemWidth: 210,
                itemMargin: 5,
                asNavFor: '.slide_thumb',
                itemWidth: 210,
                itemMargin: 5,
                minItems: 4,
                maxItems: 4
            });
            });
 $(document).ready(function(){
     $(window).scroll(function () {
            if ($(this).scrollTop() > 50) {
                $('#back-to-top').fadeIn();
            } else {
                $('#back-to-top').fadeOut();
            }
        });
        // scroll body to 0px on click
        $('#back-to-top').click(function () {
            $('#back-to-top').tooltip('hide');
            $('body,html').animate({
                scrollTop: 0
            }, 800);
            return false;
        });

        $('#back-to-top').tooltip('show');

});
 $(function(){
    $('.carousel').carousel({
      interval: 2000
    });
});
 </script>
</body>
</html>

我的欢迎页面(主页),

<div style="margin-top: 100px" class="c-wrapper text-center col-md-offset-5 col-md-6">
  <div id="myCarousel" class="carousel slide">
    <ol class="carousel-indicators">
        <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
        <li data-target="#myCarousel" data-slide-to="1"></li>
        <li data-target="#myCarousel" data-slide-to="2"></li>
    </ol>
  <!-- Carousel items -->
  <div class="carousel-inner">
  <div class="active item">
    <img class="peopleCarouselImg" src="https://dummyimage.com/600x300/">
  </div>
  <div class="item">
   <img class="peopleCarouselImg" src="assets/banner-free-gift.jpg">
  </div>
  <div class="item"> 
       <img class="peopleCarouselImg" src="https://dummyimage.com/600x300/000/000">
  </div>
  </div>
  <!-- Carousel nav -->
  <a class="carousel-control left" href="#myCarousel" data-slide="prev">&lsaquo;</a>
  <a class="carousel-control right" href="#myCarousel" data-slide="next">&rsaquo;</a>
  </div>
</div>


    <div class="lookbook col-md-offset-2 col-md-9 text-center">
      <h3 class="subjudul">Lookbook</h3>
      <div id="" class="flexslider slide_thumb">
          <ul class="slides">
            <li>
              <img src="<?=base_url();?>assets/images/kitchen_adventurer_cheesecake_brownie.jpg" />
            </li>
            <li>
              <img src="<?=base_url();?>assets/images/kitchen_adventurer_lemon.jpg" />
            </li>
            <li>
              <img src="<?=base_url();?>assets/images/kitchen_adventurer_donut.jpg" />
            </li>
            <li>
              <img src="<?=base_url();?>assets/images/kitchen_adventurer_caramel.jpg" />
            </li>
            <li>
              <img src="<?=base_url();?>assets/images/kitchen_adventurer_cheesecake_brownie.jpg" />
            </li>
            <li>
              <img src="<?=base_url();?>assets/images/kitchen_adventurer_lemon.jpg" />
            </li>
            <li>
              <img src="<?=base_url();?>assets/images/kitchen_adventurer_donut.jpg" />
            </li>
            <li>
              <img src="<?=base_url();?>assets/images/kitchen_adventurer_caramel.jpg" />
            </li>
            <li>
              <img src="<?=base_url();?>assets/images/kitchen_adventurer_cheesecake_brownie.jpg" />
            </li>
            <li>
              <img src="<?=base_url();?>assets/images/kitchen_adventurer_lemon.jpg" />
            </li>
            <li>
              <img src="<?=base_url();?>assets/images/kitchen_adventurer_donut.jpg" />
            </li>
            <li>
              <img src="<?=base_url();?>assets/images/kitchen_adventurer_caramel.jpg" />
            </li>
          </ul>
        </div>
  </div>



<div class="grid col-md-offset-2 col-md-9 text-center">
    <table class="table" style="display:block" >
        <tr>
            <td>
          <img src="<?=base_url();?>assets/mini-banner.jpg" width="80%">
      </td>
            <td>     
          <img src="<?=base_url();?>assets/mini-banner.jpg" width="80%">
      </td>
        </tr>
        <tr>
            <td>     
          <img src="<?=base_url();?>assets/mini-banner.jpg" width="80%">
            </td>
            <td>              <img src="<?=base_url();?>assets/mini-banner.jpg" width="80%">

            </td>
        </tr>
    </table>
 </div>



    <div
          class="quote col-md-offset-3 col-md-6 text-center">
 <blockquote class="quote-card">
              <p class="quotecontent">
                "Lorem ipsum dolor sit amet, consectetur adipisicing elit." 
              </p>

              <p class="quoteautor">
                Lorem I psum
              </p>
            </blockquote>
    </div>
</div>


<div class="lookbook col-md-offset-2 col-md-9 text-center">
      <h3 class="subjudul">Ladies Room</h3>
     <div class = "col-sm-5 col-md-3">
      <div class = "thumbnail">
         <img src = "<?=base_url();?>assets/images/kitchen_adventurer_donut.jpg" alt = "Generic placeholder thumbnail">
      </div>

      <div class = "caption">
         <h3 class="thumbnail">Thumbnail label</h3>

      </div>
   </div>
   <div class = "col-sm-5 col-md-3">
      <div class = "thumbnail">
         <img src = "<?=base_url();?>assets/images/kitchen_adventurer_donut.jpg" alt = "Generic placeholder thumbnail">
      </div>

      <div class = "caption">
           <h3 class="thumbnail">Thumbnail label</h3>


      </div>
   </div>
   <div class = "col-sm-5 col-md-3">
      <div class = "thumbnail">
         <img src = "<?=base_url();?>assets/images/kitchen_adventurer_donut.jpg" alt = "Generic placeholder thumbnail">
      </div>

      <div class = "caption">
            <h3 class="thumbnail">Thumbnail label</h3>


      </div>
   </div>
   <div class = "col-sm-5 col-md-3">
      <div class = "thumbnail">
         <img src = "<?=base_url();?>assets/images/kitchen_adventurer_donut.jpg" alt = "Generic placeholder thumbnail">
      </div>

      <div class = "caption">
           <h3 class="thumbnail">Thumbnail label</h3>


      </div>
   </div>

  </div>
  <div class="instagram col-md-offset-2 col-md-9 text-center">
<h3 class="subjudul">See The Latest On Instagram</h3>
  <div id="" class="flexslider slide_thumb">
          <ul class="slides">
            <li>
              <img src="<?=base_url();?>assets/images/kitchen_adventurer_cheesecake_brownie.jpg" />
            </li>
            <li>
              <img src="<?=base_url();?>assets/images/kitchen_adventurer_lemon.jpg" />
            </li>
            <li>
              <img src="<?=base_url();?>assets/images/kitchen_adventurer_donut.jpg" />
            </li>
            <li>
              <img src="<?=base_url();?>assets/images/kitchen_adventurer_caramel.jpg" />
            </li>
            <li>
              <img src="<?=base_url();?>assets/images/kitchen_adventurer_cheesecake_brownie.jpg" />
            </li>
            <li>
              <img src="<?=base_url();?>assets/images/kitchen_adventurer_lemon.jpg" />
            </li>
            <li>
              <img src="<?=base_url();?>assets/images/kitchen_adventurer_donut.jpg" />
            </li>
            <li>
              <img src="<?=base_url();?>assets/images/kitchen_adventurer_caramel.jpg" />
            </li>
            <li>
              <img src="<?=base_url();?>assets/images/kitchen_adventurer_cheesecake_brownie.jpg" />
            </li>
            <li>
              <img src="<?=base_url();?>assets/images/kitchen_adventurer_lemon.jpg" />
            </li>
            <li>
              <img src="<?=base_url();?>assets/images/kitchen_adventurer_donut.jpg" />
            </li>
            <li>
              <img src="<?=base_url();?>assets/images/kitchen_adventurer_caramel.jpg" />
            </li>
          </ul>
        </div>

</div>
 <div class="subscribe col-md-offset-3 col-md-6 text-center">
<h3 class="subjudul">SUBSCRIBE TO OUR NEWSLETTER</h3>
<p>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. 
Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
</p>

<div class="input-group col-md-offset-2 col-md-8">
    <input type="text" class="form-control"/>
    <span class="input-group-addon">
        <i class="fa fa-check"></i>
    </span>
</div>
</div>

和我的关于页面

<style>

</style>
<div style="background-color: pink; height: 400px; margin-top: 50px" class="col-md-12">
    <div class="box">
        <div class="box-inner">
            <p>lorem ipsum dolar sit amet</p>
        </div>
    </div>
</div>
<iframe class="youtubeabout" width="900px" height="400px" src="https://www.youtube.com/embed/viWs0M5R2BLo" frameborder="0" allowfullscreen></iframe>

<div class="about col-md-offset-5 col-md-5">
    <h3 class="subjudul">About Us</h3>
</div>

<div style="margin-bottom: 100px" class="abouttext col-md-offset-1 text-center col-md-10">
    <p style="text-align: center;"> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. </p>
    <p>
    Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc,</p>

    <p> Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc,
    </p>
</div>

1 个答案:

答案 0 :(得分:5)

您将以98%设置第二个背景位置。这意味着您将根据顶部中的98%设置其位置。在不同高度的页面上,背景的视觉位置在绝对像素上会略有不同。

您的页脚似乎高约40px,因此不是98%,而是将值设置为calc(100% - 40px)