Two hexagon borders around image (responsive) - html

Iam trying to make a double hexagon border around my image. Here is my fiddle, which didnt come far:
https://jsfiddle.net/qeh8wdsd/
code:
<div class="hex">
<div class="hex inner">
<div class="hex inner2">
<img src="http://www.jqueryscript.net/images/Simplest-Responsive-jQuery-Image-Lightbox-Plugin-simple-lightbox.jpg"/>
</div>
</div>
</div>
.hex {
margin-top: 70px;
width: 208px;
height: 120px;
background: #000;
position: relative;
}
.hex:before, .hex:after {
content:"";
border-left: 104px solid transparent;
border-right: 104px solid transparent;
position: absolute;
}
.hex:before {
top: -59px;
border-bottom: 60px solid #000;
}
.hex:after {
bottom: -59px;
border-top: 60px solid #000;
}
.hex.inner {
background-color:blue;
-webkit-transform: scale(.8, .8);
-moz-transform: scale(.8, .8);
transform: scale(.8, .8);
z-index:1;
}
.hex.inner:before {
border-bottom: 60px solid blue;
}
.hex.inner:after {
border-top: 60px solid blue;
}
.hex.inner2 {
background-color:red;
-webkit-transform: scale(.8, .8);
-moz-transform: scale(.8, .8);
transform: scale(.8, .8);
z-index:2;
}
.hex.inner2:before {
border-bottom: 60px solid red;
}
.hex.inner2:after {
border-top: 60px solid red;
}
so i want the image to be where the red hexagon is, basically the image should be inside and "clipped" to a hexagon and then i want a blue and a black border around it which is about 2px each. And the second issue is that i want to make it responsive. Hope anyone can help me achieve this.

The CSS property of clip-path should be able to provide you with the functionality you are looking for natively, particularly the polygon option.
You can define custom shapes for clipping, including a hexagon, and provides a high level of customization.
Here's a link for more info on this: css-tricks clip-path

Related

How do I make a slash in a webpage with HTML/CSS?

I'm trying to produce a parallelogram/slash look in my webpage as follows:
It's easy to smash two divs together and then you have a rectangle next to a rectangle, but this slash is mind boggling. Is this possible with pure CSS or HTML? The examples I've seen all use SVGs.
html,
body {
min-height: 100%; /* demo only */
}
#page {
min-height: 100vh; /* demo only */
}
#page:before {
content: '';
position: absolute;
width: 25%;
height: 150%;
left: -10%;
top: -25%;
background: #F6990D;
transform: rotate(4deg);
border-right: 4px solid #FEBF78;
}
<div id="page"></div>
Just adding the linear option, but getting around the aliasing jagged edges will be tough regardless of the approach you take.
div {
position: absolute;
top: 0;right: 0;bottom: 0; left:0;
background: rgba(255,163,3,1);
background: linear-gradient(95deg, rgba(255,163,3,1) 0%,
rgba(255,163,3,1) 9%,
rgba(245,205,135,1) 9%,
rgba(245,205,135,1) 10%,
rgba(255,255,255,1) 10%,
rgba(255,255,255,1) 100%
);
}
<div></div>
Start from a square div with four thick borders.
div {
width: 50px;
height: 50px;
border-left: 50px solid green;
border-top: 50px solid red;
border-right: 50px solid blue;
border-bottom: 50px solid yellow;
}
<div> </div>
Now reduce the square to zero height.
div {
width: 50px;
height: 0;
border-left: 50px solid green;
border-top: 50px solid red;
border-right: 50px solid blue;
border-bottom: 50px solid yellow;
}
<div> </div>
Now take off the left and bottom borders.
div {
width: 50px;
height: 0;
border-top: 50px solid red;
border-right: 50px solid blue;
}
<div> </div>
Finally, shrink the right border and make it transparent.
div {
width: 50px;
height: 0;
border-top: 50px solid red;
border-right: 15px solid transparent;
}
<div> </div>
You can adjust the numbers and add a shadow to make it look more like the example image. You can also add transform: rotate(360deg) to get cleaner aliasing in certain scenarios (this is a hack; it tricks the browser into switching to GPU-accelerated rendering mode if such a mode is available).
div {
width: 50px;
height: 0;
border-top: 300px solid orange;
border-right: 15px solid transparent;
filter: drop-shadow(10px 0 yellow);
/* HACK: trick the browser into GPU-accelerated mode if possible,
* this can help get cleaner aliasing in certain scenarios. */
transform: rotate(360deg);
}
<div> </div>
#slash {
width: 15px;
height: 100px;
transform: skew(-20deg);
background: red;
}
#container {
padding-left: 20px;
}
<div id="container">
<div id="slash">
</div>
</div>
Just create a square and use skew transform

