zoukankan      html  css  js  c++  java
  • 网页开发中利用CSS以图换字的多中实现方法总汇

    在h1标签中,新增span标签来保存标题内容,然后将其样式设置为display:none 

    <style>
        h1 {
           64px;
          height: 64px;
          background: url();
          font: 12px/1 '微软雅黑';
        }
        span {
          display: none;
        }
      </style>
      <h1>
        <span>文字</span>
      </h1>

    负缩进  

    通过使用text-index:-9999px,这样一个比较大的负缩进,使文本移到页面以外的区域 

    <style>
        h1 {
           64px;
          height: 64px;
          background: url();
          font: 12px/1 '微软雅黑';
          text-indent:-9999px;
        }
      </style>
      <h1>文字</h1>

    负margin 

    通过使用margin-left:-2000px,使盒模型向左偏移2000px,然后将宽度设置为2064px,从而页面中只显示2064px中64px的部分。将图片的背景设置为右对齐,且不重复 

    <style>
        h1 {
           2064px;
          height: 64px;
          background: url() right no-repeat;
          font: 12px/1 '微软雅黑';
          margin-left:-2000px;
        }
      </style>
      <h1>文字</h1>

    上padding 

     因为背景是显示在padding-box区域中的,而文本是显示在content-box区域中。所以,将height设置为0,用padding-top来替代height,并设置overflow:hidden。则,可以只显示背景不显示文本

    <style>
        h1 {
           64px;
          padding-top: 64px;
          height:0;
          overflow:hidden;
          background: url();
          font: 12px/1 '微软雅黑';
        }
      </style>
      <h1>文字</h1>

     0宽高

    通过新增一个span标签来保存文本内容,并将该标签的宽高设置为0,再设置溢出隐藏即可 

    <style>
        h1 {
           64px;
          height: 64px;
          background: url();
          font: 12px/1 '微软雅黑';
        }
        span{display:block; 0;height:0;overflow:hidden;}
      </style>
      <h1><span>文字</span></h1>

    文本透明  

    设置文本的颜色为transparent,并设置font-size为1px,即减少行高的影响

    <style>
        h1 {
           64px;
          height: 64px;
          background: url();
          color:transparent;
          font-size:1px;
          }
      </style>
      <h1>文字</h1>

    伪元素  

    使用before伪元素,content设置为图片的URL,在h1元素上设置溢出隐藏 

    <style>
        h1 {
           64px;
          height: 64px;
          overflow: hidden;
          font: 12px/1 '微软雅黑';
        }
        h1:before {
          content: url();
          display: block;
        }
      </style>
      <h1>文字</h1>

    正缩进  

    设置text-indent:100%,使文本缩进到父元素宽度区域的右侧。然后配合设置white-space:nowrap和overflow:hidden,使文本不换行,并溢出隐藏。从而隐藏文本内容 

    <style>
        h1 {
           64px;
          height: 64px;
          background: url();
          text-indent: 100%;
          white-space: nowrap;
          overflow: hidden;
          font: 12px/1 '微软雅黑';
        }
      </style>
      <h1>文字</h1>

    办公资源网址导航 https://www.wode007.com

    字体大小  

     通过设置font-size:0,可以将字体大小设置为0

    1 <style>
    2     h1 {
    3        64px;
    4       height: 64px;
    5       background: url();
    6       font-size:0;
    7     }
    8   </style>
    9   <h1>文字</h1>
  • 相关阅读:
    大型网站架构
    大数据以及Hadoop相关概念介绍
    Hadoop产生背景
    hadoop知识体系
    hadoop生态系统
    大数据工具集详
    大数据工具集
    关于CoDeSys OPC ua配置的记录
    我要去做it培训讲师了
    用C#将Excel中的数据写入到DataSet中
  • 原文地址:https://www.cnblogs.com/ypppt/p/13030106.html
Copyright © 2011-2022 走看看