Scaling SVG with height/width/viewBox?
See original GitHub issueI’m trying to scale my SVG, which has viewBox='0 0 24 23'
, down to 16 x 16
. However, when I change the width/height
properties, the icon does not scale down, it just gets clipped off outside of the 16x16
box.
Icon with viewBox='0 0 24 23' and
width=24and
height=23`:
Icon with viewBox='0 0 24 23' and
width=16and
height=16`:
Am I missing something here? Here is my code.
import React from 'react'
import Svg, {
Path
} from 'react-native-svg'
const AlarmIcon = ({width, height, fill, stroke, viewBox, style}) => {
return (
<Svg width={width} height={height} viewBox={viewBox} style={style}>
<Path stroke={stroke} fill={fill} strokeCap='round' strokeJoin='round' d='M20.5,16.5V11A8.5,8.5,0,0,0,15,3,3,3,0,0,0,9,3,8.49,8.49,0,0,0,3.5,11v5.5a3,3,0,0,1-3,3h23A3,3,0,0,1,20.5,16.5Z'/>
<Path stroke={stroke} fill={fill} strokeCap='round' strokeJoin='round' d='M15,19.5a3,3,0,0,1-6,0'/>
</Svg>
)
}
AlarmIcon.defaultProps = {
width: 24,
height: 23,
stroke: '#fff',
fill: '#fff',
viewBox: '0 0 24 23'
}
export default AlarmIcon
Issue Analytics
- State:
- Created 7 years ago
- Reactions:5
- Comments:9
Top Results From Across the Web
How to Scale SVG | CSS-Tricks
The SVG Scaling Toolbox. Other images scale because the browser knows the height, width, and aspect ratio of the image, and it adjusts ......
Read more >Test Scaling Of SVG Images In Fluid Layouts - CodePen
Test Scaling Of SVG Images In Fluid Layouts. Resize your browser so that the images scale down. Browsers IE9+ (desktop & mobile) do...
Read more >How can I make an svg scale with its parent container?
I first create a viewBox attribute on the SVG element and set the value to "0 0 [original svg width] [original svg height]"....
Read more >Scaling Up (and Down) SVG - GitHub Pages
Core SVG scaling options; Using CSS media queries ... LIVE DEMO: No height, width, viewBox = no scaling anywhere; LIVE DEMO: No height, ......
Read more >SVG (basic support) | Can I use... Support tables for ... - CanIUse
Refers to the SVG 1.1 spec. ... 3 IE9-11 & Edge don't properly scale SVG files. Adding height, width, viewBox, and CSS rules...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I managed to get the icon to scale properly by applying
scale={width/24}
to both of the path elements. Is there a better way to do this, though?Also, the viewbox dimensions should be the original dimensions of the shape.