Tips for adjusting the dimensions of an SVG background within an element using the gulp-svg-sprite npm package

My current project involves the use of an NPM package called gulp-svg-sprite, which consolidates all my SVG images into a single file named sprites.svg and also generates sprites.css.

Within the sprites.css file, there are CSS classes that define their background-image property as the SVG image located inside sprite.svg.

sprites.css:

.icon:before {
    content: ' ';
    vertical-align: middle;
    display: inline-block;
    background-image: url(/img/sprite.svg);
    background-repeat: no-repeat;
    background-size: 71.7em 114.4em;
}
.icon.icon-logo:before {
    background-position: 0em -98.5em;
    width: 42.4em;
    height: 8.6em;
}

Now, when displaying a specific SVG image in the index.html:

<span class="icon icon-logo"></span>

Issue: the SVG background image appears to be too large

Efforts to fix the problem have involved attempting to resize it with little success:

index.html:

<style>
  .icon-logo:before {
     width: 130px;
     height: auto;
  }
</style>

Answer №1

In order to adjust the size and position of your sprites that utilize em units, it is recommended to modify the font-size property rather than width and height, like so:

.icon-logo:before {
     font-size:.8em;
  }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

When incorporating CSS with Bootstrap, it may not always have a visible impact on the

As a newcomer to using Bootstrap, I recently created a webpage with Bootstrap3. However, I encountered an issue when trying to apply two classes to the same element, as the CSS was not being applied: Here is the HTML code snippet: <div class="col-md-4 ...

JavaScript Switch Open/Close Mobile Navigation Menu

I'm currently facing a challenge with a specific issue. I want to implement a toggle menu for mobile devices on a website that I'm developing. It's functioning smoothly, and you can see it in action on this CodePen. The JavaScript code for ...

The Form button in my PHP email code is failing to produce any output when submitted

I attempted to create a contact form using a combination of HTML and PHP. Everything was functioning as expected during testing with the code input type="submit" name="submit" value="Submit" However, when I switched to using div and button with the class ...

Can you provide a guide on how to retrieve an HTML file using JSON?

There is a problem with fetching files in different formats. Specifically, I want to retrieve an HTML file that needs to be embedded in an iFrame. Currently, my AJAX request only retrieves SWF files. Is there a way to call and fetch the HTML file instead ...

How can I prevent users from clicking the same link multiple times in HTML?

Is it possible to disable the href after one click using javascript or jquery? I need some assistance with this. Please help. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xml ...

Is it necessary to treat headings within figure elements as document headings?

Imagine a scenario where we are working with a page structured like this: <!DOCTYPE HTML><HTML><BODY> <ARTICLE> <H1>Heading Example</H1> <P>Here is what a heading (level 2) looks like:</P> <FIG ...

Setting an Angular Directive on a dynamically generated DOM element using Javascript

One of my directives enables the drag-and-drop functionality for DOM elements with the following JavaScript: JS: angular.module('animationApp').directive('myDraggable', ['$document', function($document){return{link: function ...

Gulp encountered an issue - Module 'sigmund' not found

After installing browser-sync, my previously working Gulp encountered an error: Error: Cannot find module 'lru-cache' To resolve this issue, I utilized the following solution: npm link lru-cache as suggested in this thread However, upon atte ...

The Cordova advanced HTTP POST request functionality is not functioning as expected

I'm currently in the process of connecting my backend to a cordova application, and at this early stage of development, I'm attempting to test it in the browser. Unfortunately, I'm facing an issue with the post request not working, as well a ...

Which target should be specified for pressing Enter in a Javascript Alert using Selenium IDE?

Seeking assistance with creating simple test cases using Selenium IDE. Encountering difficulties when recording test cases involving Javascript alerts, as Selenium does not support these pop-ups. Attempted a workaround by simulating the Enter key press wh ...

Top method for embedding SVGs within Angular Universal

We are working on an innovative Angular 16 Universal project and are exploring optimal methods for utilizing SVG icons while prioritizing performance. Our web app requires multicolor icons which makes traditional font solutions like Icomoon impractical for ...

Can you provide me with the validation expression for the email format in ASP.NET?

Currently, I am working on validating a text field where users need to enter an email address following a specific format: [email protected] Here are the rules for the email validation: 1) The email address must end with .com. No numbers are allowed ...

Transforming segments into divisions

I recently designed a website using sections instead of divs in order to achieve the desired alignment of the divs within the same container. However, I am facing difficulties and confusion in implementing this approach. Currently, my divs collapse on top ...

Avoid placing content before a link to ensure better focus

I came across some CSS code that closely resembles the following code. (I copied it from http://jsfiddle.net/LmvgM/8/ thanks @thirtydot). I noticed that when the link is focused, the :before content is included. Is there a way to remove it from the highli ...

Enhancing Child Elements with CSS - Evaluating Rating Systems

Is there a way to change the opacity of certain images inside my div when hovering over them? Specifically, I want the 4th image and the first three to have an opacity value of 1. I've looked into using nth-child but am unsure how to implement it for ...

Setting a default value within an input tag: A step-by-step guide

const [userData, setUserData] = useState([]); const handleUserInfo = (id) => { fetch(`https://602e7c2c4410730017c50b9d.mockapi.io/users/${id}`) .then(res => res.json()) .then(data => setUserData(data)) } <inpu ...

Optimizing Rendering Performance: Comparing the Impact of Multiple Stylesheets vs. Single Dynamic CSS on Dynamic CSS

Currently, I am in the process of developing a website that supports "plugins" as external "displays". These plugins consist of custom full-screen HTML content managed by a client-provided JavaScript driver. The website engine utilizes an API to allow thes ...

Selecting one, multiple, or all checkboxes and attempting to proceed by activating the button will not function as intended

The functionality of the "check all" / "uncheck all" button allows me to easily select or deselect all checkboxes within my form. The "proceed..." button should become active once one, multiple, or all checkboxes are checked. While this feature works smoo ...

Alignment problem detected in Firefox and Safari, but works perfectly in Chrome

Currently dealing with a CSS problem on my website that is only appearing in Safari and Firefox, while Chrome displays it correctly. The images are not positioning correctly and are stacking instead of being placed in each box as intended. I've expe ...

inadequate document object module problem

Upon loading a page, I perform some JQuery actions on it. However, when trying to execute the line: var div = $("<div class='modal'>").append(r); I encountered an error mentioning a Hierarchy issue. It made me question if there is imprope ...