Utilizing a Ruby gem known as rqrcode, I am able to create a QR code in SVG format and send it as an API response. Within my frontend (Vue.js), I am faced with the task of displaying the SVG at a specific size.
Currently, my code appears as follows, rendering the SVG yet lacking the ability to specify its size:
<div v-html="qrCode" />
While attempting to add styles to the div, the SVG seems to ignore them entirely. To illustrate, here is how it currently appears:
https://i.sstatic.net/ztBtF.png
As far as I am aware, SVG scaling can be achieved with the use of width
, height
, and viewBox
within the <svg>
tag. However, rqrcode does not provide the option to specify these properties - the height and width are predetermined by the gem, resulting in the opening svg tag looking like this:
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ev="http://www.w3.org/2001/xml-events" width="246" height="246" shape-rendering="crispEdges">
Hence, my inquiry is centered around how I can indicate the size of the inline SVG to fit within its parent container, directly from the parent container?
[Edit for clarification] Should the dimensions within the <svg>
tag exceed those of my div container, I desire for the SVG to reduce in size to fit the container accordingly. Conversely, if the dimensions are smaller, I aim for the SVG to expand and fill the container. I am uncertain if this is achievable.