【发布时间】:2017-03-08 13:15:28
【问题描述】:
这是我遇到的问题的一个示例。单击中间的锚点会使其向右移动。
var anchors = document.getElementsByTagName('a');
var onSelect = function () {
var i, a;
for (i = 0; i < anchors.length; i += 1) {
a = anchors[i];
if (a === this)
continue;
a.classList.remove('selected');
}
this.classList.toggle('selected');
};
(function () {
for (var i = 0; i < anchors.length; i += 1) {
anchors[i].addEventListener('click', onSelect);
}
}());
.table {
display: table;
background-color: indigo;
width: 600px;
}
.row {
display: table-row;
background-color: seagreen;
}
.cell {
display: table-cell;
text-align: center;
vertical-align: middle;
}
a {
padding: 10px;
background-color: lightblue;
display: inline-block;
transition: 0.5s ease;
width: 140px;
height: 30px;
line-height: 30px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
text-decoration: none;
color: black;
}
a.selected {
background-color: blue;
color: white;
}
<div class="table">
<div class="row">
<div class="cell">
<a href="#">A New Hope</a>
</div>
<div class="cell">
<a href="#">The Empire Strikes Back</a>
</div>
<div class="cell">
<a href="#">Return of the Jedi</a>
</div>
</div>
</div>
如果我不更改文本颜色或删除省略号,则不会发生。我只能在 chrome 中重现它,所以我认为这是该浏览器的问题。
想知道是否有已知的解决方法。我的 chrome 版本是 53.0.2785.143 m
jsfiddle 中的相同示例: https://jsfiddle.net/f5k8p3tv/
【问题讨论】:
-
一个令人难以置信的 hacky 解决方法是从父节点中删除
'cell'类,然后将其重新添加。不幸的是,这样做元素会跳动一点,这并不是真正可取的。 -
谢谢。我认为这会起作用,因为“文本对齐:中心;”是导致错误发生的因素之一。如果我删除它,一切正常(除了没有居中对齐)
标签: javascript css google-chrome css-animations