图像在容器外仅一侧

时间:2018-07-16 11:28:47

标签: html css

im使用Bootstrap4。我有div容器,它位于容器右侧。图片div是否可以做同样的事情?我使用伪元素:after和“另一个”背景色来做到这一点。 (如果您不了解我想要实现的目标

enter image description here

body {
  overflow-x: hidden;
}
.box {
     background-color: #F0F6FB;
    padding: 120px 20px;
    margin-right: 0;
    margin-left: auto;
    margin-top: -125px;
    position: relative;
    border-radius: 50px 0px 0px 50px;
}

 .box:after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 80%;
    right: -3000px;
    background: #F0F6FB;
    z-index: -1; 
    }
    
    .box-image {
    background: url(https://images5.alphacoders.com/456/456536.jpg);
    height: 230px;
    border-radius: 0px 50px 50px 0px;
    margin-top: 60px;
    background-size: cover;
    background-position: 50% 50%;
    z-index: 1;
    position: relative;
}
<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  </head>
  <body>
  <br/><br/> <br/><br/> <br/><br/> <br/><br/>
     <div class="container">
       <div class="box-image">&nbsp;</div>
       <div class="box">
         &nbsp;
       </div>
     </div>
     <br/><br/> <br/><br/> <br/><br/> <br/><br/>
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
  </body>
</html>

3 个答案:

答案 0 :(得分:1)

您只能将容器流体用于图像。 我已经编辑了代码。

body {
  overflow-x: hidden;
}
.box {
     background-color: #F0F6FB;
    padding: 120px 20px;
    margin-right: 0;
    margin-left: auto;
    margin-top: -125px;
    position: relative;
    border-radius: 50px 0px 0px 50px;
}

 .box:after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 80%;
    right: -3000px;
    background: #F0F6FB;
    z-index: -1; 
    }
    
    .box-image {
    background: url(https://images5.alphacoders.com/456/456536.jpg);
    height: 230px;
    border-radius: 0px 50px 50px 0px;
    margin-top: 60px;
    background-size: cover;
    background-position: 50% 50%;
    z-index: 1;
    position: relative;
}
<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  </head>
  <body>
  <br/><br/> <br/><br/> <br/><br/> <br/><br/>
     <div class="container-fluid">
       <div class="box-image">&nbsp;</div>
       </div>
       <div class="container">
       <div class="box">
         &nbsp;
       </div>
     
       </div>
       
     <br/><br/> <br/><br/> <br/><br/> <br/><br/>
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
  </body>
</html>

答案 1 :(得分:1)

希望这可以帮助您

body {
  overflow-x: hidden;
}
.box {
     background-color: #F0F6FB;
    padding: 120px 20px;
    margin-right: 0;
    margin-left: auto;
    margin-top: -125px;
    position: relative;
    border-radius: 50px 0px 0px 50px;
}

 .box:after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 80%;
    right: -3000px;
    background: #F0F6FB;
    z-index: -1; 
    }
    
    .box-image {
    background: url(https://images5.alphacoders.com/456/456536.jpg);
    height: 230px;
    border-radius: 0px 50px 50px 0px;
    margin-top: 60px;
    background-size: cover;
    background-position: 50% 50%;
    z-index: 1;
    position: relative;
	width: 80%;
}
<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  </head>
  
   <body>
  <br/><br/> <br/><br/> <br/><br/> <br/><br/>
	   <div class="box-image">&nbsp;</div>
     <div class="container">
      
       <div class="box">
         &nbsp;
       </div>
     </div>
     <br/><br/> <br/><br/> <br/><br/> <br/><br/>
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
  </body>
</html>

答案 2 :(得分:0)

body {
  overflow-x: hidden;
}
.box {
     background-color: #F0F6FB;
    padding: 120px 20px;
    margin-right: 0;
    margin-left: auto;
    margin-top: -125px;
    position: relative;
    border-radius: 50px 0px 0px 50px;
}

 .box:after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 80%;
    right: -3000px;
    background: #F0F6FB;
    z-index: -1; 
    }
    
    
    .box-image {
    background: url(https://images5.alphacoders.com/456/456536.jpg);
    height: 230px;
    border-radius: 0px 50px 50px 0px;
    margin-top: 60px;
    background-size: cover;
    background-position: 50% 50%;
    z-index: 1;
    position: relative;
}
 .box-image:after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    right: 80%;
    left: -3000px;
    background: #FF0000;
    z-index: 1; 
    }
<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  </head>
  <body>
  <br/><br/> <br/><br/> <br/><br/> <br/><br/>
     <div class="container">
       <div class="box-image">&nbsp;</div>
       <div class="box">
         &nbsp;
       </div>
     </div>
     <br/><br/> <br/><br/> <br/><br/> <br/><br/>
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
  </body>
</html>