Как установить разные z-Index между div? - PullRequest
0 голосов
/ 25 августа 2018

У меня есть различия div на одном уровне, но я хочу установить другое z-index.

Это мой jsfiddle: https://jsfiddle.net/k85t9zgq/8/

Это экран:

enter image description here

Как я могу сделать красный div видимым только в белом div?

#page {
  margin-top: 50px;
  width: 300px;
  height: 300px;
  background-color: #000;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  z-index: 4;
}

#box-first,
#box-second {
  width: 200px;
  height: 100px;
  background-color: #fff;
  border-radius: 200px 200px 0 0;
  margin-top: 10px;
  margin-bottom: 10px;
  position: relative;
  display: flex;
  justify-content: flex-end;
  align-items: flex-start;
  z-index: 3;
}

#first,
#second {
  border-radius: 200px 200px 0 0;
  margin: 0;
  background: red;
  width: 200px;
  height: 100px;
  transform: rotate(230deg);
  transform-origin: 50% 100%;
  position: absolute;
  top: 0px;
  right: 0px;
  border: 0;
  z-index: 1;
}

#n1,
#n2 {
  font-size: 20px;
  color: #000;
  font-weight: bold;
  position: absolute;
  left: 50px;
  right: 0;
  text-align: center;
  top: 50px;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100px;
  height: 50px;
  background: yellow;
  border-radius: 100px 100px 0 0;
}
<div id="page">
  <div id="box-first">
    <div id="first" class="first-pause">
    </div>
    <div id="n1">
      1500
    </div>
  </div>
  <div id="box-second">
    <div id="second" class="second-pause">
    </div>
    <div id="n2">
      270
    </div>
  </div>
</div>

1 Ответ

0 голосов
/ 25 августа 2018

Я бы рассмотрел другой способ добиться этого с меньшим количеством кода:

.box {
  width:300px;
  height:300px;
  box-sizing:border-box;
  border:70px solid transparent;
  border-radius:50%;
  background:
   linear-gradient(to top,#000 50%,transparent 50%) border-box,
   linear-gradient(yellow,yellow) padding-box,
   /*adjust the degree to control the red part from 0deg to 180deg*/
   linear-gradient(var(--p,60deg), red 49.8%,transparent 50%) border-box, 
   #fff;
  margin-bottom:-140px; 
  text-align:center;
  font-size:40px;
  font-weight:bold;
}

body {
  background:#000;
}
<div class="box">
    1500
</div>
<div class="box" style="--p:120deg">
    1500
</div>

Но для вас начальный код просто рассмотрите overflow:hidden и увеличьте z-index желтого div

#page {
    margin-top: 50px;
    width: 300px;
    height: 300px;
    background-color: #000;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    z-index: 4;
}

#box-first, #box-second {
    width: 200px;
    height: 100px;
    background-color: #fff;
    border-radius: 200px 200px 0 0;
    margin-top: 10px;
    margin-bottom: 10px;
    position: relative;
    display: flex;
    justify-content: flex-end;
    align-items: flex-start;
    z-index: 3;
    overflow:hidden;
}


#first, #second {
    border-radius: 200px 200px 0 0;
    margin: 0;
    background: red;
    width: 200px;
    height: 100px;
    transform: rotate(230deg);
    transform-origin: 50% 100%;
    position: absolute;
    top: 0px;
    right: 0px;
    border: 0;
    z-index: 1;
}


#n1, #n2 {
    font-size: 20px;
    color: #000;
    font-weight: bold;
    position: absolute;
    z-index:3;
    left: 50px;
    right: 0;
    text-align: center;
    top: 50px;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100px;
    height: 50px;
    background: yellow;
    border-radius: 100px 100px 0 0;
}
<div id="page">
  <div id="box-first">
    <div id="first" class="first-pause">
     
    </div> <div id="n1">
        1500
      </div>
  </div>
  <div id="box-second">
    <div id="second" class="second-pause">
    
    </div>  <div id="n2">
        270
      </div>
  </div>
</div>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...