Scale inline SVG symbol referenced with

前端 未结 1 1903
逝去的感伤
逝去的感伤 2021-01-04 08:34

I have an SVG logo defined as a symbol like so:


    
           


        
相关标签:
1条回答
  • 2021-01-04 08:45

    Unfortunately it is the dimensions of the <svg> element that appears in your <header> that is important. There is no way to inherit a viewBox from a child symbol reference.

    You would need to copy the viewBox (width and height) from the symbol.

    .Header-logo {
        height: 5rem;
    }
    
    .Header-logo2 {
        height: 8rem;
    }
    <svg class="SpriteSheet" width="0" height="0">
        <symbol id="icon-logo" viewBox="-12 -79.61 407.19 108.36">
            <path id="logo-upperLeft" d="M0-67.61l83.66 0 0-10 -93.66 0 0 30.92 10 0Z" transform="translate(-2 -2)"></path>
            <path id="logo-upperRight" d="M383.19-67.61l-83.66 0 0-10 93.66 0 0 30.92 -10 0Z" transform="translate(2 -2)"></path>
            <path id="logo-lowerLeft" d="M0 16.75l83.66 0 0 10 -93.66 0 0-30.92 10 0Z" transform="translate(-2 2)"></path>
            <path id="logo-lowerRight" d="M383.19 16.75l-83.66 0 0 10 93.66 0 0-30.92 -10 0Z" transform="translate(2 2)"></path>
        </symbol>
    </svg>
    
    
    <header class="Header">
        <h1 class="Header-headline">
            <a href="/">
                <svg class="Header-logo" viewBox="0 0 407.19 108.36">
                    <use xlink:href="#icon-logo"></use>
                </svg>
            </a>
        </h1>
    </header>
    
    <header class="Header">
        <h1 class="Header-headline">
            <a href="/">
                <svg class="Header-logo2" viewBox="0 0 407.19 108.36">
                    <use xlink:href="#icon-logo"></use>
                </svg>
            </a>
        </h1>
    </header>

    0 讨论(0)
提交回复
热议问题