Front-end import font files

Front-end import font files

insert image description here
The font used above is Founder Big Standard Song.
First we need to have this font file.
My current directory structure is:
insert image description here
All code is:

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<style>
  /* 方正大标宋 */
  @font-face {
    
    
    font-family: '方正大标宋';
    src: url(FZDBSJW.TTF);
  }

  * {
    
    
    padding: 0;
    margin: 0;
  }

  .div {
    
    
    margin-left: 100px;
    margin-top: 100px;
    padding: 5px;
    background-image: url('./zjq.png');
    width: 210px;
    height: 210px;
    background-repeat: no-repeat;
    background-size: 100%;
    color: red;
    display: flex;
    flex-wrap: wrap;
  }

  .box {
    
    
    font-size: 200px;
    line-height: 200px;
    height: 210px;
    width: 210px;
    text-align: center;
    position: relative;
    /* top: -10px; */
    bottom: -10px;
    left: -6px;
    font-weight: bold;
    font-family: "方正大标宋";
  }

  #zjq,
  body,
  html {
    
    
    width: 100%;
    height: 100%;
  }

  #zjq {
    
    
    display: flex;
  }
</style>

<body>
  <div id="zjq">
  </div>
</body>
<script>
  let zjq = document.getElementById('zjq')
  const str = `高考加油`;
  let arr = str.split('')
  let strObj = ''
  arr.map(i => {
    
    
    strObj += `<div class="div">
      <div class="box">
        ${
      
      i}
      </div>
    </div>`
  })
  zjq.innerHTML = strObj
</script>

</html>

Let's look at the normal font again:
insert image description here
In fact, it is mainly these lines:

 /* 方正大标宋 */
  @font-face {
    
    
    font-family: '方正大标宋';
    src: url(FZDBSJW.TTF);
  }
  //使用
 font-family: "方正大标宋";

OK, that's it.

Guess you like

Origin blog.csdn.net/qq_43291759/article/details/131089910