Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove Spacing from google's Material Design Icons Exterior?

Headnote: I am having trouble removing spacing from around Google's Material Design icons, and cannot seem to find any solutions on Google or the Material Design icons guide. I am not sure whether the answer is blatantly simple and I'm missing it, or whether there is a more profound reason as to why I am unable to accomplish a seemingly simple task.

Below you can find extracts from the relevant code in my project, or, alternatively, you can view my full project here.

  • My 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>
    
  • the icon styling,

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

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

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

I would like the icon to appear directly beside the heading with no padding around the icon so that I can add spacing around the elements myself, almost like a reset! I've tried using padding: 0px;, in addition to a few other solutions to try and resolve the issue, however, it was to no avail.

Footnote: I am using Eric Meyer's "Reset CSS", however, to my knowledge, this should have no effect on Google's Material Design icons.


Update (24/03/2018 01:33 UTC): It seems as though Google adds spacing around the icon in the image file itself, giving users no option to format said spacing. If anyone else has this same problem, I would recommend that you use another icon font, such as Font Awesome.

like image 973
Michael Burns Avatar asked Sep 13 '25 02:09

Michael Burns


2 Answers

what I did was wrapping the icon with a span and give it a fix hight and width then all I had to do was to hide the overflow .

That's how it looks in my browser. result

An example for removing the white space from 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>
like image 121
Ahmad Dalao Avatar answered Sep 15 '25 17:09

Ahmad Dalao


I tackled this problem by applying a negative margin. It works... but the way Font Awesome solved this is awesome, totally agree with @Michael Burns.

When applying the negative margin, the px will depend on the icon size and the specific icon. But at least it is still consistent in different browsers.

.material-icons.primary-header-material-icon-first-menu {
  margin-left: -2px;
}
like image 39
illnr Avatar answered Sep 15 '25 17:09

illnr