在表格单元格内重新缩放div

时间:2015-07-06 16:18:45

标签: html5 css3 rescale

我试图在表格的每一行添加一个简单的upvote / downvote计数器。计数器基本上是由css塑造的div的容器,我将其插入表格单元格中。但是,投票计数器会导致行气球升温。我尝试调整最顶部的div容器,但它只调整投票元素的大小。实际的计数器大小相同。我是css的新手,所以我还没有很好的意识。重写CSS的最佳方法是什么,这样我就可以轻松地从最高级别扩展整个投票计数器,而无需手动更改所有子元素?如果我想在我的网站上的其他地方坚持这个计数器,而不是在桌面单元格内,这将是很好的。

这是jsfiddle。 https://jsfiddle.net/havok2063/30way48v/

非常简单的html描述了upvote / downvote计数器。

<div class="vote circle">
    <div class="increment up"></div>
    <div class="increment down"></div>

    <div class="count">8</div>
</div>

这是CSS。

.vote {
  display: flex;
  flex-direction: column;
  position: relative;
  width: 10rem;
  height: 10rem;
}

.circle .up { border-radius: 10rem 10rem 0 0; }
.circle .down { border-radius: 0 0 10rem 10rem; }
.circle .count { border-radius: 50%; }

.up {
  background: #4BC35F;
  height: 50%;
  margin-bottom: 0.25rem;  
}
.down {
  background: #C15044;
  height: 50%;  
}

.increment {
  flex: 1 0 0;
  text-align: center;
  opacity: .5;
  transition: 0.3s;
  cursor: pointer;
}
.increment:hover { 
  opacity : 1;
}

.count {
  position: absolute;
  top: 0;
  background: rgba(245,245,245,1.0);
  border-radius: 0.1rem;
  margin: 2.5rem;
  width: 5rem;
  font-size: 2.5rem;
  font-weight: bold;
  line-height: 5rem;
  text-align: center;
  box-shadow: 0 0 0 0.5rem rgba(245,245,245,1.0);
  pointer-events: none;
}

html, body { height: 100%; }

2 个答案:

答案 0 :(得分:0)

你是否试图让所有的桌子单元像这个小提琴一样高度? https://jsfiddle.net/30way48v/2/

如果有,请将其添加到您的css td{height: 100px;}

答案 1 :(得分:0)

好的,这里的<td>更小 这是小提琴https://jsfiddle.net/30way48v/3/

td{height: 50px;}
.vote {
  display: flex;
  flex-direction: column;
  position: relative;
  width: 5rem;
  height: 5rem;
  margin: 0px;

}

.circle .up { border-radius: 5rem 5rem 0 0; }
.circle .down { border-radius: 0 0 5rem 5rem; }
.circle .count { border-radius: 50%; }

.up {
  background: #4BC35F;
  height: 50%;
  margin-bottom: 0.25rem;  
}
.down {
  background: #C15044;
  height: 50%;  
}

.increment {
  flex: 1 0 0;
  text-align: center;
  opacity: .5;
  transition: 0.3s;
  cursor: pointer;
}
.increment:hover { 
  opacity : 1;
}

.count {
  position: absolute;
  top: 0;
  background: rgba(245,245,245,1.0);
  border-radius: 0.1rem;
  margin: 1.45rem;
  width: 2rem;
  font-size: 2.5rem;
  font-weight: bold;
  line-height: 2rem;
  text-align: center;
  box-shadow: 0 0 0 0.5rem rgba(245,245,245,1.0);
  pointer-events: none;

  &.upvoted { color: #4BC35F; }
  &.downvoted { color: #C15044; }
}

html, body { height: 100%; }
相关问题