How can I eliminate the gaps in the exterior of Google's Material Design Icons?

Query: I've encountered difficulty in removing the whitespace around Google's Material Design icons, despite searching for solutions on Google and the Material Design icons guide. It's unclear whether the solution is simple and I'm overlooking it, or if there's a more complex reason for this seemingly straightforward task.

Below are excerpts from the relevant code in my project, or you can view the full project here.

  • My HTML markup:

    <header class="primary-header first-header-column">
      <i class="material-icons primary-header-material-icon-first-menu">
        menu
      </i>
      <h1>
        <strong>
          Neocrypt
        </strong> 
        Network
      </h1>
      <nav class="primary-header-navigation">
    
      </nav>
    </header>
    
  • Icon styling:

    .material-icons.primary-header-material-icon-first-menu {
      color: var(--primary-typeface-color);
      font-size: 48px;
    }
    
  • Heading styling:

    .primary-header h1 {
      text-align: center;
      color: var(--primary-typeface-color);
      display: inline;
      font-family: var(--primary-typeface);
      font-size: 60px;
      line-height: 150px;
    }
    
  • Referenced variables:

    :root {
      --primary-typeface-color: #ffffff;
      --primary-typeface: 'Lato', sans-serif;
    }
    

I'm aiming to have the icon sit directly beside the heading without any padding so I can adjust the spacing myself, like a reset. Despite attempting padding: 0px; and other solutions, the issue persists.

Note: I'm implementing Eric Meyer's "Reset CSS," which, as far as I know, shouldn't impact Google's Material Design icons.


Update (24/03/2018 01:33 UTC): It appears that Google adds the spacing around the icon within the image file itself, limiting users' control over that spacing. For those facing a similar challenge, I suggest exploring alternative icon fonts like Font Awesome.

Answer №1

My approach was to enclose the icon within a span element and define fixed dimensions for it by setting a specific height and width. Then, I simply concealed the overflowing content.

This is the result displayed in my web browser. https://i.sstatic.net/3qkbb.png

Here's an illustration of how to eliminate the whitespace around the icon.

.print-element {
  min-width: 175px;
  min-height: 45px;
  border: solid 1px #ccc;
  color: rgba(0, 0, 0, 0.87);
  display: inline-flex;
  justify-content: center;
  align-items: center;
  text-align: center;
  background: #fff;
  border-radius: 4px;
  margin-right: 25px 25px 15px 0px;
  cursor: move;
  position: relative;
  z-index: 1;
  box-sizing: border-box;
  padding: 10px 50px 10px 10px;
  transition: box-shadow 200ms cubic-bezier(0, 0, 0.2, 1);
  box-shadow: 0 3px 1px -2px rgba(0, 0, 0, 0.2), 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 1px 5px 0 rgba(0, 0, 0, 0.12);
}

.resize-circle {
  position: relative;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: white;
  border: .1px solid white;
  color: #aaa;
  cursor: pointer;
}

span {
  width: 20px;
  height: 20px;
  background: white;
  position: absolute;
  top: -7px;
  border-radius: 50%;
  right: -7px;
  overflow: hidden;
}
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">


<div class="print-element">
  Tag Number
  <span><i class="material-icons resize-circle">highlight_off</i></span>
</div>

Answer №2

To resolve this issue, I utilized a technique involving a negative margin. While effective, I must admit that the solution presented by Font Awesome is truly remarkable, echoing the sentiments of @Michael Burns.

When implementing the negative margin, the specific pixel value required will vary depending on the size and type of icon used. Nevertheless, it ensures consistency across different web browsers.

.material-icons.primary-header-material-icon-first-menu {
  margin-left: -2px;
}

Answer №3

If you're tired of manually removing padding from icons, fear not! I have developed a handy tool that can remove padding from all icons in a set with ease. While it does involve creating a new icon set, it can be a lifesaver: https://github.com/johndoe/IconPaddingRemover

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

Why is there a mismatch between CSS and Angular 6 selector components?

