如何在div周围放置div?

时间:2017-07-07 05:41:55

标签: html css

我想使用CSS设计<div>,如下图所示。我没有得到任何线索。请提供此设计的想法。

Designed image

2 个答案:

答案 0 :(得分:1)

为了给你和想法,即使你应该自己尝试过。

还需要做的是设置所有箭头的位置......

.wrap {
  position: relative;
}

.wrap > div {
  position: absolute;
  width: 90px;
  height: 90px;
  background-color: #AFAFAF;
  border-radius: 50%; 
}

.wrap > div.gray {
  position: absolute;
  top: 100px;
  left: 50px;
  width: 200px;
  height: 200px;
  background-color: #CFCFCF;
}

.wrap > div.gray:before {
  position: relative;
  top: -20px;
  left: -20px;
  content: '';
  display: block;
  width: 200px;
  height: 200px;
  border-radius: 50%;
  z-index: -1;
  border: solid 1px #CFCFCF;
  padding: 20px;
}

.wrap > div.orange {
  background-color: orange;
  top: 0px;
  left: 200px;
}
.wrap > div.green {
  background-color: green;
  top: 80px;
  left: 270px;
}
.wrap > div.purple {
  background-color: purple;
  top: 180px;
  left: 290px;
}
.wrap > div.blue {
  background-color: blue;
  top: 290px;
  left: 290px;
}


/* arrows */
.wrap > div:not(.gray):before {
  position: absolute;
  left: -40px;
  top: 60%;
  content: '';
  display: inline-block;
  width: 30px;
  height: 3px;
  background-color: inherit;
}
.wrap > div:not(.gray):after {
  position: absolute;
  content: '';
  display: block;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0 10px 10px 10px;
  border-color: transparent transparent fuchsia transparent;
}

.wrap > div.orange:before {
  left: -40px;
  top: 100%;
  transform: rotate(-40deg);
}
.wrap > div.orange:after {
  left: -20px;
  top: 75px;
  transform: rotate(44deg);
  border-color: transparent transparent orange transparent;
}


.wrap > div.green:before {
  /* needs position and transform */
  /* see .wrap > div.orange:before {} */
}
.wrap > div.green:after {
  /* needs position, transform  and border-color */
  /* see .wrap > div.orange:after {} */
}

.wrap > div.purple:before {
  /* needs position and transform */
  /* see .wrap > div.orange:before {} */
}
.wrap > div.purple:after {
  /* needs position, transform  and border-color */
  /* see .wrap > div.orange:after {} */
}

.wrap > div.blue:before {
  /* needs position and transform */
  /* see .wrap > div.orange:before {} */
}
.wrap > div.blue:after {
  /* needs position, transform  and border-color */
  /* see .wrap > div.orange:after {} */
}
<div class="wrap">
  <div class="gray"></div>
  <div class="orange"></div>
  <div class="green"></div>
  <div class="purple"></div>
  <div class="blue"></div>
</div>

答案 1 :(得分:0)

嗯,不是用箭头,但我认为这是一个很好的开始学习。

编辑:添加了一些箭头。

#bigGrayOneBox {
    position: absolute;
}

#bigGrayOne {
    width: 100px;
    height: 100px;
    background-color: #E9E9E9;
    border-radius: 100%;
    border: 10px solid white;
    position: relative;
    top: 100px;
}

#bigGrayOne:after {
    border-radius: 100%;
    position: absolute;
    width: 118px;
    height: 118px;
    border: 1px solid #E9E9E9;
    content: "";
    z-index: 1;
    top: -10px;
    left: -10px;
}

#yellow,
#green,
#purple,
#blue {
    width: 50px;
    height: 50px;
    border-radius: 100%;
    position: absolute;
}

#yellow {
    background-color: #E2A213;
    top: 35px;
    left: 100px;
}

#yellow::before {
    content: '';
    left: -18px;
    top: 69px;
    transform: rotate(-58deg);
    width: 30px;
    height: 5px;
    display: block;
    background-color: #E2A213;
    position: absolute;
    z-index: 1;
}

#yellow::after {
    content: "";
    transform: rotate(28deg);
    border-color: transparent transparent #E2A213 transparent;
    display: block;
    border-width: 10px;
    border-style: solid;
    width: 0px;
    position: absolute;
    top: 43px;
    left: -2px;
}

#green {
    background-color: #00A19A;
    top: 100px;
    left: 160px;
}

#green::before {
    content: '';
    left: -43px;
    top: 40px;
    transform: rotate(-18deg);
    width: 30px;
    height: 5px;
    display: block;
    background-color: #00A19A;
    position: absolute;
    z-index: 1;
}

#green::after {
    content: "";
    transform: rotate(73deg);
    border-color: transparent transparent #00A19A transparent;
    display: block;
    border-width: 10px;
    border-style: solid;
    width: 0px;
    position: absolute;
    top: 25px;
    left: -15px;
}

#purple {
    background-color: #D63080;
    top: 180px;
    left: 160px;
}

#purple::before {
    content: '';
    left: -41px;
    top: 5px;
    transform: rotate(19deg);
    width: 30px;
    height: 5px;
    display: block;
    background-color: #D63080;
    position: absolute;
    z-index: 1;
}

#purple::after {
    content: "";
    transform: rotate(107deg);
    border-color: transparent transparent #D63080 transparent;
    display: block;
    border-width: 10px;
    border-style: solid;
    width: 0px;
    position: absolute;
    top: 6px;
    left: -13px;
}

#blue {
    background-color: #173DC6;
    top: 245px;
    left: 105px;
}

#blue::before {
    content: '';
    left: -16px;
    top: -22px;
    transform: rotate(61deg);
    width: 30px;
    height: 5px;
    display: block;
    background-color: #173DC6;
    position: absolute;
    z-index: 1;
}

#blue::after {
    content: "";
    transform: rotate(148deg);
    border-color: transparent transparent #173DC6 transparent;
    display: block;
    border-width: 10px;
    border-style: solid;
    width: 0px;
    position: absolute;
    top: -8px;
    left: 1px;
}
<div id="bigGrayOneBox">
    <div id="bigGrayOne">
    </div>
</div>
<div id="yellow">
</div>
<div id="green">
</div>
<div id="purple">
</div>
<div id="blue">
</div>