简体   繁体   English

如何在两端的Background repeat-x设置上使用CSS作为“Left Slanted Stripe”

[英]How to using CSS for "Left Slanted Stripe" on Background repeat-x setting for both ends

I am trying to making Left Slanted Stripe with CSS.我正在尝试使用 CSS 制作左斜条纹。

I don't know how to make both ends not to show clearly like below image that I attached.我不知道如何使两端不像我附上的下图那样清楚地显示出来。

ideas for Left Slanted Stripe左斜条纹的想法

Can I repeat as Counting Numbers of Image with CSS?我可以重复使用 CSS 计算图像数量吗?

Can I get some help?我能得到一些帮助吗?

 .stripe { width: 100%; height: 2em; background: slategray; background-image: url(https://i.stack.imgur.com/qVP44.png), url(https://i.stack.imgur.com/ogF3W.png); background-size: 1em, 1em; background-position: left bottom, 0.5em bottom; background-repeat: repeat-x, repeat-x; }
 <div class="stripe"></div>

stripe unit green条纹单元绿色

stripe unit orange条纹单元橙色

when adapted to paragraph with span当适应具有跨度的段落时

Adapting A Haworth Answer to ...将海沃氏答案改编为...

It isn't work.. Don't know why the reason...它不起作用..不知道为什么...

 .stripe, .stripe::before, .stripe::after { margin: 0; } .stripe { width: 100%; height: 2em; position: relative; margin: 0; nt-size: 50px; } .stripe::before, .stripe::after { content: ''; position: absolute; bottom: 0; left: 0; width: 100%; z-index: -1; } .stripe::after { height: .72em; /* depends on the slope */ background-image: url(https://i.stack.imgur.com/qVP44.png), url(https://i.stack.imgur.com/ogF3W.png); background-size: 1em, 1em; background-position: left bottom, 0.5em bottom; background-repeat: repeat-x, repeat-x; clip-path: polygon(.72em 0, 100% 0, calc(100% - .72em) 100%, 0 100%); } .stripe::before { background-color: slategray; height: 100%; }
 <h2>in span</h2> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla ac tellus nunc. Phasellus imperdiet leo metus, et gravida lacus. Donec metus ligula, elementum at pellentesque pellentesque, suscipit ac nunc. Etiam lobortis, massa ac aliquam auctor, augue nisl sagittis urna, at dapibus tellus erat ullamcorper ligula. Praesent orci dui, pulvinar id convallis a, faucibus non mauris. Donec tellus augue, tempus sed facilisis sed, fringilla quis leo. Mauris vulputate, leo ac facilisis vulputate, enim orci interdum augue, in blandit quam turpis quis dui. <span class="stripe">Morbi dictum luctus velit nec faucibus. Cras vitae tortor purus, ut tincidunt mauris.</span> Sed at velit nisl. Donec eu mauris tortor, interdum condimentum erat. Nam egestas turpis eget nibh laoreet pharetra. Suspendisse a sem eros, ut pulvinar enim. In sed elit eu nulla accumsan tincidunt eget sit amet ipsum. Nullam ut massa rutrum dolor placerat tempor accumsan eget purus.</p> <h2>in div</h2> <div class="stripe">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla ac tellus nunc. Phasellus imperdiet leo metus, et gravida lacus. Donec metus ligula, elementum at pellentesque pellentesque, suscipit ac nunc. Etiam lobortis, massa ac aliquam auctor, augue nisl sagittis urna, at dapibus tellus erat ullamcorper ligula. Praesent orci dui, pulvinar id convallis a, faucibus non mauris. Donec tellus augue, tempus sed facilisis sed, fringilla quis leo. Mauris vulputate, leo ac facilisis vulputate, enim orci interdum augue, in blandit quam turpis quis dui. <span class="stripe">Morbi dictum luctus velit nec faucibus. Cras vitae tortor purus, ut tincidunt mauris.</span> Sed at velit nisl. Donec eu mauris tortor, interdum condimentum erat. Nam egestas turpis eget nibh laoreet pharetra. Suspendisse a sem eros, ut pulvinar enim. In sed elit eu nulla accumsan tincidunt eget sit amet ipsum. Nullam ut massa rutrum dolor placerat tempor accumsan eget purus.</div>

You can put the stripey background and the gray background onto after and before pseudo elements, and clip the stripey one so that the odd bits of stripe at the two ends are removed.您可以将条纹背景和灰色背景放在伪元素之前和之前,然后将条纹剪掉,以便去除两端的奇数位条纹。

Note: the widths here are based on the slope/relative size of the stripey images.注意:此处的宽度基于条纹图像的斜率/相对大小。 Things will scale OK if for example the font-size is changed (in fact, if you put the font-size to something big in .stripe you can check that the clipping is working better).例如,如果更改了字体大小,事情将正常缩放(事实上,如果您将字体大小设置为 .stripe 中的较大值,您可以检查剪辑是否工作得更好)。

 .stripe, .stripe::before, .stripe::after { margin: 0; } .stripe { width: 100%; height: 20em; position: relative; margin: 0; nt-size: 50px; } .stripe::before, .stripe::after { content: ''; position: absolute; bottom: 0; left: 0; width: 100%; z-index: -1; } .stripe::after { height: .72em; /* depends on the slope */ background-image: url(https://i.stack.imgur.com/qVP44.png), url(https://i.stack.imgur.com/ogF3W.png); background-size: 1em, 1em; background-position: left bottom, 0.5em bottom; background-repeat: repeat-x, repeat-x; clip-path: polygon(.72em 0, 100% 0, calc(100% - .72em) 100%, 0 100%); } .stripe::before { background-color: slategray; height: 100%; }
 <div class="stripe"></div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM