Footer div with slated edge and border - html

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;
}
​

Related

Flipbox is displaying warped skewed image on hover in Chrome

Someone coded a flip box with CSS transform. It works fine in Safari and Firefox, but not in Chrome. In Chrome it continues to display the image and skews it. I tried several things in the CSS (labeled "Extra Code START") but it's not working. How do I just make the image disappear or fix this?
I made a codepen:
https://codepen.io/harmjoy/pen/ExwVarv
.collection-type-index #call-to-actions {
background:rgba(2,139,255,1)
}
.collection-type-index #our-programs-1 {
background:#f0f0f0
}
.flip {
margin: 30px auto;
position: relative;
width: 300px;
height: 200px;
color: #000;
text-align:center;
}
.flip h1 {
font-size: 30px;
font-weight: bold;
line-height:98px;
margin:0;
padding:0;
}
.flip h2 {
font-size: 21px;
font-weight: bold;
margin: 0;
padding: 0 0 12px;
}
.flip p {
font-size: 14px;
padding: 5px 0px;
margin: 0 0 8px 0;
}
.default-state, .active-state {
height: 200px;
position: absolute;
left: 0;
top: 0;
transition: transform 0.4s ease;
transform-origin: center center -50px;
-webkit-transform-origin: center center -50px;
width: 100%;
display: flex;
flex-direction: column;
justify-content: center;
}
.default-state {
transform: perspective(1000px) rotateX(0deg) rotateY(0deg) rotateZ(0deg);
-webkit-transform: perspective(1000px) rotateX(0deg) rotateY(0deg) rotateZ(0deg);
-moz-transform: perspective(1000px) rotateX(0deg) rotateY(0deg) rotateZ(0deg);
-o-transform: perspective(1000px) rotateX(0deg) rotateY(0deg) rotateZ(0deg);
-ms-transform: perspective(1000px) rotateX(0deg) rotateY(0deg) rotateZ(0deg);
height: 100%;
display: flex;
}
.default-state img {
position: relative;
flex-shrink: 0;
}
.default-state h2 {
position: absolute;
z-index: 2;
color: #fff;
text-transform: uppercase;
width: 100%;
align-self: center;
text-shadow: 0px 1px 10px rgba(0, 0, 0, 1);
}
.active-state {
transform: perspective(1000px) rotateX(-90deg) rotateY(0deg) rotateZ(0deg);
-webkit-transform: perspective(1000px) rotateX(-90deg) rotateY(0deg) rotateZ(0deg);
-moz-transform: perspective(1000px) rotateX(-90deg) rotateY(0deg) rotateZ(0deg);
-o-transform: perspective(1000px) rotateX(-90deg) rotateY(0deg) rotateZ(0deg);
-ms-transform: perspective(1000px) rotateX(-90deg) rotateY(0deg) rotateZ(0deg);
}
.flip:hover .default-state {
height:200px;
width:300px;
transform: perspective(0px) rotateX(90deg) rotateY(0) rotateZ(0deg);
-webkit-transform: perspective(0px) rotateX(90deg) rotateY(0) rotateZ(0deg);
-moz-transform: perspective(0px) rotateX(90deg) rotateY(0) rotateZ(0deg);
-o-transform: perspective(0px) rotateX(90deg) rotateY(0) rotateZ(0deg);
-ms-transform: perspective(0px) rotateX(90deg) rotateY(0) rotateZ(0deg);
}
.flip:hover .active-state {
height:200px;
width:300px;
z-index: 99999;
transform: perspective(1000px) rotateX(0deg) rotateY(0deg) rotateZ(0);
-webkit-transform: perspective(1000px) rotateX(0deg) rotateY(0deg) rotateZ(0);
-moz-transform: perspective(1000px) rotateX(0deg) rotateY(0deg) rotateZ(0);
-o-transform: perspective(1000px) rotateX(0deg) rotateY(0deg) rotateZ(0);
-ms-transform: perspective(1000px) rotateX(0deg) rotateY(0deg) rotateZ(0);
}
/* Extra Code START */
.flip:hover .active-state,
.flip:hover .default-state {
transform-origin: none;
-webkit-transform-origin: none !important;
}
.flip:hover .active-state img,
.flip:hover .default-state img {
display: none !important;
}
/* Extra Code END */
a.btn {
background: #013b59;
color: #ffffff;
font-size: 14px;
padding: 8px 20px 8px 20px;
text-decoration: none;
}
a.btn:hover {
background: #33627a;
text-decoration: none;
}
.blog-item-wrapper .post-title { display: none; }
<div class="flip" id="yui_3_17_2_1_1638546693755_910">
<div class="active-state" id="yui_3_17_2_1_1638546693755_909">
<h2>Hope After School</h2>
<a class="btn" href="/hope-after-school" id="yui_3_17_2_1_1638546693755_908">Learn More</a>
</div>
<div class="default-state">
<h2>After-School Programs</h2>
<img src="https://static1.squarespace.com/static/5b0ff9af3e2d099669c3dc55/5b1001a688251b1ccbfd906e/5b1004112b6a28f09dc1af7d/1527776479763/child-865116_1920.jpg?format=750w" alt="Childcare">
</div>
</div>
In my chrome browser there indeed was some strange artefact of the image visible although not recognisable as the image anymore. I fixed it with * { backface-visibility: hidden; } out of laziness, which worked fine but you would probably want to apply this only to the elements being transformed. backface-visibilty precisely handles the see-throughness os 3D elements which is what you are dealing with here.

