Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to delete extra space between buttons?

Tags:

please check out this code in jsfiddle

HTML:

<div id="main">     <div id="menu">         <a href="#" class="buttons">Home</a>         <a href="#" class="buttons">About Us</a>         <a href="#" class="buttons">Pictures</a>         <a href="#" class="buttons">Contact Us</a>     </div> </div> 

CSS:

#main {     width: 64em;     height: 25em; }  #menu      {         background-color: #00b875;         height: 3em;     }      .buttons     {         text-decoration: none;         color: #ffffff;         line-height: 3em;         display: inline-block;         padding-left: 10px;         padding-right: 10px;         font-family: courier new;         -moz-transition: 1s linear;         -ms-transition: 1s linear;         -o-transition: 1s linear;         -webkit-transition: 1s linear;         transition: 1s linear;     }      .buttons:hover     {         background-color: #0d96d6;     } 

when switching from one button to another very quickly, you'll notice that there is actually some gap in between two buttons. i want to get rid of this space. any ideas? if you do answer the question, please also explain why a certain property will fix this.

i know that it is tweakable using padding and margin, but the result is likely to get distorted upon zoom. please point out a stable way of solving the problem.

thanks

like image 892
amin Avatar asked Jun 28 '13 12:06

amin


People also ask

How do you change the space between buttons?

How do I add a space between buttons? Add an Empty div Element Between Two Buttons to Add Space Between Them in HTML. Use the margin-right Property to Put Space Between the Buttons in HTML. Use the margin-right Property and not(:last-child) Selector to Provide Space Between Multiple Buttons in HTML.

How do I reduce the space between two buttons in HTML?

add &nbsp; between them.

How do you reduce space between label and input?

How to remove the space? Space between label and input. Use the element inspector in your browser's devtools to see that margin and/or padding are causing this. But basically setting the margin and padding of these elements to 0 should do the trick, I think..


2 Answers

Look at this jsFiddle

I've updated display:inline-block; to display:block; on the menu links and added float:left to them.

When you use inline-block you will have this ugly inline gap between elements caused by the whitespace between the elements in your HTML markup..

like image 151
Yotam Omer Avatar answered Oct 27 '22 00:10

Yotam Omer


Any whitespace between tags in HTML is collapsed into a single space character, which is why you have that gap.

You could:

  • Float your elements left,
  • Put the </a> and <a> next to each other in the source or
  • Use a font-size: 0 trick

In this case, personally I'd float all my <a>s left although removing whitespace from your source comes with the fewest caveats, the only one being that it's more difficult to read.

like image 31
Bojangles Avatar answered Oct 26 '22 23:10

Bojangles