Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Draw a line that doesn't get thicker when image stretches

Tags:

Is there a way in SVG to draw a line that keeps thin when the image is stretched?

I'm using a SVG image as a CSS background, something like this:

<svg ... preserveAspectRatio="none" viewBox="0 0 15 15">
  <line x1="0" y1="15" x2="15" y2="0"
        color="#000" stroke="#333" stroke-width="1" />
</svg> 

(A diagonal line). I'm stretching this image through a rectangular element, and when the element is bigger, the line gets thicker, but I need an always-thin line.

Possible? Something like "thin" lines in flash.

like image 420
ezakto Avatar asked Apr 15 '12 07:04

ezakto


People also ask

How do I make my background image not stretch in CSS?

How to fit image without stretching and maintain aspect ratio? Answer: If you want to use the image as a CSS background, there is an elegant solution. Simply use cover or contain in the background-size CSS3 property. contain will give you a scaled-down image.

How do I stretch an image in CSS?

You can use the CSS background-size: cover; to stretch and scale an image in the background with CSS only. This scales the image as large as possible in such a way that the background area is completely covered by the background image, while preserving its intrinsic aspect ratio.

How do I make the background image fit my screen size?

Using CSS, you can set the background-size property for the image to fit the screen (viewport). The background-size property has a value of cover . It instructs browsers to automatically scale the width and height of a responsive background image to be the same or bigger than the viewport.


1 Answers

In browsers that implement SVG 1.2T you can have a non-scaling stroke Opera and Webkit support this as does Firefox from version 15.

<!-- via property -->
<line … vector-effect="non-scaling-stroke" />

<!-- via CSS -->
<style>
  line { vector-effect:non-scaling-stroke }
</style>
<line … />
like image 101
Robert Longson Avatar answered Nov 07 '22 02:11

Robert Longson