Add text in CSS chevron shape

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>

Styling breaks after using anchor tag

I'm trying to put some images in a decorative way, however, I can't seem to get the code to work properly mainly on the CSS side. I'm pretty sure I'm doing something wrong with the selectors and was wondering if someone would be willing to take a look at it.
It seems that the code breaks when I add the <a> tag but I would really like to include the link to the images.
Broken code with <a> tag: JSFiddle
Working code without <a> for reference: JSFiddle
I'm hoping I can get the one with the <a> tag working.
.photos img {
position: absolute;
-webkit-transition: all 0.5s ease-out;
-moz-transition: all 0.5s ease-out;
-o-transition: all 0.5s ease-out;
transition: all 0.5s ease-out;
padding: 10px 10px 30px 10px;
background: white;
border: solid 1px black;
}
.photos img:nth-of-type(1) {
left: 50px;
top: 50px;
-webkit-transform: rotate(5deg);
-moz-transform: rotate(5deg);
-o-transform: rotate(5deg);
transform: rotate(5deg);
}
.photos img:nth-of-type(2) {
left: 150px;
top: 100px;
-webkit-transform: rotate(-10deg);
-moz-transform: rotate(-10deg);
-o-transform: rotate(-10deg);
transform: rotate(-10deg);
}
.photos img:nth-of-type(3) {
left: 250px;
top: 50px;
-webkit-transform: rotate(7deg);
-moz-transform: rotate(7deg);
-o-transform: rotate(7deg);
transform: rotate(7deg);
}
.photos img:nth-of-type(4) {
left: 350px;
top: 150px;
-webkit-transform: rotate(-3deg);
-moz-transform: rotate(-3deg);
-o-transform: rotate(-3deg);
transform: rotate(-3deg);
}
.photos img:nth-of-type(5) {
left: 450px;
top: 50px;
-webkit-transform: rotate(2deg);
-moz-transform: rotate(2deg);
-o-transform: rotate(2deg);
transform: rotate(2deg);
}
.photos img:hover {
-webkit-transform: scale(1.5);
-moz-transform: scale(1.5);
-o-transform: scale(1.5);
transform: scale(1.5);
z-index: 10;
-webkit-transform: rotate(380deg) scale(1.5);
-moz-transform: rotate(380deg) scale(1.5);
-o-transform: rotate(380deg) scale(1.5);
transform: rotate(380deg) scale(1.5);
z-index: 10;
}
<div class="photos">
<img src="https://lorempixel.com/160/220"/>
<img src="https://lorempixel.com/160/220"/>
<img src="https://lorempixel.com/160/220"/>
<img src="https://lorempixel.com/160/220"/>
<img src="https://lorempixel.com/160/220"/>
</div>
You're using nth-of-type(1) to place the images, but because they are now children of anchor tags, they're all the first child. Therefore they will all be placed in the same location and get the .photos img:nth-of-type(1) CSS.
Try doing it like this instead:
.photos a:nth-of-type(1) img {
left: 50px;
top: 50px;
-webkit-transform: rotate(5deg);
-moz-transform: rotate(5deg);
-o-transform: rotate(5deg);
transform: rotate(5deg);
}
Full result: https://jsfiddle.net/kLnn2jLu/4/

