我在各种HTML元素下都有几个SVG元素。正如您在下面的示例中看到的那样,它们占用了大量空间,并使html变得混乱。
我想知道是否有人对清除此问题的最佳方法有任何建议。我可以为每个SVG元素使用部分HTML视图,但这有点过头了,我能想到的一切。
<div id="canvasControl" class="cnvsControl" hidden="hidden" style="height:36px; background-color:black; position:relative;margin-top:-36px;z-index:9999;opacity: 0.2;">
<div class="imageUpload canvasControlButton alignLeft" style="height:36px; position:relative;" title="Open File" id="btnOpenFile" name="btnOpenFile" onclick="snes_readfile(this)">
<label for="btnFileImport" style="position:absolute;top:5px;">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100%" height="25" viewBox="0 0 512 512">
<g id="icomoon-ignore"></g>
<defs>
<path id="openFolder1" d="M416 480l96-256h-416l-96 256zM64 192l-64 288v-416h144l64 64h208v64z"></path>
</defs>
<use fill="#fff" xlink:href="#openFolder1"></use>
</svg>
</label>
<input id="btnFileImport" type="file" onchange="snes_readfile(this)" />
</div>
<button class="canvasControlButton alignRight" title="Full screen" id="btnFullScreen" name="btnFullScreen">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100%" height="25" viewBox="0 0 512 512">
<g id="icomoon-ignore"></g>
<defs>
<path id="outFullArrow1" d="M512 0h-208l80 80-96 96 48 48 96-96 80 80z"></path>
<path id="outFullArrow2" d="M512 512v-208l-80 80-96-96-48 48 96 96-80 80z"></path>
<path id="outFullArrow3" d="M0 512h208l-80-80 96-96-48-48-96 96-80-80z"></path>
<path id="outFullArrow4" d="M0 0v208l80-80 96 96 48-48-96-96 80-80z"></path>
</defs>
<use fill="#fff" xlink:href="#outFullArrow1"></use>
<use fill="#fff" xlink:href="#outFullArrow2"></use>
<use fill="#fff" xlink:href="#outFullArrow3"></use>
<use fill="#fff" xlink:href="#outFullArrow4"></use>
</svg>
</button>
<button class="canvasControlButton alignRight" title="Bigger Screen" id="btnChangeScreenSize" name="btnChangeScreenSize">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100%" height="25" viewBox="0 0 512 512">
<g id="icomoon-ignore"></g>
<defs>
<path id="outArrow1" d="M512 0v208l-80-80-96 96-48-48 96-96-80-80zM224 336l-96 96 80 80h-208v-208l80 80 96-96z"></path>
</defs>
<use fill="#fff" xlink:href="#outArrow1"></use>
</svg>
</button>
您可以创建一个单独的SVG文件,然后将其链接到HTML文档,如下所示:
创建名为的SVG文件
一个.svg:
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100%" height="25" viewBox="0 0 512 512">
<g id="icomoon-ignore"></g>
<defs>
<path id="openFolder1" d="M416 480l96-256h-416l-96 256zM64 192l-64 288v-416h144l64 64h208v64z"></path>
</defs>
<use fill="#fff" xlink:href="#openFolder1"></use>
</svg>
两个.svg
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100%" height="25" viewBox="0 0 512 512">
<g id="icomoon-ignore"></g>
<defs>
<path id="outFullArrow1" d="M512 0h-208l80 80-96 96 48 48 96-96 80 80z"></path>
<path id="outFullArrow2" d="M512 512v-208l-80 80-96-96-48 48 96 96-80 80z"></path>
<path id="outFullArrow3" d="M0 512h208l-80-80 96-96-48-48-96 96-80-80z"></path>
<path id="outFullArrow4" d="M0 0v208l80-80 96 96 48-48-96-96 80-80z"></path>
</defs>
<use fill="#fff" xlink:href="#outFullArrow1"></use>
<use fill="#fff" xlink:href="#outFullArrow2"></use>
<use fill="#fff" xlink:href="#outFullArrow3"></use>
<use fill="#fff" xlink:href="#outFullArrow4"></use>
</svg>
三.svg
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100%" height="25" viewBox="0 0 512 512">
<g id="icomoon-ignore"></g>
<defs>
<path id="outArrow1" d="M512 0v208l-80-80-96 96-48-48 96-96-80-80zM224 336l-96 96 80 80h-208v-208l80 80 96-96z"></path>
</defs>
<use fill="#fff" xlink:href="#outArrow1"></use>
</svg>
然后将HTML编辑为:
<div id="canvasControl" class="cnvsControl" hidden="hidden" style="height:36px; background-color:black; position:relative;margin-top:-36px;z-index:9999;opacity: 0.2;">
<div class="imageUpload canvasControlButton alignLeft" style="height:36px; position:relative;" title="Open File" id="btnOpenFile" name="btnOpenFile" onclick="snes_readfile(this)">
<label for="btnFileImport" style="position:absolute;top:5px;">
<object>
<embed scr="one.svg">
</object>
</label>
<input id="btnFileImport" type="file" onchange="snes_readfile(this)" />
</div>
<button class="canvasControlButton alignRight" title="Full screen" id="btnFullScreen" name="btnFullScreen">
<object>
<embed scr="two.svg">
</object>
</button>
<button class="canvasControlButton alignRight" title="Bigger Screen" id="btnChangeScreenSize" name="btnChangeScreenSize">
<object>
<embed scr="three.svg">
</object>
</button>
希望它能有所帮助,并且如果解决了您的问题,请不要忘记验证答案。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句