How to draw a gradient colored trapezoid with css3?

I need to make a trapezoid like in image, but I don't know how.
I'm trying to do it with the following css but I'm stuck:
#trapezoid {
width: 100px;
height: 0;
border-top: 50px solid #82E81B;
border-left: 0px solid transparent;
border-right: 30px solid transparent;
}
If you have a good method to achieve using CSS it please tell me.
look this:
#div1 {
position: relative;
height: 150px;
width: 50px;
margin: 50px;
padding: 0px;
-webkit-perspective: 150px; /* Chrome, Safari, Opera */
perspective: 200px;
}
#div2 {
padding: 40px 70px;
position: absolute;
border-radius:2px;
-webkit-transform: rotateY(-30deg); /* Chrome, Safari, Opera */
transform: rotateY(-30deg);
box-shadow:3px 0px 6px rgb(19,83,60),inset 1px 1px 2px 2px rgba(241,251,50,1);
background-image:-webkit-linear-gradient(to right, #b7f915, #b7f915,#6fd00c);
background-image:linear-gradient(to right,#b7f915,#b7f915, #6fd00c);
}
<div id="div1">
<div id="div2"></div>
</div>
Leaving the shadow and gradient to you. Enjoy.
#trapezoid {
border-top: 50px solid #82E81B;
border-left: 0px solid transparent;
border-right: 30px solid transparent;
height: 30px;
background: transparent;
width: 100px;
perspective-origin: 0% 50%;
transform: perspective( 600px ) rotateY( -45deg );
position: relative;
}
<div id="trapezoid"></div>

create full border triangle div

I am trying to make a top-left triangle (red) with a (black) border. I want it to have the black border all the way around. This attempt angles a square to fake it (pushed outside the screen to mimmick a triangle)
I want the border all the way around, in which my attempt won't work
#corner {
height: 75px;
width: 100px;
position: absolute;
left: -3em; top: -2em;
z-index: 999;
transform: rotateZ(-45deg);
background-color: red;
border-bottom: 5px solid #0c0c0c;
}
<div id="corner"></div>
There is an easier way to create triangles, you can just use an element with a width / height of 0.
And for the border you want, the idea is to have two overlapping triangles in two different colors and different sizes, maybe take a look at the following snippet:
.triangle-up-left-1 {
width: 0;
height: 0;
border-top: 50px solid rgb(246, 85, 85);
border-right: 50px solid transparent;
z-index:2;
position:absolute;
top:5px;
left:13px;
}
.triangle-up-left-2 {
width: 0;
height: 0;
position:absolute;
top:0;
border-top: 68px solid rgb(0, 0, 0);
border-right: 68px solid transparent;
z-index:1:
}
<div class="triangle-up-left-1"></div>
<div class="triangle-up-left-2"></div>
You can made triangle also like this: https://css-tricks.com/examples/ShapesOfCSS/
I tried to combine two of them and with margin to position it, so it would look as one with a border. Perhaps this is a possible solution for you. Cheers.
.triangle1 {
width: 0;
height: 0;
border-top: 100px solid black;
border-right: 100px solid transparent;
}
.triangle2 {
width: 0;
height: 0;
border-top: 82px solid red;
border-right: 82px solid transparent;
position: absolute;
margin-top: -95px;
margin-left: 5px;
}
<div class="triangle1">
<div class="triangle2"></div>
</div>

