I am trying to make avatar as a hexagon, I have found a css snippet for doing this, but it only worked for non-square images:
.hexagon {
overflow: hidden;
visibility: hidden;
-webkit-transform: rotate(120deg);
-moz-transform: rotate(120deg);
-ms-transform: rotate(120deg);
-o-transform: rotate(120deg);
transform: rotate(120deg);
cursor: pointer;
}
.hexagon-in1 {
overflow: hidden;
width: 100%;
height: 100%;
-webkit-transform: rotate(-60deg);
-moz-transform: rotate(-60deg);
-ms-transform: rotate(-60deg);
-o-transform: rotate(-60deg);
transform: rotate(-60deg);
}
.hexagon-in2 {
width: 100%;
height: 100%;
background-repeat: no-repeat;
background-position: 50%;
background-size: contain;
visibility: visible;
-webkit-transform: rotate(-60deg);
-moz-transform: rotate(-60deg);
-ms-transform: rotate(-60deg);
-o-transform: rotate(-60deg);
transform: rotate(-60deg);
}
.hexagon1 {
width: 80px;
height: 50px;
}
<div class="hexagon hexagon1">
<div class="hexagon-in1">
<div class="hexagon-in2" style="background-image:url('https://media-exp1.licdn.com/dms/image/C560BAQG-vLQJr3J3zg/company-logo_200_200/0?e=2159024400&v=beta&t=cXNxHCDmX7A_e_LGk75XIbL-eVc7VYdHQfSFH39r3Qo')"></div>
</div>
</div>
<br />
<div class="hexagon hexagon1">
<div class="hexagon-in1">
<div class="hexagon-in2" style="background-image:url('https://poemesurleprophete.com/wp-content/uploads/2018/09/la-seule-force.jpg')"></div>
</div>
</div>
The problem as you can see, with images where width equals height it is not exactly a hexagon, I tried to set the background-size to cover, it worked but part of the image is being cropped. Any idea how to solve this?
it's because the hexagon-in2 is rectangular, put in his css class:
width:72%;
margin:0 14%;
background-size:cover;
It will look like:
.hexagon {
overflow: hidden;
visibility: hidden;
-webkit-transform: rotate(120deg);
-moz-transform: rotate(120deg);
-ms-transform: rotate(120deg);
-o-transform: rotate(120deg);
transform: rotate(120deg);
cursor: pointer;
}
.hexagon-in1 {
overflow: hidden;
width: 100%;
height: 100%;
-webkit-transform: rotate(-60deg);
-moz-transform: rotate(-60deg);
-ms-transform: rotate(-60deg);
-o-transform: rotate(-60deg);
transform: rotate(-60deg);
}
.hexagon-in2 {
width: 72%;
margin: 0 14%;
height: 100%;
background-repeat: no-repeat;
background-position: 50%;
background-size: cover;
visibility: visible;
-webkit-transform: rotate(-60deg);
-moz-transform: rotate(-60deg);
-ms-transform: rotate(-60deg);
-o-transform: rotate(-60deg);
transform: rotate(-60deg);
}
.hexagon1 {
width: 80px;
height: 50px;
}
<div class="hexagon hexagon1">
<div class="hexagon-in1">
<div class="hexagon-in2" style="background-image:url('https://media-exp1.licdn.com/dms/image/C560BAQG-vLQJr3J3zg/company-logo_200_200/0?e=2159024400&v=beta&t=cXNxHCDmX7A_e_LGk75XIbL-eVc7VYdHQfSFH39r3Qo')"></div>
</div>
</div>
<br />
<div class="hexagon hexagon1">
<div class="hexagon-in1">
<div class="hexagon-in2" style="background-image:url('https://poemesurleprophete.com/wp-content/uploads/2018/09/la-seule-force.jpg')"></div>
</div>
</div>
hope it will help
Related
A status bar made with a number of divs, Each has text status in the middle.
Generated the chevron shape with CSS, Shape made with joining two parallelograms. How I can add a text in the middle of each chevron.
.chevron {
display: inline-block;
position: relative;
clear: both;
padding: 12px;
height:20px;
width: 200px;
margin-top:30px;
}
.chevron:before {
content: '';
position: absolute;
top: 0;
left: 0;
height: 50%;
width: 100%;
background: #009999;
color: white;
-webkit-transform: skew(60deg, 0deg);
-moz-transform: skew(60deg, 0deg);
-ms-transform: skew(60deg, 0deg);
-o-transform: skew(60deg, 0deg);
transform: skew(60deg, 0deg);
}
.chevron:after {
content: '';
position: absolute;
top: 50%;
right: 0;
height: 50%;
width: 100%;
background: #009999;
-webkit-transform: skew(-60deg, 0deg);
-moz-transform: skew(-60deg, 0deg);
-ms-transform: skew(-60deg, 0deg);
-o-transform: skew(-60deg, 0deg);
transform: skew(-60deg, 0deg);
}
<div class="chevron"> Text here</div>
<div class="chevron"> Text here</div>
<div class="chevron"> Text here</div>
You should consider using clip-path in combination with a negative right margin instead of your transform: skew() approach. You would have way less code and the result is the same:
.chevron {
display: inline-block;
min-width: 150px;
text-align: center;
padding: 15px 0;
margin-right: -30px;
background: #009999;
-webkit-clip-path: polygon(0 0, 80% 0, 100% 50%, 80% 100%, 0 100%, 20% 50%);
clip-path: polygon(0 0, 80% 0, 100% 50%, 80% 100%, 0 100%, 20% 50%);
}
<div class="chevron">Text here</div>
<div class="chevron">Text here</div>
<div class="chevron">Text here</div>
Give z-index to :before , :after
.chevron {
display: inline-block;
position: relative;
clear: both;
padding: 12px;
height:20px;
width: 200px;
margin-top:30px;
text-align:center;
}
.chevron:before {
content: '';
position: absolute;
top: 0;
left: 0;
height: 50%;
width: 100%;
background: #009999;
color: white;
-webkit-transform: skew(60deg, 0deg);
-moz-transform: skew(60deg, 0deg);
-ms-transform: skew(60deg, 0deg);
-o-transform: skew(60deg, 0deg);
transform: skew(60deg, 0deg);
z-index:-1;
}
.chevron:after {
content: '';
position: absolute;
top: 50%;
right: 0;
height: 50%;
width: 100%;
background: #009999;
-webkit-transform: skew(-60deg, 0deg);
-moz-transform: skew(-60deg, 0deg);
-ms-transform: skew(-60deg, 0deg);
-o-transform: skew(-60deg, 0deg);
transform: skew(-60deg, 0deg);
z-index:-1;
}
<div class="chevron"> Text here</div>
<div class="chevron"> Text here</div>
<div class="chevron"> Text here</div>
You need to add z-index:-1 to the .chevron:before and .chevron:after:
.chevron {
display: inline-block;
position: relative;
clear: both;
padding: 12px;
height:20px;
width: 200px;
margin-top:30px;
text-align:center;
}
.chevron:before {
top: 0;
-webkit-transform: skew(60deg, 0deg);
-moz-transform: skew(60deg, 0deg);
-ms-transform: skew(60deg, 0deg);
-o-transform: skew(60deg, 0deg);
transform: skew(60deg, 0deg);
}
.chevron:after {
top: 50%;
-webkit-transform: skew(-60deg, 0deg);
-moz-transform: skew(-60deg, 0deg);
-ms-transform: skew(-60deg, 0deg);
-o-transform: skew(-60deg, 0deg);
transform: skew(-60deg, 0deg);
}
.chevron:after, .chevron:before {
content: '';
position: absolute;
left: 15px;
z-index:-1;
height: 50%;
width: 100%;
background: #009999;
}
<div class="chevron"> Text here</div>
<div class="chevron"> Text here</div>
<div class="chevron"> Text here</div>
I am trying to rotate 3 divs (cubes) on a hover state but it seems that not every browser can handle this. Only IE Edge without problem.
Firefox works great with the first 2 divs on hover but the cube disappears when hovering on the 3rd.
Chrome starts shaking all the cubes when hovering.
Is there something wrong in my code?
.cube-a,
.cube-b,
.cube-c {
margin-top: 100px;
margin-left: 10px;
float: left;
margin-right: 80px;
width: 100px;
height: 100px;
transform-style: preserve-3d;
transform: rotateX(108deg) rotateY(16deg) rotateZ(192deg);
}
.cube-a .tcface,
.cube-b .tcface,
.cube-c .tcface {
width: 100%;
height: 100%;
position: absolute;
}
.cube-a .cube-a-face {
background-color: #f4e00d;
/* geel */
transform: rotateX(90deg) rotatez(180deg) translateY(-50px) translateZ(50px);
height: 100px;
}
.cube-b .cube-b-face {
background-color: #8db63c;
/* groen */
transform: rotateX(90deg) rotatez(180deg) translateY(-50px) translateZ(50px);
height: 100px;
}
.cube-c .cube-c-face {
background-color: #009de0;
/* blauw */
transform: rotateX(90deg) rotatez(180deg) translateY(-50px) translateZ(50px);
height: 100px;
}
.cube-a .cube-a-right,
.cube-c .cube-c-right {
background-color: #8db63c;
/* groen */
transform: rotateY(-90deg) rotateZ(90deg) translateY(-100px);
transform-origin: 0 0;
width: 100px;
height: 100px;
}
.cube-b .cube-b-right {
background-color: #f4e00d;
/* geel */
transform: rotateY(-90deg) rotateZ(90deg) translateY(-100px);
transform-origin: 0 0;
width: 100px;
height: 100px;
}
.cube-a .cube-a-bottom,
.cube-b .cube-b-bottom {
background-color: #009de0;
/* blauw */
}
.cube-c .cube-c-bottom {
background-color: #f4e00d;
/* geel */
}
.cube-a-bottom,
.cube-b-bottom {
-webkit-transform: rotate(-180deg);
-moz-transform: rotate(-180deg);
-ms-transform: rotate(-180deg);
-o-transform: rotate(-180deg);
}
.cube-a-face,
.cube-a-right,
.cube-a-bottom,
.cube-b-face,
.cube-b-right,
.cube-b-bottom,
.cube-c-face,
.cube-c-right,
.cube-c-bottom {
color: #fff;
text-align: center;
line-height: 100px;
font-size: 92px;
font-weight: 500;
font-family: "Simply Rounded Bold";
}
.cube-a:hover,
.cube-b:hover,
.cube-c:hover {
-webkit-transform: rotateX(90deg) rotateY(0deg) rotateZ(180deg);
-moz-transform: rotateX(90deg) rotateY(0deg) rotateZ(180deg);
-ms-transform: rotateX(90deg) rotateY(0deg) rotateZ(180deg);
-o-transform: rotateX(90deg) rotateY(0deg) rotateZ(180deg);
}
<div class="cube-a">
<div class="tcface cube-a-face">A</div>
<div class="tcface cube-a-right">B</div>
<div class="tcface cube-a-bottom">C</div>
</div>
<div class="cube-b">
<div class="tcface cube-b-face">B</div>
<div class="tcface cube-b-right">A</div>
<div class="tcface cube-b-bottom">C</div>
</div>
<div class="cube-c">
<div class="tcface cube-c-face">C</div>
<div class="tcface cube-c-right">B</div>
<div class="tcface cube-c-bottom">A</div>
</div>
Here is my fiddle:
https://jsfiddle.net/8vuj7peb/100/
Try adding -webkit-transition: all 1s; and transition: all 1s;. This is the transition property, making the transition 1s long.
.cube-a,
.cube-b,
.cube-c {
margin-top: 100px;
margin-left: 10px;
float: left;
margin-right: 80px;
width: 100px;
height: 100px;
transform-style: preserve-3d;
transform: rotateX(108deg) rotateY(16deg) rotateZ(192deg);
-webkit-transition: all 1s; /* Safari */
transition: all 1s;
}
.cube-a .tcface,
.cube-b .tcface,
.cube-c .tcface {
width: 100%;
height: 100%;
position: absolute;
}
.cube-a .cube-a-face {
background-color: #f4e00d;
/* geel */
transform: rotateX(90deg) rotatez(180deg) translateY(-50px) translateZ(50px);
height: 100px;
}
.cube-b .cube-b-face {
background-color: #8db63c;
/* groen */
transform: rotateX(90deg) rotatez(180deg) translateY(-50px) translateZ(50px);
height: 100px;
}
.cube-c .cube-c-face {
background-color: #009de0;
/* blauw */
transform: rotateX(90deg) rotatez(180deg) translateY(-50px) translateZ(50px);
height: 100px;
}
.cube-a .cube-a-right,
.cube-c .cube-c-right {
background-color: #8db63c;
/* groen */
transform: rotateY(-90deg) rotateZ(90deg) translateY(-100px);
transform-origin: 0 0;
width: 100px;
height: 100px;
}
.cube-b .cube-b-right {
background-color: #f4e00d;
/* geel */
transform: rotateY(-90deg) rotateZ(90deg) translateY(-100px);
transform-origin: 0 0;
width: 100px;
height: 100px;
}
.cube-a .cube-a-bottom,
.cube-b .cube-b-bottom {
background-color: #009de0;
/* blauw */
}
.cube-c .cube-c-bottom {
background-color: #f4e00d;
/* geel */
}
.cube-a-bottom,
.cube-b-bottom {
-webkit-transform: rotate(-180deg);
-moz-transform: rotate(-180deg);
-ms-transform: rotate(-180deg);
-o-transform: rotate(-180deg);
}
.cube-a-face,
.cube-a-right,
.cube-a-bottom,
.cube-b-face,
.cube-b-right,
.cube-b-bottom,
.cube-c-face,
.cube-c-right,
.cube-c-bottom {
color: #fff;
text-align: center;
line-height: 100px;
font-size: 92px;
font-weight: 500;
font-family: "Simply Rounded Bold";
}
.cube-a:hover,
.cube-b:hover,
.cube-c:hover {
-webkit-transform: rotateX(90deg) rotateY(0deg) rotateZ(180deg);
-moz-transform: rotateX(90deg) rotateY(0deg) rotateZ(180deg);
-ms-transform: rotateX(90deg) rotateY(0deg) rotateZ(180deg);
-o-transform: rotateX(90deg) rotateY(0deg) rotateZ(180deg);
}
<div class="cube-a">
<div class="tcface cube-a-face">A</div>
<div class="tcface cube-a-right">B</div>
<div class="tcface cube-a-bottom">C</div>
</div>
<div class="cube-b">
<div class="tcface cube-b-face">B</div>
<div class="tcface cube-b-right">A</div>
<div class="tcface cube-b-bottom">C</div>
</div>
<div class="cube-c">
<div class="tcface cube-c-face">C</div>
<div class="tcface cube-c-right">B</div>
<div class="tcface cube-c-bottom">A</div>
</div>
This is my CSS and HTML.
div.musiclink {
position: relative;
}
a.music {
width: 258px;
height: 117px;
display: block;
background: deepskyblue url('MUSIC-cursive.png') center top no-repeat;
-webkit-transform: rotate(330deg);
-moz-transform: rotate(330deg);
-ms-transform: rotate(330deg);
-o-transform: rotate(330deg);
transform: rotate(330deg);
}
a.music:hover {
background-image: url('MUSIC-cursive-hover.png');
}
a.store {
position: relative;
left: 500px;
top: 100px;
width: 220px;
height: 110px;
display: block;
background: deeppink url('STORE-cursive.png') center top no-repeat;
-webkit-transform: rotate(30deg);
-moz-transform: rotate(30deg);
-ms-transform: rotate(30deg);
-o-transform: rotate(30deg);
transform: rotate(30deg);
}
a.store:hover {
background-image: url('STORE-cursive-hover.png');
}
<div class="musiclink">
</div>
<div class="storelink">
</div>
The thing is I positioned everything successfully when I used images instead of href links, but now nothing is working the way I want it to. I don't want the images/links to move when I resize the browser.
So what i want is: when cursor goes over the image (diamond), no to activate the hover of the octagon.
Here is the example:
http://codepen.io/Chrez/pen/yYajGo
<li>
<a href="#">
<div class="octagonFirst">
<div class="octagonIn1">
<div class="octagonIn2">
<div class="octagonIn3"></div>
</div>
</div>
<span class="text First">Startseite</span>
<div class="diamond"></div>
</div>
</a>
</li>
CCS:
body {
background-color: #ba2020;
}
.octagonFirst {
width: 164px;
height: 68px;
position: absolute;
background: black;
top: 200px;
left: 1000px;
color: white;
font-size: 30px;
-webkit-transform: rotate(-16deg);
-moz-transform: rotate(-16deg);
-ms-transform: rotate(-16deg);
-o-transform: rotate(-16deg);
transform: rotate(-16deg);
}
.octagonIn1 {
width: 100%;
height: 100%;
background: inherit;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
}
.octagonIn2 {
width: 100%;
height: 100%;
display: inherit;
background: inherit;
-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);
-ms-transform: rotate(90deg);
-o-transform: rotate(90deg);
transform: rotate(90deg);
}
.octagonIn3 {
width: 100%;
height: 100%;
display: inherit;
background: inherit;
-webkit-transform: rotate(135deg);
-moz-transform: rotate(135deg);
-ms-transform: rotate(135deg);
-o-transform: rotate(135deg);
transform: rotate(135deg);
}
.text {
display: block;
position: absolute;
z-index: 1000;
-webkit-transform: rotate(16deg);
-moz-transform: rotate(16deg);
-ms-transform: rotate(16deg);
-o-transform: rotate(16deg);
transform: rotate(16deg);
}
.First {
left: 35px;
top: 10px;
}
.octagonFirst:hover {
background: white;
color: black;
}
.diamond {
width: 206px;
height: 202px;
position: absolute;
background-image: url('http://i.imgur.com/Yyv3dht.png');
top: 0;
}
Add pointer-events: none; to .diamond
codepen
body {
background-color: #ba2020;
}
.octagonFirst {
width: 164px;
height: 68px;
position: absolute;
background: black;
top: 200px;
left: 1000px;
color: white;
font-size: 30px;
-webkit-transform: rotate(-16deg);
-moz-transform: rotate(-16deg);
-ms-transform: rotate(-16deg);
-o-transform: rotate(-16deg);
transform: rotate(-16deg);
}
.octagonIn1 {
width: 100%;
height: 100%;
background: inherit;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
}
.octagonIn2 {
width: 100%;
height: 100%;
display: inherit;
background: inherit;
-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);
-ms-transform: rotate(90deg);
-o-transform: rotate(90deg);
transform: rotate(90deg);
}
.octagonIn3 {
width: 100%;
height: 100%;
display: inherit;
background: inherit;
-webkit-transform: rotate(135deg);
-moz-transform: rotate(135deg);
-ms-transform: rotate(135deg);
-o-transform: rotate(135deg);
transform: rotate(135deg);
}
.text {
display: block;
position: absolute;
z-index: 1000;
-webkit-transform: rotate(16deg);
-moz-transform: rotate(16deg);
-ms-transform: rotate(16deg);
-o-transform: rotate(16deg);
transform: rotate(16deg);
}
.First {
left: 35px;
top: 10px;
}
.octagonFirst:hover {
background: white;
color: black;
}
.diamond {
width: 206px;
height: 202px;
position: absolute;
background-image: url('http://i.imgur.com/Yyv3dht.png');
top: 0;
pointer-events: none;
}
<li>
<a href="#">
<div class="octagonFirst">
<div class="octagonIn1">
<div class="octagonIn2">
<div class="octagonIn3"></div>
</div>
</div>
<span class="text First">Startseite</span>
<div class="diamond"></div>
</div>
</a>
</li>
I'm building a footer which has a slated top and border :
Is there any way to achieve this in CSS (with transforms perhaps) without having to resort to SVG ?
Thanks
Try this - http://jsfiddle.net/QBxhd/
body {
overflow-x: hidden;
}
footer {
height: 100px;
position: relative;
background: #000;
margin-top: 200px;
}
footer:before, footer:after {
content: '';
display: block;
position: absolute;
height: 40px;
width: 102%;
background: #ccc;
top: -30px;
-webkit-transform: rotate(-3deg);
-moz-transform: rotate(-3deg);
-ms-transform: rotate(-3deg);
-o-transform: rotate(-3deg);
transform: rotate(-3deg);
zoom: 1;
}
footer:after {
background: #000;
top: -23px;
-webkit-transform: rotate(-2deg);
-moz-transform: rotate(-3deg);
-ms-transform: rotate(-3deg);
-o-transform: rotate(-3deg);
transform: rotate(-2deg);
zoom: 1;
}
I would think that using two div that lie on each other, having grey and black as color could do this. turn an position them to the wanted place, and sort them with the z-index.
Or this: http://jsfiddle.net/faceleg/tQtZY/
<div class="grey"></div>
<div class="black"></div>
.grey, .black {
width: 100%;
height: 100px;
position: absolute;
margin-bottom: -20px;
bottom: 0px;
}
.grey {
background-color: gray;
z-index: 10;
-moz-transform: scale(1) rotate(-2deg) translateX(0px) translateY(0px) skewX(0deg) skewY(0deg);
-webkit-transform: scale(1) rotate(-2deg) translateX(0px) translateY(0px) skewX(0deg) skewY(0deg);
-o-transform: scale(1) rotate(-2deg) translateX(0px) translateY(0px) skewX(0deg) skewY(0deg);
-ms-transform: scale(1) rotate(-2deg) translateX(0px) translateY(0px) skewX(0deg) skewY(0deg);
transform: scale(1) rotate(-2deg) translateX(0px) translateY(0px) skewX(0deg) skewY(0deg);
}
.black {
background-color: black;
z-index: 11;
-moz-transform: scale(1) rotate(-1deg) translateX(0px) translateY(0px) skewX(0deg) skewY(0deg);
-webkit-transform: scale(1) rotate(-1deg) translateX(0px) translateY(0px) skewX(0deg) skewY(0deg);
-o-transform: scale(1) rotate(-1deg) translateX(0px) translateY(0px) skewX(0deg) skewY(0deg);
-ms-transform: scale(1) rotate(-1deg) translateX(0px) translateY(0px) skewX(0deg) skewY(0deg);
transform: scale(1) rotate(-1deg) translateX(0px) translateY(0px) skewX(0deg) skewY(0deg);
}
just another way http://jsfiddle.net/uttara/XrVzx/3/
<div id="footer"></div>
#footer{
width:500px;
height:100px;
margin:50px auto;
background-color:black;
}
#footer:after{
border-bottom: 30px solid black;
border-left: 500px solid transparent;
height: 0;
width: 0;
top:20px;
content:"";
position:absolute;
}
#footer:before{
border-bottom: 40px solid grey;
border-left: 500px solid transparent;
height: 0;
width: 0;
top:10px;
content:"";
position:absolute;
}