How to create a sprite from a folder with and without background-size (using Compass)
That does it. It iterates over the whole map:
@each $sprite in sprite_names($logo-sprites) {
.logo-#{$sprite} {
@include resize-sprite($logo-sprites, $sprite, 40);
}
}
This helped: Way to iterate over sprites in a map
It's great to scale down sprites in modern Browsers without loading another generated sprite-image. If the logos sometimes are 50px, but should also be 20px somewhere else, this is perfectly fine.
Compass sprites: applying individual styles to every sprite class without writing out each sprite name manually
You can retrieve the list of names with the function sprite-names($map)
, like that:
@each $item in sprite-names($sprites-sprites)
...
Compass creates the sprite map $<map>-sprites
after importing images (@import "<map>/*.png"
).
Compass sprite - avoid using extends when including a sprite
Using Compass sprites inside media queries is not possible, at least the way it's described in the documentation.
There are a couple of workarounds:
- creating sprites manually via command line;
- using a custom mixin.
Getting image width and height from compass sprites
I found the solution. Adding $common-sprite-dimensions: true;
(link to compass sprite options docs) will put the width and height into the output.
Compass Sprite Sheet Paths with Webroot Folder
Relative assets
If you want to use relative path between images and CSS (ie background: url('../images/foo.png')
), you have to add relative_assets = true
in your configuration file:
css_dir = "public/css"
sass_dir = "application/scss"
images_dir = "public/images"
javascripts_dir = "public/js"
relative_assets = true
With this, Compass will ignore the http_path
option and will generate the access to the images relative to the location of the CSS file paths.
Absolute assets
If you want to use absolute paths to access to your images (ie background: url('/images/foo.png')
, according the configuration reference, remember that the local paths *_path
are different of the full http path http_*_path
.
So, to access to the images stored in public/images
when the webroot is public
, you have to work in two times:
- you have to tell to Compass that the images are stored locally in the
public/images
directory:images_dir = "public/images"
. - the full http path must be configured:
http_images_path = "/images"
for regular images (when you use the helperimage-url()
) andhttp_generated_images_path = "/images"
for generated sprites.
The final configuration file becomes:
css_dir = "public/css"
sass_dir = "application/scss"
images_dir = "public/images"
javascripts_dir = "public/js"
http_images_path = "/images"
http_generated_images_path = "/images"
Get reference to Compass sprite map when using @import
Say you import via @import "icons/*.png"
, the variable $icons-sprites
now contains the reference to the sprite-map
function used by Compass' @import
function.
The key is using $<folder>-sprites
to reference that sprite map.
Spriting with Compass - Should icons be of the same size?
Compass combines all of your images vertically no matter what their size into a single image. It should then calculate the height of each image and assign it as the background position offset. If your li
has a height of say 20px and the current-menu
icon has a height of 16px, you'll see some of the next image in the sprite.
You can either make all of your icons the same size or use the customization options to set things like spacing, position, and repeating. You can read more about it in the Spriting tutorial.
Related Topics
Center Wrapped Items in a Space-Between Flexbox
How to Change Font-Size of a Tag Using Inline CSS
How to Make a Div Full Screen and Scrollable
Bootstrap Collapse Accordion - Default Expand/Collapse
How to Make Tinymce's Modal Dialogs Responsive
CSS - Horizontal Navigation List Items to Fill All Available Space
Tailwind CSS + Vuejs Single File Component and Vs Code Integration
How to Use CSS3: :Selection Without Changing The Default Color and Background Color
CSS Sprite Techniques, CSS Background or Img's Clip
CSS - Smooth Button Gradient Color Transition on Hover
How to Divide Bootstrap Col-Md Div to Half Vertically
Align Flex-Box Items to Baseline of Last Text Line in a Block
How to Edit Auto-Formatting Rules for CSS/Scss/Less Using Prettier in Vscode
What Fonts Are Included (I.E. Installed by Default) with Which Operating Systems
HTML5Shiv - Why Is It Only for Ie