居中位置:相对于td?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (2)
  • 关注 (0)
  • 查看 (107)

我有一张表,想要为某些行添加手风琴切换以显示更多信息。我找到了一个漂亮的+/-动画来配合手风琴切换,但似乎无法让它在我的td中正确居中。到目前为止我的代码看起来像这样:

<tr ng-repeat="item in c.list track by $index" ng-if="$index >= data.window_start && $index < data.window_end">
          <td>
            <div ng-class="{'accordion-toggle collapsed':item.work_history_type == 'Uniformed Service'}" data-toggle="collapse" href="#{{item.sys_id}}" role="button" aria-expanded="false" aria-controls="collapseDetails"></div>
          </td>
          <td>{{item.work_history_type}}
          </td>
          <td>{{item.work_name}}
            <div id="{{item.sys_id}}" class="collapse">
              <div ng-repeat="item2 in c.list2 | filter: {'uni' : item.sys_id}">
                <span ng-click="c.newEntry(item2.sys_id, 'campaign_table','newWork')"class="h4 edit" >{{item2.camp}}: From: {{item2.from}} To: {{item2.to}}</span>
              </div>
            </div>          
          </td>

          <td>{{item.from}}</td>
          <td>{{item.to}}</td>
        </tr>

我的CSS看起来像这样:

.accordion-toggle {
  position: relative;
}

.accordion-toggle::before,
.accordion-toggle::after {
  content: '';
  display: block;
  position: absolute;
  width: 12px;
  height: 2px;
  background-color: $color-darkest;
  -webkit-transform-origin: 50% 50%;
  -ms-transform-origin: 50% 50%;
  transform-origin: 50% 50%;
  -webkit-transition: all 0.25s;
  transition: all 0.25s;
}
.accordion-toggle::before {
  -webkit-transform: rotate(-90deg);
  -ms-transform: rotate(-90deg);
  transform: rotate(-90deg);
  opacity: 0;
}
.accordion-toggle.collapsed::before {
  -webkit-transform: rotate(0deg);
  -ms-transform: rotate(0deg);
  transform: rotate(0deg);
  opacity: 1;
}
.accordion-toggle.collapsed::after {
  -webkit-transform: rotate(-90deg);
  -ms-transform: rotate(-90deg);
  transform: rotate(-90deg);
}

.accordion-toggle > span {
  margin-left: 20px;
}

最终结果如下:

加号未正确对齐,有关如何解决此问题的指导?

提问于
用户回答回答于

试着看看这个代码:https:/codepen.io/samandAu/PEN/LrbpqJ

.accordion-toggle::before,
.accordion-toggle::after {
  content: '';
  display: block;
  position: absolute;
  width: 12px;
  height: 2px;
  background-color: red;
  -webkit-transform-origin: 50% 50%;
  -ms-transform-origin: 50% 50%;
  transform-origin: 50% 50%;
  -webkit-transition: all 0.25s;
  transition: all 0.25s;
  top: 50%;
  left: 0;
}
用户回答回答于

试着以它为中心

.accordion-toggle > span {
    margin-left:20%;
    top:50%;
}

扫码关注云+社区

领取腾讯云代金券