带有侧箭头的CSS Square div

时间:2017-05-19 06:36:50

标签: javascript jquery html css

我有一个包含图像的div。此图像仅在元素悬停时显示,因此我希望侧箭头指向侧面(在元素悬停的方向上)。

此代码生成方形div:

 <div id="image-thumbnail-container">
    <img id="image-thumbnail" class="arrow-right">
    <div class="triangle"></div>
</div>

的CSS:

#image-thumbnail-container {
    display: block,
    position: fixed,
    padding: 4px,
    border-radius: 5px,
}

#image-thumbnail {
    display: block,
    position: fixed,
    border: 1px solid #000,
    padding: 4px,
    border-radius: 5px,
}

.triangle {
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 10px 0 10px 17.3px;
    border-color: transparent transparent transparent #ff0055;
}

这是我所拥有的一个例子(这不是代码完全生成的内容):

enter image description here

如何制作箭头以及如何制作div是没有问题的,但有没有办法连接它们并使边框无缝?如:

enter image description here

如果这对于它的价值来说太多了,是否有一个很好的方法来获得箭头,但也有一个很好的背景,以迎合透明的背景图像?

谢谢!

1 个答案:

答案 0 :(得分:3)

尝试使用它。

.arrow{
	position: relative;
	background: #88b7d5;
	border: 4px solid #c2e1f5;
  width: 250px;
  height: 350px;
}
.arrow:after, .arrow:before {
	left: 100%;
	top: 50%;
	border: solid transparent;
	content: " ";
	height: 0;
	width: 0;
	position: absolute;
	pointer-events: none;
}

.arrow:after {
	border-color: rgba(136, 183, 213, 0);
	border-left-color: #88b7d5;
	border-width: 30px;
	margin-top: -30px;
}
.arrow:before {
	border-color: rgba(194, 225, 245, 0);
	border-left-color: #c2e1f5;
	border-width: 36px;
	margin-top: -36px;
}
<div class="arrow"></div>