Font scaling based on width of container

后端 未结 30 3732
面向向阳花
面向向阳花 2020-11-21 04:35

I\'m having a hard time getting my head around font scaling.

I currently have a website with a body font-size of 100%. 100% of what though? This seems t

30条回答
  •  长情又很酷
    2020-11-21 05:06

    There is a way to do this without JavaScript!

    You can use an inline SVG image. You can use CSS on an SVG if it is inline. You have to remember that using this method means your SVG image will respond to its container size.

    Try using the following solution...

    HTML

    SAVE $500

    CSS

    div {
      width: 50%; /* Set your container width */
      height: 50%; /* Set your container height */
    
    }
    
    svg {
      width: 100%;
      height: auto;
    
    }
    
    text {
      transform: translate(40px, 202px);
      font-size: 62px;
      fill: #000;
    }
    

    Example: https://jsfiddle.net/k8L4xLLa/32/

    Want something more flashy?

    SVG images also allow you to do cool stuff with shapes and junk. Check out this great use case for scalable text...

    https://jsfiddle.net/k8L4xLLa/14/

提交回复
热议问题