英文:
In CSS, how can I fill the empty space of each line wrapped from a paragraph with dashes?
问题
I want to fill the empty space with dashes, but not on the last line only, I want to fill each line since I am not using justify for my text-align.
英文:
I've been trying to figure this out and can't find the answer. What I want to do is fill the empty space with dashes, but not on the last line only, I want to fill each line since I am not using justify for my text-align.
答案1
得分: 2
如果不需要透明度,您可以使用渐变效果:
p {
font-size: 30px;
font-family: sans-serif;
margin: 20px;
/* 调整20px和80%以控制虚线 */
background: conic-gradient(at 80% 2px,#0000 75%,#000 0) 100% .5lh/20px 1lh;
/* 如果lh单位不起作用,请使用以下行 */
/* line-height: 1.2em;
background: conic-gradient(at 80% 2px,#0000 75%,#000 0) 100% .6em/20px 1.2em; */
}
p span {
background: #fff;
padding-right: 10px;
-webkit-box-decoration-break: clone;
}
<p>
<span>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. At quod est quis modi, ab necessitatibus, ipsa alias cum consectetur, dolorum mollitia omnis cupiditate laboriosam debitis nisi? Laboriosam impedit voluptatibus minima. Lorem ipsum dolor sit amet, consectetur adipisicing elit. At quod est quis modi, ab necessitatibus, ipsa alias cum consectetur, dolorum mollitia omnis cupiditate laboriosam debitis nisi? Laboriosam impedit voluptatibus minima.
</span>
</p>
希望这有所帮助!
英文:
If transparency is not need you can play with gradients:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
p {
font-size: 30px;
font-family: sans-serif;
margin: 20px;
/* adjust the 20px and the 80% to control the dash */
background: conic-gradient(at 80% 2px,#0000 75%,#000 0) 100% .5lh/20px 1lh;
/* lh is a new unit if it doesn't work use the below
line-height: 1.2em;
background: conic-gradient(at 80% 2px,#0000 75%,#000 0) 100% .6em/20px 1.2em;
*/
}
p span {
background: #fff;
padding-right: 10px;
-webkit-box-decoration-break: clone
}
<!-- language: lang-html -->
<p>
<span>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. At quod est quis modi, ab necessitatibus, ipsa alias cum consectetur, dolorum mollitia omnis cupiditate laboriosam debitis nisi? Laboriosam impedit voluptatibus minima. Lorem ipsum dolor sit amet, consectetur adipisicing elit. At quod est quis modi, ab necessitatibus, ipsa alias cum consectetur, dolorum mollitia omnis cupiditate laboriosam debitis nisi? Laboriosam impedit voluptatibus minima.
</span>
</p>
<!-- end snippet -->
答案2
得分: 0
以下是翻译好的内容:
-
计算(或设置)每行的字符数和总行数。
-
用短线填充一个容器,并将其放在原始文本后面。
-
将原始文本放在带有白色背景的 span 中,只在行末显示短线。
很快的说明,随时可以改进:
<!-- 开始代码片段:js 隐藏:false 控制台:true Babel:false -->
<!-- 语言:lang-js -->
const lineHeight = 16;
const maxLength = 30;
const height = document.querySelector(".wrapper").scrollHeight;
const fillup = document.querySelector(".fillup");
fillup.innerHTML = "-".repeat(height / lineHeight * maxLength);
<!-- 语言:lang-css -->
.wrapper {
position: relative;
font-family: Courier;
max-width: 30ch;
line-height: 16px;
}
span {
background: white;
}
.fillup {
position: absolute;
top: 0;
right: 0;
z-index: -1;
max-height: 100%;
overflow: hidden;
}
<!-- 语言:lang-html -->
<div class="wrapper">
<span>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</span>
<div class="fillup"></div>
</div>
<!-- 结束代码片段 -->
(注意:上述代码片段中的 HTML、CSS 和 JavaScript 部分未被翻译,仅提供原文)
英文:
This will get you started working on this:
-
Calculate (or set) the number of characters per line and the number of total lines.
-
Fill up a container with dashes and place it behind the original text.
-
Put the original text in a span with white background to only show the dashes at the end of the line
Very quick write-up, feel free to improve:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
const lineHeight = 16;
const maxLength = 30;
const height = document.querySelector(".wrapper").scrollHeight
const fillup = document.querySelector(".fillup");
fillup.innerHTML = "-".repeat(height / lineHeight * maxLength);
<!-- language: lang-css -->
.wrapper {
position: relative;
font-family: Courier;
max-width: 30ch;
line-height: 16px;
}
span {
background: white;
}
.fillup {
position: absolute;
top: 0;
right: 0;
z-index: -1;
max-height: 100%;
overflow: hidden;
}
<!-- language: lang-html -->
<div class="wrapper">
<span>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</span>
<div class="fillup"></div>
</div>
<!-- end snippet -->
答案3
得分: 0
以下是您要翻译的内容:
<article>
<p>
<span>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. At quod est quis modi, ab necessitatibus, ipsa alias cum consectetur, dolorum mollitia omnis cupiditate laboriosam debitis nisi? Laboriosam impedit voluptatibus minima. Lorem ipsum dolor sit amet, consectetur adipisicing elit. At quod est quis modi, ab necessitatibus, ipsa alias cum consectetur, dolorum mollitia omnis cupiditate laboriosam debitis nisi? Laboriosam impedit voluptatibus minima.
</span>
</p>
<div>
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
</div>
</article>
CSS:
body {
font-family: monospace;
}
article {
width: 400px;
position: relative;
overflow: hidden;
}
p {
position: relative;
z-index: 2;
margin: 0;
}
span {
background-color: white;
}
div {
position:absolute;
z-index: 1;
top: 0; bottom: 0; left: 0; right: 0;
text-align: justify;
}
英文:
You could do something like this:
<article>
<p>
<span>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. At quod est quis modi, ab necessitatibus, ipsa alias cum consectetur, dolorum mollitia omnis cupiditate laboriosam debitis nisi? Laboriosam impedit voluptatibus minima. Lorem ipsum dolor sit amet, consectetur adipisicing elit. At quod est quis modi, ab necessitatibus, ipsa alias cum consectetur, dolorum mollitia omnis cupiditate laboriosam debitis nisi? Laboriosam impedit voluptatibus minima.
</span>
</p>
<div>
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
</div>
</article>
CSS:
body {
font-family: monospace;
}
article {
width: 400px;
position: relative;
overflow: hidden;
}
p {
position: relative;
z-index: 2;
margin: 0;
}
span {
background-color: white;
}
div {
position:absolute;
z-index: 1;
top: 0; bottom: 0; left: 0; right: 0;
text-align: justify;
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论