【发布时间】:2016-11-10 02:35:55
【问题描述】:
我使用仅在角落显示的选择器创建了边框效果,如下面的 sn-p 所示。
html {
box-sizing: border-box !important;
}
*, *:before, *:after {
box-sizing: inherit;
}
.ix-border{
position: relative;
padding: 0;
margin: 0;
border-style: solid;
display: inline-block;
border-width: 1px;
background-color: transparent;
border-color: #A00;
}
.ix-border, .ix-border:hover, .ix-border:before, .ix-border:after{
transition: 0.42s;
}
.ix-border:before, .ix-border:after{
content:'';
position:absolute;
padding: 0;
margin: 0;
border-style: solid;
display: inline-block;
border-width: 1px;
background-color: transparent;
border-color: #FFF;
}
.ix-border:before{
top: 8px; right:-1px; bottom: 8px; left:-1px;
border-width: 0 1px 0 1px;
}
.ix-border:after{
top:-1px; right: 8px; bottom:-1px; left: 8px;
border-width: 1px 0 1px 0;
}
.ix-border:hover{
border-color: #F00;
}
.ix-border:hover:before{
top: 16px; bottom: 16px;
border-width: 0 1px 0 1px;
}
.ix-border:hover:after{
right: 16px; left: 16px;
border-width: 1px 0 1px 0;
}
.elmt{
width: 120px;
height: 60px;
text-align: center;
line-height: 60px;
}
<div class="elmt ix-border">
Hello World
</div>
但是,我注意到在执行缩放时,应该由 ::before/::after 选择器边框隐藏的元素边框有时会在一侧或两侧随机可见,具体取决于缩放因素和导航器。
我添加了box-sizing:border box,以便在缩放计算中包含边框,正如here 建议的那样,但它仍然没有修复。
那么,我错过了什么吗?是否有任何 hack 来修复它或任何其他方式(仅限 css)来达到相同的效果?
【问题讨论】:
-
为什么需要担心放大外观?这不是移动网站的显示方式。
-
好的,伙计,我现在已经用另一个(更好的?)解决方案编辑了我的答案,它的元素更少,希望对您有所帮助......
标签: css pseudo-element