【问题标题】:Outline border bottom only [duplicate]仅轮廓边框底部[重复]
【发布时间】:2014-06-30 19:23:27
【问题描述】:

当光标在图像上时,我想创建一个底部轮廓边框,但我不知道该怎么做。我想使用这种内边框,因为我不希望传统边框底部出现布局问题。

这是我当前的代码,到处都有轮廓边距:

.img-lightbox-small{
width:110px;
height:110px;
margin: 1px;}

a img.img-lightbox-small:hover{
opacity:1;
outline: 3px solid #4bb6f5;
outline-offset: -3px;
}

【问题讨论】:

  • Outline 不允许只有一侧拥有它。
  • 你可以这样做DEMO

标签: html css border outline


【解决方案1】:

要解决此问题,您可以使用border-bottom,并设置margin-bottom: -1px(边框大小)。这将阻止它移动下面的内容。

HTML:

<div></div>
test

CSS:

div {
    width: 100px;
    height: 100px;
    background: #eee;
}
div:hover {
    width: 100px;
    height: 100px;
    background: #eee;
    border-bottom: 1px solid;
    margin-bottom: -1px;
}

DEMO HERE

【讨论】:

  • 我愿意接受任何其他解决方案。不漂亮是什么意思?
  • 我刚刚添加了我的答案
  • 如何为边框着色?我的总是显示黑色
  • @JoePhillips border-color: red; 只是普通的 CSS。
【解决方案2】:

outline 不像边框属性。你有所有方面,或者没有。 您最好使用与覆盖盒子模型的box-sizing:border-box 混合的border 属性,这样您的布局就不会“移动”。

http://jsfiddle.net/8XjM5/1/

div {
    width: 100px;
    height: 100px;
    background: #eee;
    box-sizing:border-box;
    -webkit-box-sizing:border-box;
}
div:hover {
    width: 100px;
    height: 100px;
    background: #eee;
    border-bottom: 1px solid;

}

【讨论】:

  • 啊,我明白了,我没有这样做,因为它使用的是CSS3
  • 我也试过这个,但是当我应用它时,我的图像正在移动(当 a:hover 时尺寸减小),而其他代码不是这种情况......请参阅jsfiddle.net/8XjM5/4(对不起,我不知道如何使用这个网站我想我删除了你的代码新手
  • img 是一个内联元素,该属性仅适用于块元素。无论如何,即使它是一个 css3 功能,它也得到了广泛的支持:caniuse.com/#search=box-sizing
猜你喜欢
  • 2021-11-26
  • 2014-04-20
  • 1970-01-01
  • 2012-09-22
  • 1970-01-01
  • 1970-01-01
  • 2020-12-14
  • 1970-01-01
  • 2014-06-06
相关资源
最近更新 更多