Bold on Hover… Without the Layout Shift

栏目: IT技术 · 发布时间: 4年前

内容简介:When you change theRyan’s technique is very clever. Each item in the list has a pseudo-element on it with the exact text in the link. That pseudo-element is visually hidden, but pre-bolded and still occupies width. So when the actual link text is bolded, i

When you change the font-weight of a font, the text will typically cause a bit of a layout shift. That’s because bold text is often larger and takes up more space. Sometimes that doesn’t matter, like a vertical stack of links where the wider/bolder text doesn’t push anything anyway. Sometimes it does matter, like a horizontal row where the wider/bolder text pushes other elements away a smidge.

Ryan Mulligan demonstrates :

Bolding text on mouse hover causes a layout shift that’s especially noticeable when elements start wrapping. Here’s a nifty trick: add a hidden pseudo element with the same text string but set it to the bold font size 

See it on @CodePen : https://t.co/kBzZXqqtmi pic.twitter.com/kdZBTLQ0RD

— Ryan Mulligan (@hexagoncircle) July 20, 2020

Ryan’s technique is very clever. Each item in the list has a pseudo-element on it with the exact text in the link. That pseudo-element is visually hidden, but pre-bolded and still occupies width. So when the actual link text is bolded, it won’t take up any additional width.

It also sorta depends on how you’re doing the layout. Here, if I force four columns with CSS grid and text that doesn’t really challenge the width, the bolding doesn’t affect the layout either:


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

十亿美金的教训

十亿美金的教训

林军 唐宏梅 / 浙江大学出版社 / 2011-5 / 39.00元

《十亿美金的教训》内容简介:创业者个人能力欠缺、团队涣散、经营方向把握不当、资金动用失措以及时局不利……这其中有哪一个细节被忽视,都可能是失败的导火索! 国内二十年互联网风云,有人成功,有人失败。两种结果,不同方向,却往往只是一线之隔。他们留给我们怎样的教训与启示?后来者要怎样才能跳出失败之殇? 《十亿美金的教训》选取了互联网十个经典的失败案例,并深层解读这些互联网企业与创业者们从成功......一起来看看 《十亿美金的教训》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具