如何在带有图像的圆圈之间放置线条?

时间:2016-08-21 21:38:13

标签: html css layout psd

我是HTML和CSS的初学者所以我决定尝试代码.psd布局。不幸的是,我对这部分布局感到困惑:

enter image description here

我指的是带有图像的圆圈之间的线条。 这是我的代码:



html {
    font-size: 62.5%;
}

body {
  width: 1400px;
  font-family: "Roboto Slab", serif;
}

section {
  padding-right: 230px;
  padding-left: 230px;
}

.culture {
    padding-top: 100px;
    padding-bottom: 100px;
    background-color: #f9f9f9;
    overflow: auto;
}

h2 {
    font-family: "Montserrat", sans-serif;
    font-size: 4rem;
    color: #222;
    text-align: center;
}

.culture p {
    color: #777;
    text-align: center;
}

.culture > p {
    padding-top: 20px;
    padding-bottom: 89px;
    font-size: 2rem;
}

.value {
    float: left;
    padding-right: 56px;
}

.line {
    width: 170px;
    height: 2px;
    background-color: #777;
}

.value_img {
    width: 91px;
    height: 91px;
    margin: 0 auto 25px;
    border: 2px #777 solid;
    border-radius: 100%;
    background-repeat: no-repeat;
    background-position: center center;
}

.balance {
    background-image: url("http://d-k.aq.pl/note.png");
}

.quality {
    background-image: url("http://d-k.aq.pl/chart.png");
}

.excellence {
    background-image: url("http://d-k.aq.pl/star.png");
}

h3 {
    font-family: "Montserrat", sans-serif;
    font-size: 1.8rem;
    color: #222;
    text-align: center;
}

.value p {
    padding-top: 20px;
    font-size: 1.4rem;
}

<head>
  <link href="https://fonts.googleapis.com/css?family=Montserrat:400,700" rel="stylesheet" type="text/css">
  <link href="https://fonts.googleapis.com/css?family=Roboto+Slab:100,300,400,700" rel="stylesheet" type="text/css">
</head>
<section class="culture">
  <h2>
    CULTURE &amp; VALUES
  </h2>
  <p>
    Phasellus gravida ex at odio elementum.
  </p>
  <div class="value">
    <div class="value_img balance">
                        
    </div>
    <h3>
      WORK-LIFE BALANCE
    </h3>
    <p>
      Suspendisse ut odio vel felis pulvinar<br>
      sodales. Nunc ultricies nibh non velit<br>
      feugiat cursus. Phasellus scelerisque
    </p>
  </div>
  <div class="line">
                    
  </div>
  <div class="value">
    <div class="value_img quality">
                    
    </div>
    <h3>
      QUALITY OVER QUANTITY
    </h3>
    <p>
      Suspendisse ut odio vel felis pulvinar<br>
      sodales. Nunc ultricies nibh non velit<br>
      feugiat cursus. Phasellus scelerisque.
    </p>
  </div>
  <div class="line">
                    
  </div>
  <div class="value">
    <div class="value_img excellence">
                        
    </div>
    <h3>
      DELIVER EXCELLENCE
    </h3>
    <p>
      Suspendisse ut odio vel felis pulvinar<br>
      sodales. Nunc ultricies nibh non velit<br>
      feugiat cursus. Phasellus scelerisque.
    </p>
  </div>
</section>
&#13;
&#13;
&#13;

我应该使用绝对定位吗?

2 个答案:

答案 0 :(得分:1)

使用padding .wrapper来设置所有项目的宽度。

&#13;
&#13;
.wrapper {
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 0 10%;
  }

.item {
  border: 3px solid #777;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  }
.line {
  border: 1px solid #777;
  margin: 0 2%;
  flex: 1 0;
  }
&#13;
<div class="wrapper">
  <div class="item"></div>
  <div class="line"></div>
  <div class="item"></div>
  <div class="line"></div>
  <div class="item"></div>
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

您可以使用伪元素和负边距:

.value + .value .value_img:before {
  content: '';
  display: block;
  margin: 50px 0 0 -190px;
  width: 170px;
  height: 2px;
  background-color: #777;
}

.line {/* deleted from html */}

您还可以查看display:flex来设置布局float,也可以使用margin代替固定的padding

&#13;
&#13;
html {
  font-size: 62.5%;
}
body {
  width: 940px;/* padding of section removed */
  font-family: "Roboto Slab", serif;
  margin: auto;
}
section {
  /* ?? 
  padding-right: 230px;
  padding-left: 230px;
  */
}
.culture {
  padding-top: 100px;
  padding-bottom: 100px;
  background-color: #f9f9f9;
  overflow: auto;
  display: flex;/* set things easily and will allow vertical and or horizontal alignements */
  flex-wrap: wrap;/* we need this here */
}
h2 {
  font-family: "Montserrat", sans-serif;
  font-size: 4rem;
  color: #222;
  text-align: center;
  width: 100%;
}
.culture p {
  color: #777;
  text-align: center;
}
.culture > p {
  padding-top: 20px;
  padding-bottom: 89px;
  font-size: 2rem;
  width: 100%;
}
.value {
  padding: 0 28px;/* around equally , helps to center things visually */
}
/* draw the lines here, .value + .value .. does not select first */
.value + .value .value_img:before {
  content: '';
  display: block;
  margin: 50px 0 0 -190px;
  width: 170px;
  height: 2px;
  background-color: #777;
}
.line {/* no need no more */} 
.value_img {
  width: 91px;
  height: 91px;
  margin: 0 auto 25px;
  border: 2px #777 solid;
  border-radius: 100%;
  background-repeat: no-repeat;
  background-position: center center;
}
.balance {
  background-image: url("http://d-k.aq.pl/note.png");
}
.quality {
  background-image: url("http://d-k.aq.pl/chart.png");
}
.excellence {
  background-image: url("http://d-k.aq.pl/star.png");
}
h3 {
  font-family: "Montserrat", sans-serif;
  font-size: 1.8rem;
  color: #222;
  text-align: center;
}
.value p {
  padding-top: 20px;
  font-size: 1.4rem;
}
&#13;
<head>
  <link href="https://fonts.googleapis.com/css?family=Montserrat:400,700" rel="stylesheet" type="text/css">
  <link href="https://fonts.googleapis.com/css?family=Roboto+Slab:100,300,400,700" rel="stylesheet" type="text/css">
</head>
<section class="culture">
  <h2>
    CULTURE &amp; VALUES
  </h2>
  <p>
    Phasellus gravida ex at odio elementum.
  </p>
  <div class="value">
    <div class="value_img balance">

    </div>
    <h3>
      WORK-LIFE BALANCE
    </h3>
    <p>
      Suspendisse ut odio vel felis pulvinar
      <br>sodales. Nunc ultricies nibh non velit
      <br>feugiat cursus. Phasellus scelerisque
    </p>
  </div>

  <div class="value">
    <div class="value_img quality">

    </div>
    <h3>
      QUALITY OVER QUANTITY
    </h3>
    <p>
      Suspendisse ut odio vel felis pulvinar
      <br>sodales. Nunc ultricies nibh non velit
      <br>feugiat cursus. Phasellus scelerisque.
    </p>
  </div>

  <div class="value">
    <div class="value_img excellence">

    </div>
    <h3>
      DELIVER EXCELLENCE
    </h3>
    <p>
      Suspendisse ut odio vel felis pulvinar
      <br>sodales. Nunc ultricies nibh non velit
      <br>feugiat cursus. Phasellus scelerisque.
    </p>
  </div>
</section>
&#13;
&#13;
&#13;