HTML elements gets distorted after including bootstrap

I am a learning HTML/CSS. I have made two simple circles and a rotating element in between. Afterwards, I decided to use bootstrap for decorating subsequent elements. However, as soon as I include the link to bootstrap, the circles get distorted and the animation is ruined.
Also, if I remove the statement overflow: hidden, on re-sizing the browser, the scroll bar starts to behave erratically. If I let it be, I am not able to insert further content down the window.
Please help!
Here is my code:
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=0.5">
<!--<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> -->
<style>
* {
margin: 0;
padding: 0;
}
html,
body {
height: 100%;
margin: 0%;
}
body {
background-color: #080808;
overflow: hidden;
}
#spinner,
#spinner:before,
#spinner:after {
position: absolute;
top: 50%;
left: 50%;
background: none;
border-radius: 50%;
border: 5px solid cyan;
}
#spinner {
height: 386px;
width: 386px;
margin: -208px;
border: 15px solid blue;
z-index: 1;
border-top: 15px solid red;
-webkit-animation: spin 1s ease-in-out infinite;
-moz-animation: spin 1s ease-in-out infinite;
-ms-animation: spin 1s ease-in-out infinite;
-o-animation: spin 1s ease-in-out infinite;
animation: spin 1s ease-in-out infinite;
}
#spinner:before {
content: "";
height: 372px;
width: 372px;
margin: -191px;
}
#spinner:after {
content: "";
width: 420px;
height: 420px;
margin: -215px;
}
#vline,
#hline,
#dline1,
#dline2 {
height: 420px;
position: absolute;
border-left: 1px solid cyan;
top: 50%;
left: 50%;
margin-top: -210px;
}
#hline {
-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);
-o-transform: rotate(90deg);
-ms-transform: rotate(90deg);
transform: rotate(90deg);
}
#dline1 {
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-o-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
}
#dline2 {
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
transform: rotate(-45deg);
}
#keyframes "spin" {
0% {
-webkit-transform: rotate(0deg);
-moz-transform: rotate(0deg);
-o-transform: rotate(0deg);
-ms-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
-moz-transform: rotate(360deg);
-o-transform: rotate(360deg);
-ms-transform: rotate(360deg);
transform: rotate(360deg);
}
}
#-moz-keyframes spin {
0% {
-moz-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-moz-transform: rotate(360deg);
transform: rotate(360deg);
}
}
#-webkit-keyframes "spin" {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
#-ms-keyframes "spin" {
0% {
-ms-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-ms-transform: rotate(360deg);
transform: rotate(360deg);
}
}
#-o-keyframes "spin" {
0% {
-o-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-o-transform: rotate(360deg);
transform: rotate(360deg);
}
}
</style>
<title>Test</title>
</head>
<body>
<div id="spinner"></div>
<div id="vline"></div>
<div id="hline"></div>
<div id="dline1"></div>
<div id="dline2"></div>
</body>
</html>
Bootstrap sets box-sizing: border-box; on everything.
Set box-sizing: content-box; on elements and pseudo-elements in your spinner:
* {
margin: 0;
padding: 0;
}
.spinner-container *,
.spinner-container :after,
.spinner-container :before {
box-sizing: content-box;
}
html,
body {
height: 100%;
margin: 0%;
}
body {
background-color: #080808!important;
overflow: hidden;
}
#spinner,
#spinner:before,
#spinner:after {
position: absolute;
top: 50%;
left: 50%;
background: none;
border-radius: 50%;
border: 5px solid cyan;
}
#spinner {
height: 386px;
width: 386px;
margin: -208px;
border: 15px solid blue;
z-index: 1;
border-top: 15px solid red;
-webkit-animation: spin 1s ease-in-out infinite;
-moz-animation: spin 1s ease-in-out infinite;
-ms-animation: spin 1s ease-in-out infinite;
-o-animation: spin 1s ease-in-out infinite;
animation: spin 1s ease-in-out infinite;
}
#spinner:before {
content: "";
height: 372px;
width: 372px;
margin: -191px;
}
#spinner:after {
content: "";
width: 420px;
height: 420px;
margin: -215px;
}
#vline,
#hline,
#dline1,
#dline2 {
height: 420px;
position: absolute;
border-left: 1px solid cyan;
top: 50%;
left: 50%;
margin-top: -210px;
}
#hline {
-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);
-o-transform: rotate(90deg);
-ms-transform: rotate(90deg);
transform: rotate(90deg);
}
#dline1 {
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-o-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
}
#dline2 {
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
transform: rotate(-45deg);
}
#keyframes "spin" {
0% {
-webkit-transform: rotate(0deg);
-moz-transform: rotate(0deg);
-o-transform: rotate(0deg);
-ms-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
-moz-transform: rotate(360deg);
-o-transform: rotate(360deg);
-ms-transform: rotate(360deg);
transform: rotate(360deg);
}
}
#-moz-keyframes spin {
0% {
-moz-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-moz-transform: rotate(360deg);
transform: rotate(360deg);
}
}
#-webkit-keyframes "spin" {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
#-ms-keyframes "spin" {
0% {
-ms-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-ms-transform: rotate(360deg);
transform: rotate(360deg);
}
}
#-o-keyframes "spin" {
0% {
-o-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-o-transform: rotate(360deg);
transform: rotate(360deg);
}
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="spinner-container">
<div id="spinner"></div>
<div id="vline"></div>
<div id="hline"></div>
<div id="dline1"></div>
<div id="dline2"></div>
</div>
EDIT: Scrollbar appears erratic because your #spinner pushes body out while spinning. To solve this problem put everything in container, set container's width and height, position it in the center and set overflow:hidden; on it. Also, mind media-queries for cases when display is smaller than spinner:
* {
margin: 0;
padding: 0;
}
.spinner-container *,
.spinner-container :after,
.spinner-container :before {
box-sizing: content-box;
}
.spinner-container {
overflow: hidden;
height: 430px;
width: 430px;
position: relative;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
}
#media (max-height: 430px) {
.spinner-container {
transform: translate(-50%,0);
top: 0;
}
}
#media (max-width: 430px) {
.spinner-container {
transform: translate(0,-50%);
left: 0;
}
}
#media (max-height:430px) and (max-width: 430px) {
.spinner-container {
transform: none;
left: 0;
top: 0;
}
}
html,
body {
height: 100%;
margin: 0%;
}
body {
background-color: #080808!important;
}
#spinner,
#spinner:before,
#spinner:after {
position: absolute;
top: 50%;
left: 50%;
background: none;
border-radius: 50%;
border: 5px solid cyan;
}
#spinner {
height: 386px;
width: 386px;
margin: -208px;
border: 15px solid blue;
z-index: 1;
border-top: 15px solid red;
-webkit-animation: spin 1s ease-in-out infinite;
-moz-animation: spin 1s ease-in-out infinite;
-ms-animation: spin 1s ease-in-out infinite;
-o-animation: spin 1s ease-in-out infinite;
animation: spin 1s ease-in-out infinite;
}
#spinner:before {
content: "";
height: 372px;
width: 372px;
margin: -191px;
}
#spinner:after {
content: "";
width: 420px;
height: 420px;
margin: -215px;
}
#vline,
#hline,
#dline1,
#dline2 {
height: 420px;
position: absolute;
border-left: 1px solid cyan;
top: 50%;
left: 50%;
margin-top: -210px;
}
#hline {
-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);
-o-transform: rotate(90deg);
-ms-transform: rotate(90deg);
transform: rotate(90deg);
}
#dline1 {
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-o-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
}
#dline2 {
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
transform: rotate(-45deg);
}
#keyframes "spin" {
0% {
-webkit-transform: rotate(0deg);
-moz-transform: rotate(0deg);
-o-transform: rotate(0deg);
-ms-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
-moz-transform: rotate(360deg);
-o-transform: rotate(360deg);
-ms-transform: rotate(360deg);
transform: rotate(360deg);
}
}
#-moz-keyframes spin {
0% {
-moz-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-moz-transform: rotate(360deg);
transform: rotate(360deg);
}
}
#-webkit-keyframes "spin" {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
#-ms-keyframes "spin" {
0% {
-ms-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-ms-transform: rotate(360deg);
transform: rotate(360deg);
}
}
#-o-keyframes "spin" {
0% {
-o-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-o-transform: rotate(360deg);
transform: rotate(360deg);
}
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="spinner-container">
<div id="spinner"></div>
<div id="vline"></div>
<div id="hline"></div>
<div id="dline1"></div>
<div id="dline2"></div>
</div>

