我正在尝试使用背景颜色创建一个围绕文本的h1样式.
h1.skew { padding-left: 10px; text-decoration: none; color: white; font-weight: bold; display: inline-block; border-right: 50px solid transparent; border-top: 50px solid #4c4c4c; height: 0; line-height: 50px; }
<h1 class="skew">HELLO WORLD
https://jsfiddle.net/zo32q98n/
最佳答案
由于边框高度为50px,因此您可以在内部插入相同数量的负边距:
h1.skew::before { content: ''; display: block; margin-top: -50px; }
body { background: #ddd; } h1.skew { padding-left: 10px; text-decoration: none; color: white; font-weight: bold; display: inline-block; border-right: 50px solid transparent; border-top: 50px solid #4c4c4c; height: 0; line-height: 50px; } h1.skew::before { content: ''; display: block; margin-top: -50px; }
<h1 class="skew">HELLO WORLD原文链接:https://www.f2er.com/html/426934.html