admin管理员组文章数量:1133769
I'm struggling to achieve the same result as Flowbite form fields. They seem to use a 1px border on focus (with a 2px transparent outline) but the result looks like a 2px border...
How to prevent layout shift when applying a 2px border to a 1px field on focus?
My pen
Relevant piece:
#contact input[type="text"],
#contact input[type="email"],
#contact input[type="tel"],
#contact input[type="url"],
#contact textarea {
border: 1px solid #ccc;
}
#contact input:focus,
#contact textarea:focus {
border-color: tomato;
border-width: 2px; /* Flowbite form fields seem to have a 1px border */
outline: 2px solid transparent;
outline-offset: 2px;
}
I'm struggling to achieve the same result as Flowbite form fields. They seem to use a 1px border on focus (with a 2px transparent outline) but the result looks like a 2px border...
How to prevent layout shift when applying a 2px border to a 1px field on focus?
My pen
Relevant piece:
#contact input[type="text"],
#contact input[type="email"],
#contact input[type="tel"],
#contact input[type="url"],
#contact textarea {
border: 1px solid #ccc;
}
#contact input:focus,
#contact textarea:focus {
border-color: tomato;
border-width: 2px; /* Flowbite form fields seem to have a 1px border */
outline: 2px solid transparent;
outline-offset: 2px;
}
Share
Improve this question
asked Jan 7 at 21:27
ideassideass
311 silver badge5 bronze badges
2
- this should help: bekk.christmas/post/2023/05/with-box-shadow-instead-of-border – Armen Commented Jan 7 at 21:36
- 2 Thank you. I received the correct answer in Staging Ground and I'm waiting for the user to post it so I can accept it. A 1px "box-shadow" did it. – ideass Commented Jan 7 at 21:44
1 Answer
Reset to default 0The correct answer was commented in Staging Ground by user @vincentdecaux:
"On Flowbite, they use a box shadow to make the "border" thicker. Keep a border-width at 1px, and add the CSS to your input:focus to have the same effect: box-shadow: tomato 0px 0px 0px 0px, tomato 0px 0px 0px 1px, rgba(0, 0, 0, 0) 0px 0px 0px 0px;
"
本文标签: cssLayout shift when applying a 2px border to a 1px field on focusStack Overflow
版权声明:本文标题:css - Layout shift when applying a 2px border to a 1px field on focus - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736773895a1952234.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论