Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SCSS - Getting Image Dimensions

Tags:

css

sass

I am using the inline-image function to create icon classes. This is my current SCSS:

.folder {
    background: inline-image("icons/home/folder.png", 'image/png') no-repeat center;
    height: 30px;
    width: 41px;
}

I am looking for a function that can determine the width and height of the image so I can do something like this:

.folder {
    background: inline-image("icons/home/folder.png", 'image/png') no-repeat center;
    height: image-height("icons/home/folder.png", 'image/png');
    width: image-width("icons/home/folder.png", 'image/png');
}

Does anything like this exist?

like image 813
sissonb Avatar asked Mar 16 '12 03:03

sissonb


People also ask

How do I make an image fit in HTML size?

One of the simplest ways to resize an image in the HTML is using the height and width attributes on the img tag. These values specify the height and width of the image element. The values are set in px i.e. CSS pixels.


1 Answers

Found this http://compass-style.org/reference/compass/helpers/image-dimensions/

You've guessed the right function names.

To use them you'll need to install compass.

It will be something like this:

@import "compass/helpers";

.folder {
    background: inline-image("icons/home/folder.png", 'image/png') no-repeat center;
    height: image-height("icons/home/folder.png");
    width: image-width("icons/home/folder.png");
}

By the way I would recommend you to use sprites for icons: http://compass-style.org/reference/compass/helpers/sprites/

like image 138
welldan97 Avatar answered Sep 30 '22 12:09

welldan97