html - 如何以文本为背景制作新行?

标签 html css text ascii-art

引用这个问题: Is there a way to use use text as the background with CSS?

我能够让一行文本出现在另一行文本后面。 我无法弄清楚的是如何制作多行背景文本。 这是我想要使用的模式: http://nanocluster.umeche.maine.edu/scope/bgScope

所以直接插入不行,一切都在一条线上。 好的,我想,我会使用 <pre></pre>一组标签,但这使背景文本不可见。 所以我试着取出 pre标签,并放入 <br>在每条新线上。但它仍然没有。接下来我试着把

font-family: Courier;
font-size: 18px;
color:#167c11;

进入样式表,但是,背景中的文本仍然不可见。

看看我试图在文本中添加换行符作为背景的页面。 http://nanocluster.umeche.maine.edu/scope/

谁能看出我做错了什么?如何在 CSS 中获取多行文本作为背景?

最佳答案

您使用绝对定位和 z-index 来添加背景效果。

body{
    background:black;
    color:green;

}
#background{
    position:absolute;
    top:0px;
    left:0px;
    z-index:-1;
    -webkit-user-select: none; /* Chrome/Safari */        
    -moz-user-select: none; /* Firefox */
    -ms-user-select: none; /* IE10+ */
    /* Rules below not implemented in browsers yet */
    -o-user-select: none;
    user-select: none;
    cursor:default;
}
#content{
    color:red;
    font-family: Courier;
}

规则:

-webkit-user-select: none; /* Chrome/Safari */        
        -moz-user-select: none; /* Firefox */
        -ms-user-select: none; /* IE10+ */
        /* Rules below not implemented in browsers yet */
        -o-user-select: none;
        user-select: none;
        cursor:default;

给它一个背景效果,这样文本就不能被选中,并且光标是默认的而不是文本。 html 非常简单:

<div id="background">
<pre>

    +---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
    |         |         |         |         |         |         |         |         |         |         |
    |         |         |         |         |         |         |         |         |         |         |
    |         |         |         |         |         |         |         |         |         |         |
    |         |         |         |         |         |         |         |         |         |         |
    +---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
    |         |         |         |         |         |         |         |         |         |         |
    |         |         |         |         |         |         |         |         |         |         |
    |         |         |         |         |         |         |         |         |         |         |
    |         |         |         |         |         |         |         |         |         |         |
    +---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
    |         |         |         |         |         |         |         |         |         |         |
    |         |         |         |         |         |         |         |         |         |         |
    |         |         |         |         |         |         |         |         |         |         |
    |         |         |         |         |         |         |         |         |         |         |
    +---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
    |         |         |         |         |         |         |         |         |         |         |
    |         |         |         |         |         |         |         |         |         |         |
    |         |         |         |         |         |         |         |         |         |         |
    |         |         |         |         |         |         |         |         |         |         |
    +---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
    |         |         |         |         |         |         |         |         |         |         |
    |         |         |         |         |         |         |         |         |         |         |
    |         |         |         |         |         |         |         |         |         |         |
    |         |         |         |         |         |         |         |         |         |         |
    +---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
    |         |         |         |         |         |         |         |         |         |         |
    |         |         |         |         |         |         |         |         |         |         |
    |         |         |         |         |         |         |         |         |         |         |
    |         |         |         |         |         |         |         |         |         |         |
    +---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
    |         |         |         |         |         |         |         |         |         |         |
    |         |         |         |         |         |         |         |         |         |         |
    |         |         |         |         |         |         |         |         |         |         |
    |         |         |         |         |         |         |         |         |         |         |
    +---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
    |         |         |         |         |         |         |         |         |         |         |
    |         |         |         |         |         |         |         |         |         |         |
    |         |         |         |         |         |         |         |         |         |         |
    |         |         |         |         |         |         |         |         |         |         |
    +---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
    |         |         |         |         |         |         |         |         |         |         |
    |         |         |         |         |         |         |         |         |         |         |
    |         |         |         |         |         |         |         |         |         |         |
    |         |         |         |         |         |         |         |         |         |         |
    +---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
_____________________________________________________________________________________________________
t1:288 ms  t2:480 ms    Display Mode: Normal: Peak Detect    Vectors: OFF       Grid = FULL


</pre>
        </div>
        <div id="content">
            I am content and I am above the grid!
        </div>

Check out this Demo

关于html - 如何以文本为背景制作新行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24782268/

相关文章:

iphone - 如何编写类似于 iPhone UI 的 HTML?

javascript - 如何分层 2 svg 图像

javascript - 在 ngRepeat 生成的每个表格行下方添加表格行

javascript - 使用 javascript 启动 SVG 动画 "onload"

html - 在 CSS 中阻止滚动不起作用

html - 如何使导航中的最后一个元素显示为链接

html - 如何制作自由形式的图像,导航栏的背景?

javascript - 有没有办法检测我是否将鼠标悬停在文本上?

Css 仅条纹文本阴影效果

java - 如何避免使用 textWatcher 更改 editText?