【问题标题】:font icon as page background with flexbox字体图标作为带有 flexbox 的页面背景
【发布时间】:2015-10-28 19:52:44
【问题描述】:

我正在尝试使用字体图标作为背景图像,并使用 flexbox 将其水平和垂直居中。我已将其设置为主体。

我希望所有其他内容都位于字体图标上方,并且我使用相同的 flex 属性来使内容居中。

我在codepen 上创建了一支笔。

------html-------------

<div class="module-card">
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptatem possimus ipsam commodi consequuntur quo dolor ad cupiditate blanditiis perferendis maiores incidunt dolores similique officiis a provident, obcaecati temporibus! Culpa, reprehenderit.</p>
</div>

-----css-------------

body{
  display: flex;
  align-items: center;
  justify-content: center;
  height:100vh;
  z-index:-1;
}

body:before {
    content: "\f113";
    font-family: FontAwesome;
/*--adjust as necessary--*/
    color: blue;
    font-size: 30em;
  text-shadow: 2px 2px #ff0000;

}

.module-card {
  width:50%;
  background: #fff;
  padding: 10px;
  display: flex;
  flex-direction: column;
  background:  rgba(0,191,255,0.2);
  z-index:9999;
}

有没有可能这样做而不是背景图片?

谢谢, 苏海尔。

【问题讨论】:

    标签: html css flexbox icon-fonts


    【解决方案1】:
    body {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      height:100vh;
      z-index:-1;
      position: relative;
    }
    
    body::after {
      content: "\f113";
      font-family: FontAwesome;
      color: blue;
      font-size: 30em;
      text-shadow: 2px 2px #ff0000;
    } 
    
    .module-card {
      width:50%;
      background: #fff;
      padding: 10px;
      display: flex;
      /* flex-direction: column; */
      background:  rgba(0,191,255,0.2);
      z-index:9999;
    
      /* center and overlay content */
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%,-50%);
    }
    

    演示:http://codepen.io/anon/pen/zvjLyV

    【讨论】:

      【解决方案2】:

      只需将您的 html/css 修改为如下所示:http://codepen.io/anon/pen/EVLpGq

      HTML:

      <div class="someother-dif">
      <div class="module-card">
        <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptatem possimus ipsam commodi consequuntur quo dolor ad cupiditate blanditiis perferendis maiores incidunt dolores similique officiis a provident, obcaecati temporibus! Culpa, reprehenderit.</p>
      </div>
      </div>
      

      CSS:

      body{
        display: flex;
        align-items: center;
        justify-content: center;
        height:100vh;
        z-index:-1;
      }
      
      
      
      /*replace the content value with the
      corresponding value from the list below*/
      
      body:after {
          content: "\f113";
          font-family: FontAwesome;
      /*--adjust as necessary--*/
          color: blue;
          font-size: 30em;
          text-shadow: 2px 2px #ff0000;
          z-index:1;
          font-family: FontAwesome;
          font-style: normal;
          font-weight: normal;
          text-decoration: inherit;
          position: absolute;
          font-size: 400px;
          top: 50%;
          left: 50%;
          margin: -300px 0 0 -200px;
          z-index: 1;
      
      }
      
      .someother-dif:after{
      
      }
      
      .module-card {
        width:50%;
        margin-left:auto;
        margin-right:auto;
        background: #fff;
        padding: 10px;
        display: flex;
        flex-direction: column;
        background:  rgba(0,191,255,0.2);
        z-index:9999;
        position:relative;
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-07-05
        • 2016-03-30
        • 2019-09-22
        • 1970-01-01
        • 2013-03-17
        • 2021-06-14
        • 2022-11-28
        • 1970-01-01
        相关资源
        最近更新 更多