Anyone know what or how to implement display:block; on SVG elements like <svg> and <a>? I ask this because once you start working inside the <svg> parent all the children work as if they are set to absolute positioning and refuse to interact with each other. Is my only option to use transform? The same issue applies to width and height on <a>.
<svg> I believe is a HTML element, so any CSS rules to be applied to it should work. Have a link to related webpage?
No, working on this on my desktop and from what I understand of the W3C documentation certain properties like display:block; do not work on child elements within <svg>. I am trying to figure out how to extract the width and height from a <polygon>.
Hi there everlive, may we see your svg code? It would give members a chance to assess your problem(s). coothead
Hi there everlive, in my test the "console.log" returns a value of "auto" for the "polygon". Here is my test code... <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>untitled document</title> <link rel="stylesheet" href="screen.css" media="screen"> <style media="screen"> svg { display:block; width:20%; margin:auto; } </style> </head> <body> <svg class="polu" preserveAspectRatio="xMidYMid meet" viewBox="0 0 100 100"> <a class="polu2" xlink:href="deviantart.com" > <polygon class="polu3" fill="red" stroke="brown" points="45,2 2,45 45,88 88,45"/> </a> </svg> <script> (function() { 'use strict'; var el=document.getElementsByClassName('polu')[0]; var el3=document.getElementsByClassName('polu3')[0]; var svgWidth=window.getComputedStyle(el).getPropertyValue('width'); var polyWidth=window.getComputedStyle(el3).getPropertyValue('width'); console.log(svgWidth+' svg width \n'+polyWidth+' polygon width'); })(); </script> </body> </html> Code (markup): coothead
May I ask why you need to get the width and height? As far as I can see, the a-element inside the SVG is "block" in that it covers the entire svg-element - which I assume would be the normal behavior - what is it you want to do? Perhaps there is another way?