如何实现这种效果?它的边界/线条

时间:2017-04-03 05:14:59

标签: css html5 css3

https://codepen.io/anon/pen/NpoevM

http://imgur.com/a/OQ3cu

我想用小线来分隔盒子。我正在考虑如何在图片中制作线条。我在考虑使用bordersspan,但遇到了麻烦



#third {
  height: 55%;
  width: 40%;
  display: flex;
  flex-direction: column;
  float: right;
}
.t-row {
  height: 100%;
  display: flex;
}
.tbox {
  width: 50%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
.fa {
  font-size: 5em !important;
}

<section id="third">
  <div class="hr-lines">
    <hr class="icon-sep">
  </div>
  <div class="t-row">
    <div class="tbox tb-one">
      <i class="fa fa-home" aria-hidden="true"></i>
      <h1 class="t-text">Home</h1>
    </div>
    <div class="tbox tb-two">
      <i class="fa fa-info-circle" aria-hidden="true"></i>
      <h1 class="t-text">About</h1>
    </div>
  </div>	
  <div class="t-row">
    <div class="tbox tb-three">
      <i class="fa fa-book" aria-hidden="true"></i>
      <h1 class="t-text">Work</h1>
    </div>
    <div class="tbox tb-four">
      <i class="fa fa-envelope" aria-hidden="true"></i>
      <h1 class="t-text">Hire</h1>
    </div>
  </div>
</section>
&#13;
&#13;
&#13;

3 个答案:

答案 0 :(得分:1)

检查下面的代码段。我已将:after用于所有四个div,并使用border创建了+符号。

&#13;
&#13;
#third {
    height: 55%;
    width: 40%;
    display: flex;
    flex-direction: column;
    float: right;
}

.t-row {
    height: 100%;
    display: flex;
}

.tbox {
    width: 50%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.fa {
    font-size: 5em !important;
}

.tb-one,
.tb-two,
.tb-three,
.tb-four {
    position: relative;
}

.tb-one:after,
.tb-two:after,
.tb-three:after,
.tb-four:after {
    position: absolute;
    content: " ";
    border: 1px solid #000;
    width: 20px;
    height: 20px;
    display: block;
}

.tb-one:after {
    bottom: 0;
    right: 0;
    border-top: none;
    border-left: none
}

.tb-two:after {
    bottom: 0;
    left: 0;
    border-top: none;
    border-right: none
}

.tb-three:after {
    top: 0;
    right: 0;
    border-bottom: none;
    border-left: none
}

.tb-four:after {
    top: 0;
    left: 0;
    border-bottom: none;
    border-right: none
}
&#13;
<section id="third">
    <div class="hr-lines">
        <hr class="icon-sep"> 
    </div>
    <div class="t-row">
        <div class="tbox tb-one"> 
           <i class="fa fa-home" aria-hidden="true"></i>
           <h1 class="t-text">Home</h1> 
        </div>
        <div class="tbox tb-two"> 
           <i class="fa fa-info-circle" aria-hidden="true"></i>
           <h1 class="t-text">About</h1> 
        </div>
    </div>
    <div class="t-row">
        <div class="tbox tb-three"> 
           <i class="fa fa-book" aria-hidden="true"></i>
           <h1 class="t-text">Work</h1> 
        </div>
        <div class="tbox tb-four"> 
            <i class="fa fa-envelope" aria-hidden="true"></i>
            <h1 class="t-text">Hire</h1> 
        </div>
    </div>
</section>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

在你的代码中添加四个边界属性为div的类。

    <style>
#third {
    height: 55%;
    width: 40%;
    display: flex;
    flex-direction: column;
    float: right;
}

.t-row {
    height: 100%;
    display: flex;
}

.tbox {
    width: 50%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}


.fa {
    font-size: 5em !important;
}
.left-border{ border-left : 1px solid;}
.right-border{ border-right : 1px solid;}
.bottom-border{ border-bottom : 1px solid;}
.top-border{ border-top: 1px solid;}
</style>
<section id="third">
    <div class="hr-lines">
        <hr class="icon-sep">
    </div>
    <div class="t-row">
        <div class="tbox tb-one  right-border bottom-border">
            <i class="fa fa-home" aria-hidden="true"></i>
            <h1 class="t-text">Home</h1>
        </div>
        <div class="tbox tb-two left-border bottom-border">
            <i class="fa fa-info-circle" aria-hidden="true"></i>
            <h1 class="t-text">About</h1>
        </div>
    </div>  
    <div class="t-row">
        <div class="tbox tb-three top-border right-border">
            <i class="fa fa-book" aria-hidden="true"></i>
            <h1 class="t-text">Work</h1>
        </div>
        <div class="tbox tb-four top-border left-border">
            <i class="fa fa-envelope" aria-hidden="true"></i>
            <h1 class="t-text">Hire</h1>
        </div>
    </div>
</section>

答案 2 :(得分:0)

您可以在span内使用'+'并定位/设置

#third {
	height: 55%;
	width: 40%;
	display: flex;
	flex-direction: column;
	float: right;
  position:relative;
}

.t-row {
	height: 100%;
	display: flex;
}

.tbox {
	width: 50%;
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
}




.fa {
	font-size: 5em !important;
}

.lines { position:absolute; font-size:150px; top:17%; left:40% }
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css" rel="stylesheet">

<section id="third">
  <span class="lines">+</span>
		<div class="t-row">
			<div class="tbox tb-one">
				<i class="fa fa-home" aria-hidden="true"></i>
				<h1 class="t-text">Home</h1>
			</div>
			<div class="tbox tb-two">
				<i class="fa fa-info-circle" aria-hidden="true"></i>
				<h1 class="t-text">About</h1>
			</div>
		</div>	
		<div class="t-row">
			<div class="tbox tb-three">
				<i class="fa fa-book" aria-hidden="true"></i>
				<h1 class="t-text">Work</h1>
			</div>
			<div class="tbox tb-four">
				<i class="fa fa-envelope" aria-hidden="true"></i>
				<h1 class="t-text">Hire</h1>
			</div>
		</div>
	</section>