html - 防止文本向左移动一点

标签 html css

我有一个用作菜单的列表。当我将鼠标悬停在它们上方时,我会在它们周围创建一个边框,但是当我这样做时,它们会向左移动一点!我怎样才能阻止他们这样做?

Fiddle.

CSS:

header {
    background-color: #eee;
    height: 45px;
    box-shadow: 0px 2px 3px 1px #bbb;
}
#welcome_area {
    float: left;
    margin-left: 5%;
}
#menu {
    float: right;
    margin-right: 5%;
}
#menu nav ul li {
    display: inline;
    padding: 5px;
}
#menu nav ul li a {
    color: black;
    text-decoration: none;
    padding: 2px;
}
#menu nav ul li a:hover {
    border: 1px solid black;
    border-radius: 2px;
}
.userWidget {
    position: relative;
    display: inline-block;
    width: 300px;
    height: 50px;
    overflow: visible;
    z-index: 1;
}
.userWidget:hover {
    z-index: 2;
}
.user {
    position: absolute;
    width: 300px;
    height: 50px;
    margin-bottom: 5px;
    background: #fff;
    transition: width 0.3s, height 0.3s;
}
.user:hover {
    width: 350px;
    height: 200px;
    background: #eee;
    transition: width 0.3s ease 0.5s, height 0.3s ease 0.5s;
}

最佳答案

为非悬停链接添加一个 1px 宽度的隐形边框:

#menu nav ul li a {
    ...
    border: 1px solid transparent;
}

DEMO

关于html - 防止文本向左移动一点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17450508/

相关文章:

html - 是否可以在电子邮件中折叠/展开 DIV?哪些客户支持这个?

html - div之间的css垂直间隙

html - 不能让我的页脚粘住并为内容提供滚动条

html - css a 标签没有向右移动

html - 如何使悬停可点击?

javascript - 如何将 CSS Mixins 应用于原生 Javascript?

html - Bootstrap 导航栏,左右有 2 个品牌,链接居中

html - flexbox:两个垂直图标之间没有空间

html - 在悬停状态下的常规链接前后添加字符

javascript - 如何在.load()之后获取javascript函数的返回值?