Creating a transparent CSS triangle over a background image

I'm making a divider over a background image that features a line with a pointer in the middle signifying to look below it. It's all just one line so the divider is not solid. When I made my divider the border of the parent goes through the triangle because the background is transparent.
Just take a look at what I'm trying to explain:
I would like the triangle to hide that line in the middle. This is how I create the divider:
<div class="splash">
<div class="splash-divider">
</div>
</div>
.splash {
background: url("https://unsplash.imgix.net/photo-1416339442236-8ceb164046f8?q=75&fm=jpg&s=8eb83df8a744544977722717b1ea4d09");
height: 200px;
}
.splash-divider {
position: relative;
margin: 20px auto 0 auto;
width: 50%;
height: 30px;
border-bottom: 1px solid #ffffff;
box-shadow: 0px 2px 0px rgba(0, 0, 0, 0.15);
}
.splash-divider:after {
content: "";
position: absolute;
top: 15px;
left: 50%;
width: 30px;
height: 30px;
border-left: 1px solid #ffffff;
border-bottom: 1px solid #ffffff;
box-shadow: -2px 2px 0 rgba(0, 0, 0, 0.15);
transform: rotate(-45deg) translate(-50%, -50%);
-webkit-transform: rotate(-45deg) translate(-50%, -50%);
-ms-transform: rotate(-45deg) translate(-50%, -50%);
-moz-transform: rotate(-45deg) translate(-50%, -50%);
-o-transform: rotate(-45deg) translate(-50%, -50%);
}
As you can see, the parent contains a background image. This would be super simple if it was just a color.
Here's the fiddle.
Edit
Resolved! Here's the working fiddle: http://jsfiddle.net/a9fkh0tp/1/
It is possible, see live demo: http://jsfiddle.net/a9fkh0tp/1/
.splash {
background: url("https://unsplash.imgix.net/photo-1416339442236-8ceb164046f8?q=75&fm=jpg&s=8eb83df8a744544977722717b1ea4d09");
height: 200px;
}
.splash-divider {
position: relative;
margin: 20px auto 0 auto;
width: 50%;
height: 30px;
border-bottom: 1px solid transparent;
}
.splash-divider:after {
content: "";
position: absolute;
top: 15px;
left: 50%;
width: 30px;
height: 30px;
border-left: 1px solid #ffffff;
border-bottom: 1px solid #ffffff;
box-shadow: -2px 2px 0 rgba(0, 0, 0, 0.15);
transform: rotate(-45deg) translate(-50%, -50%);
}
.splash-divider span:before,
.splash-divider span:after {
position: absolute;
top: 0;
display: inline-block;
content: "";
width: 50%;
height: 30px;
border-bottom: 1px solid #fff;
box-shadow: 0px 2px 0px rgba(0, 0, 0, 0.15);
}
.splash-divider span:before {
left: -28px;
}
.splash-divider span:after {
right: -16px;
}
<div class="splash">
<div class="splash-divider"><span></span></div>
</div>
The idea is to divide the single line to 2 parts (left + right). In order to do that, add a <span> into the <div>, so <div class="splash-divider"><span></span></div> we can then play more with it.
You could as well use a method with pseudo elements.
.divider {
padding:1em;
transform:rotate(45deg);
width:0;
margin:auto;
border:2px white solid;
border-top:none;
border-left:none;
position:relative;
box-shadow:1px 1px 1px white;
}
.divider:before, div:after {
content:'';
width:2000px;
border-bottom:2px solid white;
position:absolute;
}
.divider:before {
transform-origin:top left;
bottom:1.9em;
left:2em;
transform:rotate(-45deg);
box-shadow:1px 1px 1px white;
}
.divider:after {
transform-origin:top left;
left:0.05em;
top:2.1em;
transform:rotate(135deg);
box-shadow:1px -1px 1px white;
}
html {
min-height:100%;
background:gray;
background:linear-gradient(to bottom left, gray, yellow,purple, gray, yellow,purple, gray, yellow,purple);
}
<div class="divider"></div>
You can play with it in http://codepen.io/gc-nomade/pen/raYGyO ... add radius, transform, whatever :)
HTML:
<div class="line-separator">
<div class="side-line"> </div>
<div class="triangle"> </div>
<div class="side-line"> </div>
</div>
CSS:
.side-line {
display: inline-block;
border-top: 1px solid black;
width: 20%;
}
.triangle {
display: inline-block;
height: 7px;
width: 7px;
transform: rotate(45deg);
transform-origin: center center;
border-top: 1px solid black;
border-left: 1px solid black;
margin: 0 -3px -3px;
}
Live demo:
http://jsfiddle.net/85saaphw/
If you want the triangle to be upside-down just change the transform: rotate(45deg) arg to 225deg.

