How to set text and background on this div straight? The transform property is making it curved.
#paralelogram {
margin-left: 190px;
width: 200px;
height: 80px;
transform: skew(-30deg);
background-image: url('http://lorempixel.com/200/80/animals/8/');
position: relative;
overflow: hidden;
}
#cena {
font-size: 20px;
font-family: monospace;
font-weight: bold;
text-align: center;
vertical-align: middle;
position: absolute;
margin-left: 35px;
margin-top: 25px;
}
<div class="col-xs-12 volks">
<div id="paralelogram">
<p id="cena">136,380 Kn</p>
</div>
</div>
Use a pseudo for the image and then reverse the skew on it and the p with transform: skew(30deg);
#paralelogram {
margin-left: 190px;
width: 200px;
height: 80px;
transform: skew(-30deg);
position: relative;
overflow: hidden;
background: gray;
}
#paralelogram:before {
content: '';
width: 240px;
height: 100%;
top: 0;
left: -20px;
transform: skew(30deg);
background-image: url('http://lorempixel.com/240/80/animals/8/');
background-repeat: no-repeat;
position: absolute;
}
#cena {
font-size: 20px;
font-family: monospace;
font-weight: bold;
text-align: center;
vertical-align: middle;
position: absolute;
margin-left: 35px;
margin-top: 25px;
transform: skew(30deg);
}
<div class="col-xs-12 volks">
<div id="paralelogram">
<p id="cena">136,380 Kn</p>
</div>
</div>
An alternative idea is to use clip-path to mask out the parallelogram shape rather than transform:skew. One current caveat is limited browser compatibility.
My example is based on Harry's answer to "Shape with a slanted side (responsive)":
#parallelogram {
position: relative;
width: 240px;
height: 80px;
line-height: 80px;
text-align: center;
color: red;
background-color: grey;
background-image: url(http://lorempixel.com/g/240/80/);
-webkit-clip-path: polygon(20% 0%, 100% 0%, 80% 100%, 0% 100%);
clip-path: polygon(20% 0%, 100% 0%, 80% 100%, 0% 100%);
}
<div id="parallelogram">136,380 Kn</div>
Related
I know there are many different ways to draw in CSS but I want to draw this shape using CSS ::before and ::after pseudo-elements.
Only the yellow part I could not draw it.
.body{
width:100%;
height:100%;
background:#191919;
display: flex;
justify-content: center;
align-items: center;
}
.circle {
position: relative;
width: 160px;
height: 160px;
background: #824B20;
border-radius: 50%;
}
.circle::before{
content: "";
width: 100px;
height: 100px;
background: #E08027;
position: absolute;
border-radius: 50%;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
}
.circle::after{
content:"";
/*color : #FFF58F */
}
<div class="body"><div class="circle";div><div><div>
An idea using only gradients:
.box {
width: 200px;
aspect-ratio:1;
border-radius: 50%;
background:
radial-gradient(circle at 78% 50%, yellow 4%,#0000 4.5%),
radial-gradient(circle at 22% 50%, yellow 4%,#0000 4.5%),
radial-gradient(at top,#0000 33%,yellow 34% 45%,#0000 46%)
bottom/100% 50% no-repeat,
radial-gradient(#E08027 40%,#824B20 41%);
}
<div class="box"></div>
.body {
width: 100%;
height: 100vh;
background: #191919;
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
}
.circle {
box-sizing: border-box;
position: relative;
width: 160px;
height: 160px;
background: #E08027;
border: 30px solid #824B20;
border-radius: 50%;
}
.half-circle {
position: absolute;
width: 85px;
height: 85px;
border: 14px solid #FFF58F;
border-top-color: transparent;
border-left-color: transparent;
border-radius: 50%;
top: 50%;
left: 50%;
transform: translate(-50%, -50%) rotate(45deg);
}
.half-circle::before,
.half-circle::after {
content: "";
position: absolute;
top: 69px;
width: 14px;
height: 14px;
border-radius: 50%;
background: #FFF58F;
}
.half-circle::before {
left: 0;
}
.half-circle::after {
left: 71px;
transform: translate(-2px, -70px);
}
<div class="body">
<div class="circle">
<div class="half-circle"></div>
</div>
</div>
I'm trying to make it where the percentage text and loading text stays in the middle of the loader when I resize. The width change works when I resize the window, but when I change the height it moves the text. I'm not sure why this is happening but if someone is able to help me under why this is happening that would be nice.
CSS:
<style type="text/css">
html {
height: 100%;
width: 100%;
}
body {
background: url("https://cdn.cporigins.com/site/images/bg.jpg");
margin: 0;
}
.container {
display: none;
position: relative;
font-family: 'Do Hyeon', sans-serif;
font-size: 27px;
}
.middle {
position: absolute;
top: 50%;
left: 50%;
bottom: 50px;
transform: translate(-50%, -50%);
text-align: center;
}
hr {
margin: auto;
width: 40%;
border: 0;
height: 1px;
background: #333;
background-image: linear-gradient(to right, #ccc, #333, #ccc);
}
a {
text-decoration: none;
}
a:hover {
color: #add8e6;
}
i#heart-icon {
height: 18px;
width: 18px;
background-image: url(https://cdn.cporigins.com/site/images/heart_icon.png);
background-repeat: no-repeat;
}
i#heart-icon:before {
content: "";
padding-right: 18px;
}
.loader {
font-size: 10px;
margin: 50px auto;
border: 16px solid #f3f3f3;
border-top: 16px solid #6294f9;
border-radius: 50%;
width: 120px;
height: 120px;
animation: spin 2s linear infinite;
background-repeat: no-repeat;
position: relative;
bottom: -32%;
}
#keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
#loadingDiv {
position: relative;
top: -50px;
left: 0;
width: 100%;
height: 100%;
background: #8360c3;
background: -webkit-linear-gradient(to top, #2ebf91, #8360c3);
background: linear-gradient(to top, #2ebf91, #8360c3);
}
#loaderTxt {
position: relative;
color: white;
font-size: 32px;
font-family: 'Do Hyeon', sans-serif;
top: 297px;
font-weight: bold;
text-align: center;
}
#loaderPercent {
position: relative;
color: white;
font-size: 32px;
font-family: 'Do Hyeon', sans-serif;
top: 128px;
font-weight: bold;
text-align: center;
}
</style>
I basically have it where it appends the divs to the html tag in js.
$('html').append('<div id="loadingDiv"><div class="loader"></div><div id="loaderTxt">Initializing Origins</div><div id="loaderPercent">0%</div></div>');
In these type of design you got to put the container to flex and center all items ( make it relative too )... Now make all items inside it absolutely positioned ... Here all items will come to the center ( of that container )... Viola, You will never get a problem of putting out the elements based on px size ever again..
html {
height: 100%;
width: 100%;
}
body {
background: url("https://cdn.cporigins.com/site/images/bg.jpg");
margin: 0;
}
#loadingDiv {
display: flex;
justify-content: center;
align-items: center;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: #8360c3;
background: -webkit-linear-gradient(to top, #2ebf91, #8360c3);
background: linear-gradient(to top, #2ebf91, #8360c3);
}
.loader {
font-size: 10px;
margin: 50px auto;
border: 16px solid #f3f3f3;
border-top: 16px solid #6294f9;
border-radius: 50%;
width: 120px;
height: 120px;
animation: spin 2s linear infinite;
background-repeat: no-repeat;
position: relative;
}
#keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
#loaderTxt {
position: absolute;
color: white;
font-size: 32px;
font-family: 'Do Hyeon', sans-serif;
bottom: 10vh;
font-weight: bold;
text-align: center;
}
#loaderPercent {
position: absolute;
color: white;
font-size: 32px;
font-family: 'Do Hyeon', sans-serif;
font-weight: bold;
text-align: center;
}
<div id="loadingDiv">
<div class="loader"></div>
<div id="loaderTxt">Initializing Origins</div>
<div id="loaderPercent">0%</div>
</div>
Try to end your css alignment line with !important
so if you want to align this html text
<p>THIS IS MY TEXT</p>
You can use css like this
p{text-align:center !important;}
I hope this answer helps.
I have a project:
Codepen
When I change browser size the letters climb to each other.
I need to find the way to lock the spaces between them. The letters has to be done like it is, I mean polygon. What to do to implant the letters to the divs, and has always the same spaces between them?
<!DOCTYPE html>
<html lang="en">
<head>
<style>
.flexContainer {
height: 100vh;
width: 100vw;
display: flex;
justify-content: center;
align-items: center;
position: relative;
background: pink;
}
.letsPlay {
display: flex;
height: 50%;
width: 50%;
border: 2px solid red;
flex-wrap: wrap;
}
#lFirstLine {
position: relative;
background: lightgreen;
height: 50%;
width: 25%;
}
#eFirstLine {
position: relative;
background: green;
height: 50%;
width: 25%;
}
#tFirstLine {
position: relative;
background: lightgreen;
height: 50%;
width: 25%;
}
#sFirstLine {
position: relative;
background: green;
height: 50%;
width: 25%;
}
#pSecondLine {
position: relative;
background: CornflowerBlue;
width: 20%;
height: 50%;
}
#lSecondLine {
position: relative;
background: blue;
width: 20%;
height: 50%;
}
#aSecondLine {
position: relative;
background: CornflowerBlue;
width: 20%;
height: 50%;
}
#ySecondLine {
position: relative;
background: blue;
width: 20%;
height: 50%;
}
#exclamationMarkSecondLine {
position: relative;
background: CornflowerBlue;
width: 20%;
height: 50%;
}
.lFirst {
position: absolute;
background: black;
}
.lFirst.square {
right: 42px;
bottom: 7px;
height: 24px;
width: 24px;
transform: rotate(-45deg);
}
.lFirst.parallelogram {
right: 17px;
bottom: 1px;
height: 24px;
width: 24px;
transform: skew(-45deg);
}
.lFirst.triangleSmall1 {
right: 55px;
bottom: 1px;
height: 16.92px;
width: 33.84px;
clip-path: polygon(0% 100%, 100% 100%, 50% 0%);
}
.lFirst.triangleSmall2 {
right: -7px;
bottom: -2px;
height: 16.92px;
width: 33.84px;
transform: rotate(135deg);
clip-path: polygon(0% 100%, 100% 100%, 50% 0%);
}
.lFirst.triangleMiddle {
right: 57px;
bottom: 86px;
height: 24px;
width: 48px;
transform: rotate(-45deg);
clip-path: polygon(0% 100%, 100% 100%, 50% 0%);
}
.lFirst.triangleBig1 {
right: 39px;
bottom: 19px;
height: 33.84px;
width: 67.68px;
transform: rotate(90deg);
clip-path: polygon(0% 100%, 100% 100%, 50% 0%);
}
.lFirst.triangleBig2 {
right: 38px;
bottom: 54px;
height: 33.84px;
width: 67.68px;
transform: rotate(-90deg);
clip-path: polygon(0% 100%, 100% 100%, 50% 0%);
}
.e {
position: absolute;
background: black;
}
.e.square {
right: 51px;
bottom: 36px;
height: 24px;
width: 24px;
transform: rotate(-90deg);
}
.e.parallelogram {
right: 32px;
bottom: 75px;
height: 24px;
width: 24px;
transform: skew(-45deg);
}
.e.triangleSmall1 {
right: 69px;
bottom: 41px;
height: 16.92px;
width: 33.84px;
transform: rotate(270deg);
clip-path: polygon(0% 100%, 100% 100%, 50% 0%);
}
.e.triangleSmall2 {
right: 8px;
bottom: -3px;
height: 16.92px;
width: 33.84px;
transform: rotate(135deg);
clip-path: polygon(0% 100%, 100% 100%, 50% 0%);
}
.e.triangleMiddle {
right: 20px;
bottom: 0px;
height: 24px;
width: 48px;
transform: rotate(-180deg);
clip-path: polygon(0% 100%, 100% 100%, 50% 0%);
}
.e.triangleBig1 {
right: 49px;
bottom: -5px;
height: 33.84px;
width: 67.68px;
transform: rotate(225deg);
clip-path: polygon(0% 100%, 100% 100%, 50% 0%);
}
.e.triangleBig2 {
right: 49px;
bottom: 70px;
height: 33.84px;
width: 67.68px;
transform: rotate(-45deg);
clip-path: polygon(0% 100%, 100% 100%, 50% 0%);
}
</style>
</head>
<body>
<div class="flexContainer">
<div class=letsPlay>
<div id=lFirstLine>
<div class="lFirst square"></div>
<div class="lFirst parallelogram"></div>
<div class="lFirst triangleSmall1"></div>
<div class="lFirst triangleSmall2"></div>
<div class="lFirst triangleMiddle"></div>
<div class="lFirst triangleBig1"></div>
<div class="lFirst triangleBig2"></div>
</div>
<div id=eFirstLine>
<div class="e square"></div>
<div class="e parallelogram"></div>
<div class="e triangleSmall1"></div>
<div class="e triangleSmall2"></div>
<div class="e triangleMiddle"></div>
<div class="e triangleBig1"></div>
<div class="e triangleBig2"></div>
</div>
<div id=tFirstLine></div>
<div id=sFirstLine></div>
<div id=pSecondLine></div>
<div id=lSecondLine></div>
<div id=aSecondLine></div>
<div id=ySecondLine></div>
<div id=exclamationMarkSecondLine></div>
</div>
</div>
Because the width on .letsPlay is a percentage, the boxes containing the letters will continue to shrink with the browser, and the letters will eventually push together.
To fix this, try a width of 500px or something similar on your .letsPlay element. Unfortunately, you'll need another solution if you want all your letters to fit in on devices thinner than 500px.
you can hard code a width in, instead of with a %. Change it from width-right: 500% to width-right: 500px - or whatever you want it to be
I have a div with a background image, what I would like to do, is when I hover over it, the hidden part of background-image to display like in the example below:
My jsfiddle example:
div.test {
background: url(http://media2.intoday.in/indiatoday/images/Photo_gallery/emraan_012315020812.jpg);
background-size: cover;
width: 70px;
height: 70px;
background-position: center;
border-radius: 100%;
display: inline-block;
transition: all 1s;
position: absolute;
top: 100px;
}
.test:hover{
transform: scale(1.2);
}
body {
text-align: center;
}
<div class="test">
</div>
As you can see, in my example the image is just getting larger, instead I want to display another 20px of the image (without compromising border-radius).
Example with one html element:
div.test {
background: url(http://media2.intoday.in/indiatoday/images/Photo_gallery/emraan_012315020812.jpg) no-repeat 50% 50%;
background-size: 140px;
width: 70px;
height: 70px;
background-position: center;
border-radius: 100%;
display: inline-block;
transition: all 1s;
position: absolute;
top: 100px;
transform-origin: center center;
}
.test:hover{
width: 90px;
height: 90px;
margin-left: -10px;
margin-top: -10px;
}
body {
text-align: center;
}
<div class="test">
</div>
Example with clip-path and shape-inside:
div.test {
background: url(http://media2.intoday.in/indiatoday/images/Photo_gallery/emraan_012315020812.jpg) no-repeat 50% 50%;
background-size: cover;
shape-inside: circle(30% at 50% 50%);
clip-path: circle(30% at 50% 50%);
-webkit-clip-path: circle(30% at 50% 50%);
width: 70px;
height: 70px;
background-position: center;
display: inline-block;
transition: all 1s;
position: absolute;
top: 100px;
transform-origin: center center;
}
.test:hover{
shape-inside: circle(50% at 50% 50%);
clip-path: circle(50% at 50% 50%);
-webkit-clip-path: circle(50% at 50% 50%);
}
body {
text-align: center;
}
<div class="test">
</div>
you might oversize a bit the background image
(background-size:auto 90px;) and add some padding and reset position on hover (.test:hover{padding:10px; margin:-10px;})
those rules are suppose to be understood by most of actual browsers if not all.
div.test {
background: url(http://media2.intoday.in/indiatoday/images/Photo_gallery/emraan_012315020812.jpg);
background-size:auto 90px;
width: 70px;
height: 70px;
background-position: center;
border-radius: 100%;
display: inline-block;
transition: all 1s;
position: absolute;
top: 100px;
}
.test:hover{
padding:10px;
margin:-10px;;
}
body {
text-align: center;
}
<div class="test">
</div>
another possibility is to use an inset shadow
div.test {
background: url(http://media2.intoday.in/indiatoday/images/Photo_gallery/emraan_012315020812.jpg);
background-size: auto 90px;
width: 90px;
height: 90px;
/* hide buggy ff render */
background-clip: content-box;
padding: 1px;
/* end fix ff */
background-position: center;
border-radius: 100%;
display: inline-block;
transition: all 1s;
position: absolute;
top: 90px;
box-shadow: inset 0 0 0 10px white;
}
.test:hover {
box-shadow: inset 0 0 0 0px white;
}
body {
text-align: center;
}
<div class="test">
</div>
There is also : padding, box-sizing and background-clip
div.test {
background: url(http://media2.intoday.in/indiatoday/images/Photo_gallery/emraan_012315020812.jpg) ;
background-size: auto 90px;
width: 90px;
height: 90px;
padding: 10px;
background-clip:content-box;
box-sizing:border-box;
background-position: center;
border-radius: 100%;
display: inline-block;
transition: all 1s;
position: absolute;
top: 90px;
}
.test:hover {
padding:0px;
}
/* show transparency */
html {
min-height:100%;
text-align: center;
background:linear-gradient(45deg, gray, yellow,purple,lime,pink,turquoise, gray, yellow,purple,lime,pink,turquoise);
}
<div class="test"></div>
You are missing to remove border-radius property on the hover event:
div.test {
background: url(http://media2.intoday.in/indiatoday/images/Photo_gallery/emraan_012315020812.jpg);
background-size: cover;
width: 70px;
height: 70px;
background-position: center;
border-radius: 100%;
display: inline-block;
transition: all 1s;
position: absolute;
top: 100px;
}
.test:hover{
transform: scale(1.2);
border-radius: 0px;
}
body {
text-align: center;
}
<div class="test">
</div>
I am having a tricky(at least for me) problem with a div which is a flip card done purely in css. The front of the card shows an image and the back has a different image and a button. The problem is due to the fluid design I had to set the padding. Which places all of the text below the div
.card {
margin: 0 auto;
position: relative;
float: left;
padding-bottom: 25%;
width: 100%;
max-width: 600px;
}
.card__front,
.card__back {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.card__front,
.card__back {
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
-webkit-transition: -webkit-transform 0.7s;
transition: transform 0.7s;
}
.card__front {
background-image: url("http://i58.tinypic.com/mmu649.jpg");
padding-top: 56.25%;
background-size: cover;
-moz-background-size: cover;
background-position: center;
}
.card__back {
background-image: url("http://i58.tinypic.com/mmu649.jpg");
-webkit-transform: rotateY(-180deg);
transform: rotateY(-180deg);
padding-top: 56.25%;
background-size: cover;
-moz-background-size: cover;
background-position: center;
}
.card.effect__hover:hover .card__front {
-webkit-transform: rotateY(-180deg);
transform: rotateY(-180deg);
}
.card.effect__hover:hover .card__back {
-webkit-transform: rotateY(0);
transform: rotateY(0);
}
.card__text {
width: auto;
text-align: center;
height: 100%;
margin-top: -32%;
}
.button {
background-color: #000000;
text-indent: 0;
border: 1px solid #000000;
display: inline-block;
color: #ffffff;
font-family: Arial;
font-size: 21px;
font-weight: normal;
font-style: normal;
height: 69px;
line-height: 69px;
width: 200px;
text-decoration: none;
text-align: center;
opacity: 0.8;
}
.button:hover {
background: -webkit-gradient(linear, left top, left bottom, color- stop(0.05, #000000), color-stop(1, #000000));
background: -moz-linear-gradient(center top, #000000 5%, #000000 100%);
filter: progid: DXImageTransform.Microsoft.gradient(startColorstr='#000000', endColorstr='#000000');
background-color: #000000;
}
.button:active {
position: relative;
top: 1px;
}
<div class="card effect__hover">
<div class="card__front">
<div class="card__text"></div>
</div>
<div class="card__back">
<div class="card__text"> see more
</div>
</div>
</div>
<!-- /card -->
Here is the preview of the code: http://jsfiddle.net/j29mvoLm/
All I am trying to get is to center the same button in every card like div.
Is it possible to do it without using negative margin?
This should do you justice:
.element {
position: relative;
top: 50%;
transform: translateY(-50%);
}
or
display: table-cell;
vertical-align: middle;
It is possible. See snippet. This answer uses nested relative and absolute positioned elements and also utilized box-sizing:border-box; and padding to maintain aspect ratio.
If you need to to set a max-width, add another wrapper element around your card and set the max-width on that element.
.card-wrapper {
margin: auto;
max-width: 600px;
}
.card {
box-sizing: border-box;
margin: auto;
padding: 28.125% 50%; /* 16:9 aspect ratio */
position: relative;
width: 100%;
}
.card__front, .card__back {
bottom: 0;
height: 100%;
left: 0;
margin: auto;
position: absolute;
right: 0;
top: 0;
width: 100%;
}
.card__front, .card__back {
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
-webkit-transition: -webkit-transform 0.7s;
transition: transform 0.7s;
}
.card__front {
background-image: url("http://i58.tinypic.com/mmu649.jpg");
background-size: cover;
-moz-background-size: cover;
background-position: center;
}
.card__back {
background-image: url("http://i58.tinypic.com/mmu649.jpg");
-webkit-transform: rotateY(-180deg);
transform: rotateY(-180deg);
background-size: cover;
-moz-background-size: cover;
background-position: center;
}
.card.effect__hover:hover .card__front {
-webkit-transform: rotateY(-180deg);
transform: rotateY(-180deg);
}
.card.effect__hover:hover .card__back {
-webkit-transform: rotateY(0);
transform: rotateY(0);
}
.card__text {
height: 100%;
position: relative;
text-align: center;
width: 100%;
}
.button {
background-color: #000000;
border: 1px solid #000000;
bottom: 0;
color: #ffffff;
display: block;
font-family: Arial;
font-size: 21px;
font-style: normal;
font-weight: normal;
height: 69px;
left: 0;
line-height: 69px;
margin: auto;
opacity: 0.8;
position: absolute;
right: 0;
text-align: center;
text-decoration: none;
text-indent: 0;
top: 0;
width: 200px;
}
.button:hover {
background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #000000), color-stop(1, #000000) );
background:-moz-linear-gradient( center top, #000000 5%, #000000 100% );
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#000000', endColorstr='#000000');
background-color:#000000;
}
.button:active {
position:relative;
top:1px;
}
<div class="card-wrapper">
<div class="card effect__hover">
<div class="card__front">
<div class="card__text"></div>
</div>
<div class="card__back">
<div class="card__text"> see more </div>
</div>
</div><!-- /card -->
</div>