Center css chevron in div

I have based this chevron off some code from here, and changed it to use it as navigation in a carousel. However, I'm struggling to center it in the gray area. Preferably it would be centered horizontally with a little padding to the edges.
I tried to wrap the chevron in another div, but with no success.
.chevron {
position: absolute;
text-align: center;
padding: 12px;
margin-bottom: 6px;
height: 44px;
width: 109px;
top: 242px;
background: #545454;
}
.chevron:hover:before,
.chevron:hover:after {
background: blue;
}
.chevron {
-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);
-ms-transform: rotate(90deg);
-o-transform: rotate(90deg);
transform: rotate(90deg);
}
.chevron:before,
.chevron:after {
content: '';
position: absolute;
top: 0;
height: 17%;
background: red;
}
.chevron:before {
left: 0;
width: 51%;
-webkit-transform: skew(0deg, 6deg);
-moz-transform: skew(0deg, 6deg);
-ms-transform: skew(0deg, 6deg);
-o-transform: skew(0deg, 6deg);
transform: skew(0deg, 6deg);
}
.chevron:after {
right: 0;
width: 50%;
-webkit-transform: skew(0deg, -6deg);
-moz-transform: skew(0deg, -6deg);
-ms-transform: skew(0deg, -6deg);
-o-transform: skew(0deg, -6deg);
transform: skew(0deg, -6deg);
}
<div class="chevron"></div>
What about this:
http://jsfiddle.net/8c2r3m5d/1/
To the :before and :after I added:
top:40%;
SHould be top because the entire chevron is rotated, this is why changing the top value makes it go left and right
I believe you were confused because the chevron is rotated 90 deg. If you remove that rotation, it is much easier to understand the positioning of the chevron elements :
.chevron {
position:relative;
height: 44px;
width: 109px;
background: #545454;
}
.chevron:before, .chevron:after {
content: '';
position: absolute;
top: 40%;
height: 17%;
background: red;
}
.chevron:before {
left: 5%;
width: 46%;
transform: skew(0deg, 6deg);
}
.chevron:after {
right: 5%;
width: 45%;
transform: skew(0deg, -6deg);
}
<div class="chevron"></div>
Note that I also removed the vendor prefixes for the transform property for the sake of this question.
Simply adjust the top offset as follows:
.chevron:before,.chevron:after {
top: 42%;
height: 17%;
}
The top offset value is 50% minus half of the height (8%). You actually are centering the chevron vertically since you have rotated it 90 degrees, hence it looks like it needs to be horizontally centered.
.chevron {
position: absolute;
text-align: center;
padding: 12px;
margin-bottom: 6px;
height: 44px;
width: 109px;
top: 50px;
background: #545454;
}
.chevron:hover:before,
.chevron:hover:after {
background: blue;
}
.chevron {
-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);
-ms-transform: rotate(90deg);
-o-transform: rotate(90deg);
transform: rotate(90deg);
}
.chevron:before,.chevron:after {
content: '';
position: absolute;
top: 42%;
height: 17%;
background: red;
}
.chevron:before {
left: 0;
width: 51%;
-webkit-transform: skew(0deg, 6deg);
-moz-transform: skew(0deg, 6deg);
-ms-transform: skew(0deg, 6deg);
-o-transform: skew(0deg, 6deg);
transform: skew(0deg, 6deg);
}
.chevron:after {
right: 0;
width: 50%;
-webkit-transform: skew(0deg, -6deg);
-moz-transform: skew(0deg, -6deg);
-ms-transform: skew(0deg, -6deg);
-o-transform: skew(0deg, -6deg);
transform: skew(0deg, -6deg);
}
<div class="chevron"></div>