热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何删除按钮之间的额外空间?-howtodeleteextraspacebetweenbuttons?

pleasecheckoutthiscodeinjsfiddle请在jsfiddle中查看此代码HTML:HTML:<div><

please check out this code in jsfiddle

请在jsfiddle中查看此代码

HTML:

HTML:


CSS:

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

谢谢

9 个解决方案

#1


24  

Look at this jsFiddle

看看这个jsFiddle

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

我已经更新了display:inline-block;显示:块;在菜单链接上添加了float:left给他们。

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..

使用内联块时,HTML标记中的元素之间的空格会导致元素之间存在这种丑陋的内联间隙。

#3


6  

After all the float solutions and CSS hacks, here's a way to eliminate the spaces themselves:

在所有浮点解决方案和CSS黑客之后,这是一种消除空间本身的方法:


I'm not saying you should do it like this - but it is an option, and technically it's a lot less of a hack than floating left; this is the closest thing to not having the space at all (unless you write all links in a row which just looks ugly and makes it a pain to insert/delete/reorder).

我并不是说你应该这样做 - 但这是一个选择,从技术上来说,它不是一个黑客而是漂浮左边;这是最接近没有空间的东西(除非你把所有链接写成一行看起来很难看并且插入/删除/重新排序很麻烦)。

Again, I know it seems weird but the real weirdo here is HTML itself, not giving you a clear way to do this.

再一次,我知道它看起来很奇怪,但真正的古怪是HTML本身,没有给你一个明确的方法来做到这一点。

#4


3  

You might want to read this article about the subject by Chris Couier

您可能想阅读Chris Couier关于这个主题的这篇文章

http://css-tricks.com/fighting-the-space-between-inline-block-elements/

http://css-tricks.com/fighting-the-space-between-inline-block-elements/

#5


1  

here is your solution

这是你的解决方案

http://jsfiddle.net/NPqSr/7/

http://jsfiddle.net/NPqSr/7/

.buttons
{
    text-decoration: none;
    color: #ffffff;
    line-height: 3em;
    display: inline-block;
    padding-left: 10px;
    float:left;
    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;
}

#6


0  

Try this(JSFiddle)

试试这个(JSFiddle)

CSS

#main {

    height: 25em;
}

#menu {
    background-color: #00b875;
    height: 3em;
}

.buttons {
    text-decoration: none;
    color: #ffffff;
    line-height: 3em;
    display: inline-block;
    padding-left:5px;
    padding-right:5px;
    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;
}

#7


0  

I think with latest CSS possibilities a cleaner solution is to use display:inline-flex on menu and display:flex on buttons, and maybe width:100% on menu:

我认为最新的CSS可能性更清晰的解决方案是使用display:inline-flex菜单和显示:flex on buttons,也许宽度:100%菜单:

http://jsfiddle.net/NPqSr/212/

http://jsfiddle.net/NPqSr/212/

#8


0  

It's 2017: wrap them inside an element with display: inline-flex and flex the inner buttons with something like flex: 0 1 auto:

它是2017年:将它们包装在一个带显示的元素内:inline-flex并用flex之类的方式弯曲内部按钮:0 1 auto:

#9


0  

Add the below style to your button. If required, make the margin negative for first of the few buttons.

将以下样式添加到按钮。如果需要,请为几个按钮中的第一个按钮设置负值。

button{ margin: 0px; }

按钮{margin:0px; }


推荐阅读
  • 深入理解CSS中的margin属性及其应用场景
    本文主要介绍了CSS中的margin属性及其应用场景,包括垂直外边距合并、padding的使用时机、行内替换元素与费替换元素的区别、margin的基线、盒子的物理大小、显示大小、逻辑大小等知识点。通过深入理解这些概念,读者可以更好地掌握margin的用法和原理。同时,文中提供了一些相关的文档和规范供读者参考。 ... [详细]
  • FeatureRequestIsyourfeaturerequestrelatedtoaproblem?Please ... [详细]
  • 在分页时,我想让点过的页码变色.应该怎么做?比如:12345我点2跳到第2页然后2变成红色其他为蓝色 ... [详细]
  • <!DOCTYPEhtml><htmllang=en><head><metacharset=UT ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • Linux重启网络命令实例及关机和重启示例教程
    本文介绍了Linux系统中重启网络命令的实例,以及使用不同方式关机和重启系统的示例教程。包括使用图形界面和控制台访问系统的方法,以及使用shutdown命令进行系统关机和重启的句法和用法。 ... [详细]
  • Webpack5内置处理图片资源的配置方法
    本文介绍了在Webpack5中处理图片资源的配置方法。在Webpack4中,我们需要使用file-loader和url-loader来处理图片资源,但是在Webpack5中,这两个Loader的功能已经被内置到Webpack中,我们只需要简单配置即可实现图片资源的处理。本文还介绍了一些常用的配置方法,如匹配不同类型的图片文件、设置输出路径等。通过本文的学习,读者可以快速掌握Webpack5处理图片资源的方法。 ... [详细]
  • 本文介绍了C#中生成随机数的三种方法,并分析了其中存在的问题。首先介绍了使用Random类生成随机数的默认方法,但在高并发情况下可能会出现重复的情况。接着通过循环生成了一系列随机数,进一步突显了这个问题。文章指出,随机数生成在任何编程语言中都是必备的功能,但Random类生成的随机数并不可靠。最后,提出了需要寻找其他可靠的随机数生成方法的建议。 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • 展开全部下面的代码是创建一个立方体Thisexamplescreatesanddisplaysasimplebox.#Thefirstlineloadstheinit_disp ... [详细]
  • 本文由编程笔记#小编为大家整理,主要介绍了css回到顶部按钮相关的知识,希望对你有一定的参考价值。 ... [详细]
  • 面试中2次被问到过这个知识点,实际开发中,应用事件委托也比较常见。JS中事件委托的实现主要依赖于事件冒泡。那什么是事件冒泡?就是事件从最深 ... [详细]
  • 基于jquery实现简单的分页控件_jquery
    前台分页控件有很多,这里分享我的分页控件pagination.js1.0版本,该控件基于jquery。先来看一下预览效果: ... [详细]
  • vue扫描二维码
    本地要用localhost。发布之后要用https的才可以看到。(你的设备也必须有摄像头)切记卡号 ... [详细]
author-avatar
韩韩韩韩韩海
这个家伙很懒,什么也没留下!
Tags | 热门标签
RankList | 热门文章
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有