website.html <website-chat></website-chat> chat-page.html <h1>Greetings</h1> chat-script.ts import { Component, OnInit } from '@angular/core'; @Component({ selector: 'website-chat', templateUrl: '. ...

Emphasize the content within the table cell

Currently, I am working with an HTML table that is being generated by Java. My goal is to highlight the text within a table cell without changing the background color of the entire cell. I should mention that I am aware of the option to achieve this by ma ...

Is the form always being processed by onsubmit and confirm?

Apologies if this question has been asked before. I am currently working on a form where I ask the user to confirm an action, but it's not functioning as expected. The form proceeds regardless of whether the user clicks ok, cancel, or even closes the ...

Interacting with HTML elements in Java programming

I am facing a challenging situation that requires some brainstorming. I would greatly appreciate any advice or guidance in the right direction. My goal is to incorporate a Google Map into my Java Swing project, with the map being specified as a URL wit ...

What is the best way to eliminate the white space between two sections?

I am currently utilizing Bootstrap 4 along with a custom CSS stylesheet for my website structure. Here is the layout: <header> <!-- content in header (fixed) --> </header> <main role="main" class="container-fluid"> <!-- ...

Firefox triggers drag events while passing over a div scrollbar

I am looking to create a file drag and drop feature using a styled div: When dragging files over the div, I want the border color to change When dragging files out of the div, I want the border color to revert back to the original In Firefox 35 (Ubuntu) ...

Expanding containers with flexbox to allow for flexibility in size

I need help with a page that contains 3 div elements, where 2 of them need to be resizable. These elements should be able to be moved left or right, and maximized or minimized. You can view the example on Stackblitz. The issue I'm facing is that som ...

Could LXML potentially determine the value of a class in HTML?

For instance, consider the following scenario: <button class="oW_lN oF4XW sqdOP yWX7d _8A5w5 ">MyTextIsHere</button> The "MyTextIsHere" part of the code can contain only two specific values: "Yes" and "No". Is it feasible to determine wh ...

What's the best way to keep track of the number of objects I've created

Using this HTML code, I can create member objects. However, I also need to determine the count of these member objects for certain calculations. Additionally, when a member object is deleted, the count of member objects should be reduced accordingly. The ...

What is the best way to hide the select arrow in an input-group using Bootstrap 4?

Is there a way to get rid of the unsightly double arrow in the select element? I have tried various solutions I found online, but none seem to be effective. <div class="form-group"> <label for="date">Date</label> <d ...

Retrieve the order in which the class names are displayed within the user interface

In the following code snippet, each div element is assigned a common class name. <div id="category_9" class="list_item" data-item_ids="[38]"</div> <div id="category_2" class="list_item" data-ite ...

Alternating CSS Designs for Displaying Multiple Mysql Query Results

I have a website where users can search for a specific product in their location, and the site will display a list of results. if(isset($_POST['zip'])){ $qry="SELECT business_id FROM ".TBL_BUSINESS." WHERE zip LIKE '%".$_POST['zip&apos ...

Issues with implementing Bootstrap 4 navbar on a Rails 5 application

I'm currently in the process of transitioning my static HTML/CSS/JS website to a Rails application. Using Bootstrap 4, I had all the functionality and CSS classes working perfectly on the static site. However, after the migration to the Ruby app, the ...

Is there a way to activate the autoplay feature for this?

I'm really new to Jquery and most of this code isn't mine, I'm just using it as a learning tool for creating sliders. If someone could give me some guidance on how to make this slider work automatically when the page loads, that would be gre ...

Ways to display the modal once the user initiates the action

Is there a way to delay loading my modal HTML codes until after the user clicks a button, rather than having them load automatically with the template? HTML <!-- Template Codes--> <button data-toggle="modal" data-target="#modal-content" type="bu ...

Guide on creating a div container that spans the full width of the HTML page with a horizontal scrollbar

I'm facing an issue where the div container is not extending over the entire HTML page with a horizontal scroll bar. Here's a visual representation of my problem: Image Despite using MathJax to display math formulas, the div container does not ...

Is it possible to use cURL to open a particular frame and pass a parameter at the same time?

Currently, I am working on a website with a layout consisting of three frames. The first frame contains two columns, with the second column having two rows. Frame 1 displays a list of countries fetched from a database in the form of URLs. When a country i ...

Manipulating content with JavaScript in Internet Explorer using the outerHTML property is a powerful

Encountering an Issue with outerHTML in IE Browser If I try the following: txt = "Update Complete!"; msg = sub.appendChild(d.createElement("p")); msg.outerHTML = txt; It works without any problem. However, if I use: txt = "1 Error:<ul><li> ...

Increasing the size of the td element when including a new row

Here is an html page example that I am working with: However, when I add a new row beneath the existing row that contains a div block and form within it, I notice that the td tag in the first row expands in width, as depicted in the image below. Below is ...

Tips for keeping an image stationary when hovering over it

I'm in need of some assistance. Despite my best efforts, I have been unable to achieve the desired outcome. I am looking to create a scenario where an image remains in place even when the mouse hovers over it. Essentially, I want the image to stay vis ...