【问题标题】:half borders at top right corner and bottom left corner with css带有css的右上角和左下角的半边框
【发布时间】:2014-10-23 18:14:34
【问题描述】:

我有一些图像,我希望右上角和左下角有一半边框。我遇到的问题是:

问题1:我已经设法在所有四个角上切割边框,但不能切割左上角和右下角。下面的代码(我用的是KillaCam提供的这个fiddle,做了一点实验,结果四个角先出现,然后三个消失!:http://jsfiddle.net/3jo5btxd/

#div1 {
position: relative;
height: 100px;
width: 100px;
background-color: white;
border: 1px solid transparent;transition: border 2000ms ease 0s;
}

#div2 {
position: absolute;
top: -2px;
left: -2px;
height: 84px;
width: 84px;
background-color: #FFF;
border-radius: 15px;
padding: 10px;
}

问题 2 我已经有一个面板,它有一个使用 css 表格方法垂直居中的链接,它在悬停时也可见。当我将面板的代码与角边框结合起来时,我的垂直居中就会失控!我想这是因为我使用了额外的 div 作为边框,但我没有设法用:before 制作角落(在悬停时不起作用)。下面的 HTML 和 css 以及显示我想要制作的图像:

<ul class="img-list">
<li class="category_lists one-third column-block" '="">
<a href="http://kohphangan.smartsolutionpro.us/category/adventure/">
<img src="something.jpg"/>
 <span class="text-content">
 <span>Adventure</span>
 </span>
 </a>
</li>
<li class="category_lists one-third column-block" '="">
  <a href="http://kohphangan.smartsolutionpro.us/category/beach-2/">
<img src="something2.jpg" />
<span class="text-content">
<span>Beach</span>
</span>
</a>
</li> </ul>

CSS:

/*css for the categories on home page*/
.img-list{margin:0;padding:0; list-style:none}
ul.img-list li {
display: inline-block;
height: 20em;
margin: 0;
position: relative;

}
.category_lists.one-third{width:33%; margin-left:0;}
.category_lists img{width:100%; height:auto;}


span.text-content span {
display: table-cell;
text-align: center;
vertical-align: middle;
}
span.text-content {
background: rgba(38,196,83,0.7);
color: white;
cursor: pointer;
display: table;
 height: 7em;
left: 0;
position: absolute;
top: 0;
width: 100%;
opacity: 0;
-webkit-transition: opacity 500ms;
-moz-transition: opacity 500ms;
-o-transition: opacity 500ms;
transition: opacity 500ms;
font-size:42px;
 text-transform:uppercase;
font-family: 'Raleway', sans-serif; font-weight:300
} 
ul.img-list li:hover span.text-content {
   opacity: 1;
}

以及显示我想要制作的图片:http://tinypic.com/r/2gy5zk4/8。

如果我必须使用 javascript,我会,但我不是很擅长,所以指望 css 让它工作。非常感谢您的帮助。

【问题讨论】:

  • 你想画那种边框的图片都是一样大小的吗?
  • @Sai,是的。宽度和高度应该相同。

标签: javascript jquery html css


【解决方案1】:

这是一种解决方案:http://jsfiddle.net/f7u6yxLq/。

HTML:

<div></div>

CSS:

* {
    margin: 0;
    padding: 0;
}

body {
    padding: 10px;
}

div {
    position: relative;
    display: table;
    width: 200px;
    height: 100px;
    background: url("http://placehold.it/200x100")
                no-repeat
                top left;
}

div:before,
div:after {
    content: "";
    position: absolute;
    width: 50px;
    height: 50px;
    border: solid white;
    border-width: 2px 2px 0 0;
    display: none;
}

div:before {
    right: 5px;
    top: 5px;
}

div:after {
    border-width: 0 0 2px 2px;
    bottom: 5px;
    left: 5px;
}

div:hover:after,
div:hover:before {
    display: block;
}

【讨论】:

  • 如何让它与悬停一起工作?在之前和之后使用时,我一直坚持这一点。我的边框处于悬停状态。
  • @Sai:我很感激。
【解决方案2】:

问题 #1 的解决方案:http://jsfiddle.net/3jo5btxd/2/

.div2:before, .div2:after {width:9px; height:9px; position: absolute;background:#fff; content:'';}
.div2:before {top:0; left:0;}
.div2:after {bottom:0; right:0; }

【讨论】:

    猜你喜欢
    • 2012-02-17
    • 2021-08-21
    • 2016-07-15
    • 1970-01-01
    • 2023-03-25
    • 2020-05-07
    • 2016-06-08
    • 2013-12-22
    • 2021-10-30
    相关资源
    最近更新 更多