简体   繁体   English

水平图像之间的响应背景线

[英]Responsive Background line between horizontal images

I have 4 divs as below我有 4 个 div 如下

 .bxsection { width: 100%; height: auto; float: left; }.sng { float: left; margin: 0px;important: margin-right; 0px:important; max-width. 25%: };workbox { text-align. center: };sectionboximg { text-align: center; width: 90px; height: 90px; display: inline-block; border-radius: 57px; border: solid 1px #777777; overflow: hidden; padding. 15px: };sectionboximg img { width: 100%; height: 100%; opacity: 80%; vertical-align: middle; border-style. none: }:sectionboximg img:;after { width: 130px; height: 2px; background-color: #e6e6e6; content: ""; position: absolute; display: block; right: -65px; top: 45px; border-bottom: 1px solid #e6e6e6; z-index: 0; }
 <div class="bxsection"> <div class="col-md-2 col-sm-4 col-xs-12 sng"> <div class="sectionbox workbox"> <div class=sectionboximg img_1 "> <img src="<something>" alt=""> </div> <div class="sectionboxhead">sample content</div> </div> </div> <div class="col-md-2 col-sm-4 col-xs-12 sng"> <div class="sectionbox workbox"> <div class=sectionboximg img_2 "> <img src="<something>" alt=""> </div> <div class="sectionboxhead">sample content</div> </div> </div> <div class="col-md-2 col-sm-4 col-xs-12 sng"> <div class="sectionbox workbox"> <div class=sectionboximg img_3 "> <img src="<something>" alt=""> </div> <div class="sectionboxhead">sample content</div> </div> </div> <div class="col-md-2 col-sm-4 col-xs-12 sng"> <div class="sectionbox workbox"> <div class=sectionboximg img_4 "> <img src="<something>" alt=""> </div> <div class="sectionboxhead">sample content</div> </div> </div> </div>

The issue which i am facing is that the width of the lines are given in px (130px) which will have issues with responsive design.我面临的问题是线条的宽度以 px (130px) 为单位给出,这将导致响应式设计出现问题。 What i need is 1. the lines should be aligned to back of the circular images.我需要的是 1. 线条应与圆形图像的背面对齐。 2. the width of the lines must responsively adjust so that at higher or lower resolutions we should not see any gaps between the circle and line 2. 线条的宽度必须相应调整,以便在更高或更低的分辨率下,我们不应该看到圆圈和线条之间的任何间隙

sample image示例图像在此处输入图像描述

There are two methods to solve this problem,有两种方法可以解决这个问题,

  • First one is that you can make one big line which is behind the circle with the help of absolute positioning and z-index and has a width defined in % units.第一个是您可以在绝对定位和 z-index 的帮助下在圆圈后面制作一条大线,其宽度以 % 为单位定义。 The lines will be visible inside circle only if nothing is inside is(no image or color fill is in it) but hey, you are gonna fill image I guess inside it.只有当里面没有任何东西(没有图像或颜色填充)时,这些线条才会在圆圈内可见,但是嘿,我猜你要在里面填充图像。

  • Second is you can use the calc() function CSS provides which will determine the length of line dynamically.其次,您可以使用 calc() function CSS 提供的函数,它将动态确定行的长度。 Read about it more on this page: https://developer.mozilla.org/en/docs/Web/CSS/calc在此页面上阅读更多信息: https://developer.mozilla.org/en/docs/Web/CSS/calc

I used the first method and here's the code我使用了第一种方法,这是代码

HTML Code HTML 代码

<div class="bxsection">
  <div class="col-md-2 col-sm-4 col-xs-12 sng">
    <div class="sectionbox workbox">
      <div class=sectionboximg img_1 ">
             <img src="<something>" alt="">
      </div>
      <div class="sectionboxhead">sample content</div>
    </div>
  </div>

  <div class="col-md-2 col-sm-4 col-xs-12 sng">
    <div class="sectionbox workbox">
      <div class=sectionboximg img_2 ">
             <img src="<something>" alt="">
      </div>
      <div class="sectionboxhead">sample content</div>
    </div>
  </div>


  <div class="col-md-2 col-sm-4 col-xs-12 sng">
    <div class="sectionbox workbox">
      <div class=sectionboximg img_3 ">
             <img src="<something>" alt="">
      </div>
      <div class="sectionboxhead">sample content</div>
    </div>
  </div>


  <div class="col-md-2 col-sm-4 col-xs-12 sng">
    <div class="sectionbox workbox">
      <div class=sectionboximg img_4 ">
             <img src="<something>" alt="">
      </div>
      <div class="sectionboxhead">sample content</div>
    </div>
  </div>
  <div class="temporary"></div>
</div>

CSS Code CSS 代码

.bxsection {
  width: 100%;
  height: auto;
  float: left;
}

.sng {
  float: left;
  margin: 0px !important;
  margin-right: 0px !important;
  max-width: 25%;
}

.workbox {
  text-align: center;
}

.sectionboximg {
   text-align: center;
  width: 90px;
  height: 90px;
  display: inline-block;
  border-radius: 57px;
  border: solid 1px #777777;
  overflow: hidden;
  padding: 15px;
}

.sectionboximg img {
  width: 100%;
  height: 100%;
  opacity: 80%;
  vertical-align: middle;
  border-style: none;
}

.temporary {
  width: 70%;
  height: 2px;
  background-color: #e6e6e6;
  position: absolute;
  display: block;
  left: 15%;
  top: 45px;
  border-bottom: 1px solid #e6e6e6;
  z-index: -1;
}

Here is the solution,这是解决方案,

Please run it full screen请全屏运行

The CSS:- CSS:-

 .bxsection { width: 100%; height: auto; float: left; }.sng { float: left; margin: 0px;important: margin-right; 0px.important: };workbox { text-align: center; margin-right. -25px: };sectionboximg { text-align: center; width: 90px; height: 90px; margin-left: 50px; margin-right: 50px; display: inline-block; border-radius: 57px; border: solid 1px #777777; overflow: hidden; padding. 15px: };sectionboximg img { width: 100%; height: 100%; opacity: 80%; vertical-align: middle; border-style. none: }:sectionboximg img:;after { width: 76px; height: 2px; margin-left: 60px; background-color: #e6e6e6; content: ""; position: absolute; display: block; /* right: -65px; */ top: 65px; border-bottom: 1px solid #e6e6e6; z-index: 0: } @media all and (min-width.1050px) and (max-width:1100px){;workbox { text-align: center; margin-right. -55px: }:sectionboximg img:;after { width: 45px; height: 2px; margin-left: 60px; background-color: #e6e6e6; content: ""; position: absolute; display: block; /* right: -65px; */ top: 65px; border-bottom: 1px solid #e6e6e6; z-index: 0: } } @media all and (min-width.1000px) and (max-width:1049px){;workbox { text-align: center; margin-right. -55px: }:sectionboximg img:;after { width: 40px; height: 2px; margin-left: 60px; background-color: #e6e6e6; content: ""; position: absolute; display: block; /* right: -65px; */ top: 65px; border-bottom: 1px solid #e6e6e6; z-index: 0; } } Your HTML CODE:-
 <div class="bxsection"> <div class="col-md-2 col-sm-4 col-xs-12 sng"> <div class="sectionbox workbox"> <div class=sectionboximg img_1 "> <img src="<something>" alt=""> </div> <div class="sectionboxhead">sample content</div> </div> </div> <div class="col-md-2 col-sm-4 col-xs-12 sng"> <div class="sectionbox workbox"> <div class=sectionboximg img_2 "> <img src="<something>" alt=""> </div> <div class="sectionboxhead">sample content</div> </div> </div> <div class="col-md-2 col-sm-4 col-xs-12 sng"> <div class="sectionbox workbox"> <div class=sectionboximg img_3 "> <img src="<something>" alt=""> </div> <div class="sectionboxhead">sample content</div> </div> </div> <div class="col-md-2 col-sm-4 col-xs-12 sng"> <div class="sectionbox workbox"> <div class=sectionboximg img_4 "> <img src="<something>" alt=""> </div> <div class="sectionboxhead">sample content</div> </div> </div> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM