简体   繁体   English

右上角和左下角的半边框与CSS

[英]half borders at top right corner and bottom left corner with css

I have a few images where I'd like half borders to the top right corner and to the bottom left corner. 我有一些图像,希望在右上角和左下角使用半边框。 The problems I am running into are: 我遇到的问题是:

problem 1: I have managed to cut of borders at all four corners, but can't cut of top left and bottom right. 问题1:我设法在四个角处都切掉了边框,但是不能切开左上角和右下角。 code below (I'm using this fiddle provided by KillaCam, and experimented a little, with the result that all four corners appear at first and then three of them disappears! : http://jsfiddle.net/3jo5btxd/ 下面的代码(我正在使用KillaCam提供的这种提琴,并做了一些实验,结果首先出现了所有四个角,然后三个都消失了!: 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;
}

Problem 2 I already have a panel that has a link vertically centered using the css table method, which is also visible on hover. 问题2我已经有一个面板,该面板的链接使用css table方法垂直居中,在悬停时也可见。 When I combine the panel's code with the corner borders, my vertical centering goes out of whack! 当我将面板的代码与边角边框结合在一起时,我的垂直居中就不那么整齐了! I guess that is happening because of the extra div I am using for borders, but I haven't managed to make the corners with :before (doesn't work on hover). 我想这是由于我用于边框的额外div而发生的,但是我还没有设法通过:before (在悬停时不起作用)。 HTML and css below and the also the image showing what I want to make: 下面的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:

/*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;
}

And the image showing what I want to make: http://tinypic.com/r/2gy5zk4/8 . 以及显示我想要制作的图像: http : //tinypic.com/r/2gy5zk4/8

If I have to use javascript, I will, but I am not very good at it, so counting on css to make it work. 如果必须使用javascript,我会这样做,但是我不太擅长,因此请依靠CSS使其起作用。 Thanks a lot for any help. 非常感谢您的帮助。

Here's one solution: http://jsfiddle.net/f7u6yxLq/ . 这是一种解决方案: http : //jsfiddle.net/f7u6yxLq/

HTML: HTML:

<div></div>

CSS: 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;
}

Solution for problem #1: http://jsfiddle.net/3jo5btxd/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; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我想以简单的html显示图像从右上角移动到左下角 - I want to show a image moving from right top corner to left bottom corner in simple html Fabric Js:如何仅以2个点(即左上角和右下角)以编程方式创建矩形? - Fabric Js: How to Create Rectangle programatically with only 2 points that is Top Left Corner and Bottom Right Corner? CSS仅绘制左边界和上边界,而忽略右边界和底边界 - CSS is only drawing left and top borders, ignoring right and bottom 元素卡在左上角 React/CSS - Elements are stuck in top left corner React/CSS 如何从左下角到右上角创建动态对角线? - How to create dynamic diagonal line from left-bottom to right-top corner? 坚持页面到左下角而不是默认的左上角? - stick page to left bottom corner instead of default left top? 将角印放在砌体的左上角吗? - Place corner stamp in top left corner in Masonry? Chrome扩展程序-是否在页面底部(不是在右上角)加载弹出窗口? - Chrome Extension - Load popup at page bottom (not in top right corner)? 给定以矩形左下角为中心的圆,计算圆的边界矩形的宽度,使其半径接触右上角 - Given circle that is centered on bottom-left corner of a rect, calculate width of circle's bounding rect so its radius touches the top-right corner 计算div的左下角 - Calculate bottom left corner of a div
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM