html - 在 html 页面上使用文本而不是图像作为背景

标签 html css

我正在尝试使用文本作为网站的背景图片 - 如果文本自动重排就没问题,但我试图不滚动页面 - 所以在我身上我有溢出:隐藏,效果很好,除非我的内容 div 变得太长,此时它也被隐藏了。

有没有办法让“背景”层溢出:隐藏,同时让我的内容在必要时流动? (我已经尝试过明显的溢出:隐藏在#background 上)

<body>
<div id="content">
  All my content
</div>
<div id="background">
<p>'I told some of yo... lots of text</p>
</div>
</body>

是目前的基本页面格式,css是:

body {overflow:hidden;}

#background {
    position:absolute;
    top:-20px;
    right:-20px;
    bottom:-20px;
    left:-20px;
    overflow:hidden;
    z-index:-1;}

#content {
    width:840px;
    text-align:left;
    margin-top:30px;
    margin-left:auto;
    margin-right:auto;
    height:auto;
    overflow:visible;}

最佳答案

固定 #background 位置并设置 overflow:hidden 到它,而不是正文。

body {}

#background {
    position:fixed;
    top:0;
    left:0;
    width:95%; 
    height:95%;
    overflow:hidden;
    z-index:-1;
}

示例:http://jsfiddle.net/AlienWebguy/Av6YW/

关于html - 在 html 页面上使用文本而不是图像作为背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7046193/

相关文章:

html - img 标签和 div 彼此相邻

html - 当 flexbox 元素以列模式包装时,容器不会增加其宽度

php - 本地主机中的 XAMPP 延迟

javascript - 计算 <ul> 中特定 <li> 左侧和右侧 <li> 的数量

html - 使 Bootstrap 切换菜单的 CSS 过渡平滑

javascript - 如何将 HTML Web 组件与 HTML 文件结合起来?内部 HTML = foo ("myfile.html")

jquery - 悬停在 agendaWeek + fullcalendar 的一个单元格上的效果

html - 现在是否已弃用小程序?

javascript - Fabric.js 基于svg的多重裁剪

css - 流体图像 - 纵向/横向