How to create a triangular tip with outline on top of an HTML element with Pure CSS?

You may have probably seen this type of boxes with a triangular arrow tip on Facebook, Google, Twitter, etc. Fortunately, I've also created one with pure CSS.
Here is the code:
HTML :
<div class="box"><h3>This box contains a triangular arrow tip on top of it.</h3></div>
CSS :
.box { position: relative; background: #fff; color: #000; padding: 8px; border: 1px solid #ccc; }
.box:after {content: ""; position: absolute; display: block; width: 0; top: -15px; right: auto; bottom: auto; left: 5px; border-width: 0 10px 15px; border-style: solid; border-color: #fff transparent; }
You can see that the triangular tip is pure white color. And if you study the CSS you'll see that the white color of the tip is actually the color of the border.
Now what I'm looking for is a (gray coloured, for example) border or outline on the surface of the triangular tip. Because the color of the tip comes from the border, I can't use a second border because there is no such thing. I've tried outline but it doesn't seem to work. Any help how to do this with pure CSS?
Make use of the :before pseudo-element to place a similar arrow behind the first one.
This is the technique used on http://cssarrowplease.com.
See it in action based on your example.
.box:before {
content:"";
position: absolute;
display: block;
width: 0;
top: -16px;
right: auto;
bottom: auto;
left: 3px;
border-width: 0 12px 17px;
border-style: solid;
border-color: #ccc transparent;
z-index: -1;
}
Don't use borders to create the triangle. Simply use a pseudo-element on which you apply a CSS transform.
DEMO
Result:
HTML:
<ul class='drop-down'>
<li><a href='#'>Suggestions</a></li>
<li><a href='#'>Friends (8)</a></li>
<li><a href='#'>Friend Requests</a></li>
<li><a href='#'>My Requests</a></li>
<li><a href='#'>People I blocked</a></li>
</ul>
Relevant CSS:
.drop-down {
position: relative;
border: solid 1px #ccc;
background: white;
}
.drop-down:before {
position: absolute;
top: -.56em; left: 1em;
border-left: solid 1px #ccc;
border-top: solid 1px #ccc;
width: 1em; height: 1em;
transform: rotate(45deg);
background: inherit;
content: '';
}
/* variations */
.drop-down:first-child:before {
transform: rotate(60deg) skewX(30deg) scaleY(.866);
}
.drop-down:nth-child(3):before {
border-right: solid 1px #ccc;
border-left: none;
transform: rotate(-60deg) skewY(30deg) scaleX(.866);
}
You can do this with with the UTF-8 "up arrow" and a bit of absolute positioning and a text shadow:
Your container:
.boxArrow {
margin-top:30px;
height:100px;
width:100px;
border:1px solid #000000;
position:relative;
}
The arrow:
.boxArrow:before {
content: "\25B2";
font-size:16px;
color:#ffffff;
position:absolute;
top:-15px;
left:30px;
text-shadow: -1px 0 black, 0 1px white, 1px 0 black, 0 -1px black;
}
For simplicity, easy and fast work, you can use jQuery UI : http://jqueryui.com/tooltip/#custom-style