I'm trying to get this background image to reapply itself to cover a div container. I want it to remain the same size so that it doesn't become 'zoomed in' when the screen scale changes. However, at present, it's just zooming in and not remaining the same size:
.top-container {
background: background: -webkit-linear-gradient(70deg, #790c5a 30%, rgba(0,0,0,0) 30%), -webkit- linear-gradient(30deg, #cc0e74 60%, #e6739f 60%);
background: -o-linear-gradient(70deg, #790c5a 30%, rgba(0,0,0,0) 30%), -o-linear-gradient(30deg, #cc0e74 60%, #e6739f 60%);
background: -moz-linear-gradient(70deg, #790c5a 30%, rgba(0,0,0,0) 30%), -moz-linear-gradient(30deg, #cc0e74 60%, #e6739f 60%);
background: linear-gradient(70deg, #790c5a 30%, rgba(0,0,0,0) 30%), linear-gradient(30deg, #cc0e74 60%, #e6739f 60%);
padding-top: 5px;
padding-bottom: 5px;
text-align: center;
position: relative;
z-index: 1;
}
.top-container:before {
content: "";
background: url("./../images/skulls.PNG") no-repeat center center fixed;
background-repeat: no-repeat;
background-size: cover;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
background-position: center;
position: absolute;
top: 0px;
right: 0px;
bottom: 0px;
left: 0px;
opacity: 0.2;
width: 100%;
height: 100%;
}
Any advice?
EDIT: The image is already really small, so what I want is for it to remain the same size and just keep reapplying itself to fit the div. But instead of doing that, it's just zooming in, which distorts the image.
There are a couple of problems, the skull is not repeating, it is covering the whole div which means it looks 'fuzzy' as it's basically a small image. Also, be aware that IOS does not cope with background attachment fixed.
Taking out the no-repeats (there are several) and the fixed and just letting the skull show at its natural size we get an effect as in this snippet:
.top-container {
background: background: -webkit-linear-gradient(70deg, #790c5a 30%, rgba(0,0,0,0) 30%), -webkit- linear-gradient(30deg, #cc0e74 60%, #e6739f 60%);
background: -o-linear-gradient(70deg, #790c5a 30%, rgba(0,0,0,0) 30%), -o-linear-gradient(30deg, #cc0e74 60%, #e6739f 60%);
background: -moz-linear-gradient(70deg, #790c5a 30%, rgba(0,0,0,0) 30%), -moz-linear-gradient(30deg, #cc0e74 60%, #e6739f 60%);
background: linear-gradient(70deg, #790c5a 30%, rgba(0,0,0,0) 30%), linear-gradient(30deg, #cc0e74 60%, #e6739f 60%);
padding-top: 5px;
padding-bottom: 5px;
text-align: center;
position: relative;
z-index: 1;
width: 100vw;
height: 100vh;
}
.top-container:before {
content: "";
background: url("https://i.stack.imgur.com/B9QHI.png");
position: absolute;
top: 0px;
right: 0px;
bottom: 0px;
left: 0px;
opacity: 0.2;
width: 100%;
height: 100%;
}
<div class="top-container"></div>
Related
I'm struggling to figure out why this anchor tag link won't work when I add a background image to tge pesudo element of the div container.
What's causing the link to break is the 'absolute' positioning of the pseudo element for 'contact-me'. But if I remove that, I lose the image. How do I keep the image and get the anchor tag link to work? Any suggestions?
HTML:
<div id="contact-me">
<h2>Contact</h2>
<h3><a class="btn" href = "mailto:email#gmail.com">email#gmail.com</a></h3>
</div>
CSS:
#contact-me {
background: background: -webkit-linear-gradient(70deg, #e6739f 30%, rgba(0,0,0,0) 30%), -webkit- linear-gradient(30deg, #cc0e74 60%, #790c5a 60%);
background: -o-linear-gradient(70deg, #e6739f 30%, rgba(0,0,0,0) 30%), -o-linear-gradient(30deg, #cc0e74 60%, #790c5a 60%);
background: -moz-linear-gradient(70deg, #e6739f 30%, rgba(0,0,0,0) 30%), -moz-linear-gradient(30deg, #cc0e74 60%, #790c5a 60%);
background: linear-gradient(70deg, #e6739f 30%, rgba(0,0,0,0) 30%), linear-gradient(30deg, #cc0e74 60%, #790c5a 60%);
color: #f5f5f5;
position: relative;
margin-top: 100px;
padding-top: 5px;
padding-bottom: 60px;
}
#contact-me:after {
content: "";
background: url("http://www.transparenttextures.com/patterns/cubes.png");
position: absolute;
top: 0px;
right: 0px;
bottom: 0px;
left: 0px;
opacity: 0.9;
width: 100%;
height: 100%;
}
.btn {
cursor: pointer;
color: #fffafa;
z-index: 5;
}
Any help would be massively apprciated!
Try, this:
.btn {
cursor: pointer;
color: #fffafa;
z-index: 5;
position:relative
}
Why did you insert background: background: under contact-me ID?
Make your .btn class position: relative;
Code below
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#contact-me {
background: -webkit-linear-gradient(70deg, #e6739f 30%, rgba(0,0,0,0) 30%), -webkit- linear-gradient(30deg, #cc0e74 60%, #790c5a 60%);
background: -o-linear-gradient(70deg, #e6739f 30%, rgba(0,0,0,0) 30%), -o-linear-gradient(30deg, #cc0e74 60%, #790c5a 60%);
background: -moz-linear-gradient(70deg, #e6739f 30%, rgba(0,0,0,0) 30%), -moz-linear-gradient(30deg, #cc0e74 60%, #790c5a 60%);
background: linear-gradient(70deg, #e6739f 30%, rgba(0,0,0,0) 30%), linear-gradient(30deg, #cc0e74 60%, #790c5a 60%);
color: #f5f5f5;
position: relative;
margin-top: 100px;
padding-top: 5px;
padding-bottom: 60px;
}
#contact-me:after {
content: "";
background: url("http://www.transparenttextures.com/patterns/cubes.png");
position: absolute;
top: 0px;
right: 0px;
bottom: 0px;
left: 0px;
opacity: 0.9;
width: 100%;
height: 100%;
}
.btn {
position: relative;
cursor: pointer;
color: #fffafa;
z-index: 5;
}
</style>
</head>
<body>
<div id="contact-me">
<h2>Contact</h2>
<h3><a class="btn" href = "mailto:email#gmail.com">email#gmail.com</a></h3>
</div>
</body>
</html>
I have tried so far.
body {
margin:0;
padding:20px;
background-color: #000;
}
.mobil-menu__icon {
height: 50px;
width: 50px;
background:
linear-gradient(to bottom, #fff 0%, #fff 20%, transparent 20%, transparent 100%),
linear-gradient(to bottom, transparent 0%, transparent 40%, #fff 40%, #fff 60%, transparent 60%, transparent 100%),
linear-gradient(to bottom, transparent 0%, transparent 80%, #fff 80%, #fff 100%);
}
<div class="mobil-menu__icon"></div>
Use only solid color in gradient and rely on background-size:
.mobil-menu__icon {
height: 50px;
width: 50px;
background:
/* position / width height */
linear-gradient(#fff,#fff) top left / 100% 20%,
linear-gradient(#fff,#fff) center left / 80% 20%,
linear-gradient(#fff,#fff) bottom left / 60% 20%,
red;
border:10px solid red;
background-repeat:no-repeat; /* Never forget this! */
}
<div class="mobil-menu__icon"></div>
With hover animation:
.mobil-menu__icon {
height: 50px;
width: 50px;
background:
linear-gradient(#fff,#fff) top left,
linear-gradient(#fff,#fff) center left,
linear-gradient(#fff,#fff) bottom left,
red;
background-size:
100% 20%,
80% 20%,
60% 20%;
border:10px solid red;
background-repeat:no-repeat;
transition:0.3s all;
}
.mobil-menu__icon:hover {
background-size:100% 20%;
}
<div class="mobil-menu__icon"></div>
And if you want with transparency:
.mobil-menu__icon {
height: 50px;
width: 50px;
background:
linear-gradient(red,red) 0 calc(1*100%/4) / 100% 20%,
linear-gradient(red,red) 0 calc(3*100%/4) / 100% 20%,
linear-gradient(red,red) 100% calc(2*100%/4) / 20% 20%,
linear-gradient(red,red) 100% calc(4*100%/4) / 40% 20%;
border:10px solid red;
background-repeat:no-repeat;
}
body {
background:repeating-linear-gradient(to right,white 0 5px,grey 10px);
}
<div class="mobil-menu__icon"></div>
You were also almost good with your code but you were missing the size and the repeat:
body {
margin: 0;
padding: 20px;
background-color: #000;
}
.mobil-menu__icon {
height: 50px;
width: 50px;
background:
linear-gradient(to bottom, #fff 0%, #fff 20%, transparent 20%, transparent 100%),
linear-gradient(to bottom, transparent 0%, transparent 40%, #fff 40%, #fff 60%, transparent 60%, transparent 100%),
linear-gradient(to bottom, transparent 0%, transparent 80%, #fff 80%, #fff 100%);
background-size:100% 100%,80% 100%, 60% 100%;
background-repeat:no-repeat;
}
<div class="mobil-menu__icon"></div>
Related question to get more details about the different values:
Using percentage values with background-position on a linear gradient
I do not know if this is even possible with only css. I want to make a circle with transparent horizontal lines and you can change size and position of each of these lines. Something like this png picture:
I did this so far, but it is not responsive it has not transparent lines inside, but you can move all lines freely.
.enjoy-css {
box-sizing: content-box;
width: 300px;
height: 300px;
position: absolute;
border: none;
border-radius: 150px;
background: linear-gradient(white, white), linear-gradient(white, white), linear-gradient(white, white), linear-gradient(white, white), linear-gradient(white, white)black;
background-repeat: no-repeat;
background-position: 90% 90%, 55% 75%, 90% 10%, 95% 30%, 90%;
background-origin: padding-box;
background-size: 124px 20px, 153px 20px, 124px 20px, 153px 20px, 80px 20px;
}
<div class="enjoy-css">
<span></span>
</div>
You can use svg to create the responsive shapes like below.
For this first you have to create the svg of your shape inside svg <symbol> tag so that you can use this later.
Then create a div having class enjoy-css and then use the previously created svg using <use>. Don't forget to give width="100%" to the <svg> for responsive purpose
svg.defs-only {
display: block;
position: absolute;
height: 0;
width: 0;
margin: 0;
padding: 0;
border: none;
overflow: hidden;
}
body {
background: gold;
}
.enjoy-css {
max-width: 400px;
}
<svg class="defs-only" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="400px" height="400px">
<symbol id="potofgold" >
<path fill-rule="evenodd" fill="rgb(0, 0, 0)"
d="M387.395,270.000 L154.000,270.000 L154.000,298.000 L374.370,298.000 C368.372,308.648 361.409,318.675 353.632,328.000 L103.000,328.000 L103.000,356.000 L325.121,356.000 C290.863,383.519 247.363,400.000 200.000,400.000 C89.543,400.000 0.000,310.457 0.000,200.000 C0.000,177.987 3.567,156.809 10.136,137.000 L263.000,137.000 L263.000,109.000 L21.855,109.000 C28.645,95.734 36.895,83.344 46.356,72.000 L238.000,72.000 L238.000,44.000 L74.879,44.000 C109.140,16.485 152.638,0.000 200.000,0.000 C310.457,0.000 400.000,89.543 400.000,200.000 C400.000,224.628 395.538,248.212 387.395,270.000 ZM326.000,187.000 L63.000,187.000 L63.000,215.000 L326.000,215.000 L326.000,187.000 Z"/>
</symbol>
</svg>
<div class="enjoy-css"><svg viewBox="0 0 400 400" width="100%"><use xlink:href="#potofgold"/></svg></div>
This is it:
body {
background: #aaa;
background: url(http://www.lorempixel.com/600/600/abstract); /* background to show transparency */
}
.circle {
max-width: 20em; /* Set the max diameter */
margin: 0 auto;
}
.circle span {
position: relative;
display: block;
padding-bottom: 100%;
}
.circle span::after {
content: "";
display: block;
position: absolute;
width: 100%;
top: 0;
bottom: 0;
border-radius: 50%;
background-image: linear-gradient(
black 10%,
transparent 10%,
transparent 18%,
black 18%,
black 28%,
transparent 28%,
transparent 36%,
black 36%,
black 45%,
transparent 45%,
transparent 55%,
black 55%,
black 64%,
transparent 64%,
transparent 72%,
black 72%,
black 82%,
transparent 82%,
transparent 90%,
black 90%
),
linear-gradient(to right, transparent 60%, black 60%),
linear-gradient(to right, transparent 70%, black 70%),
linear-gradient(
to right,
black 15%,
transparent 15%,
transparent 85%,
black 85%
),
linear-gradient(to left, transparent 60%, black 60%),
linear-gradient(to left, transparent 70%, black 70%);
background-size: 100%, 100% 20%, 100% 40%, 100% 20%, 100% 20%, 100% 20%;
background-position: top, top, top, 40%, 0 70%, 0 90%;
background-repeat: no-repeat;
}
<!DOCTYPE html>
<html>
<body>
<div class="circle">
<span></span>
</div>
</body>
</html>
does anyone knows a way to create a div with responsive width in shape of an inverted cone (see attached code snippet) only using css. Also this div needs to have a repeated background image (pattern).
I tried to use clipPath:
#div {
height: 100%;
width: 100%;
-webkit-clip-path: polygon(50% 90px, 100% 0%, 100% 100%, 0 100%, 0 0);
clip-path: polygon(50% 25%, 100% 0, 100% 100%, 0 100%, 0 0);
background: blue;
padding-top: 160px;
}
<div id="div"></div>
This works fine in Safari and Chrome but won't work in Mozilla, Opera or IE.
Is there a way to achieve for all relevant browsers?
Any help would be appreciated.
Use linear-gradient with side or corner values instead of fixed angles. You can make that shape with transforms too, but that'll require JS to make it responsive.
Fiddle
body {
background-color: blue;
margin: 0;
padding: 0;
}
div {
height: 150px;
width: 100%;
position: relative;
}
div:after, div:before {
content:"";
position: absolute;
height: inherit;
width: 50%;
}
div:before {
left: 0;
background: -webkit-linear-gradient(to bottom left, white 50%, transparent 50%);
background: -moz-linear-gradient(to bottom left, white 50%, transparent 50%);
background: -o-linear-gradient(to bottom left, white 50%, transparent 50%);
background: linear-gradient(to bottom left, white 50%, transparent 50%);
}
div:after {
right: 0;
background: -webkit-linear-gradient(to bottom right, white 50%, transparent 50%);
background: -moz-linear-gradient(to bottom right, white 50%, transparent 50%);
background: -o-linear-gradient(to bottom right, white 50%, transparent 50%);
background: linear-gradient(to bottom right, white 50%, transparent 50%);
}
<div></div>
You can set the div to have overflow hidden, and then set 2 pseudo elements with skew, one for each half
.test {
width: 400px;
height: 300px;
overflow: hidden;
position: relative;
}
.test:after, .test:before {
content: "";
position: absolute;
top: 0px;
width: 50%;
height: 100%;
}
.test:before {
left: 0px;
transform: skewY(15deg);
transform-origin: top left;
background: repeating-linear-gradient(-15deg, white 0px, lightblue 40px);
}
.test:after {
right: 0px;
transform: skewY(-15deg);
transform-origin: top right;
background: repeating-linear-gradient(15deg, white 0px, lightblue 40px);
}
<div class="test"></div>
Hi, I'm scratching my head over this one. I want to create a CSS gradient arrow like the one shown, and with the ability to define the fill of the red section as a percentage. The red block is just a solid colour.
From this JFiddle example I have made some progress on creating the green arrow, but the gradient on the triangle is in the wrong direction. I am still unsure of how to get the red block to fill up as a percentage of the green arrow. For example if the red portion is 90% I'm going to have to somehow create half a triangle. Help please :)
Example Code for the green arrow:
div.a3 {
width: 100px;
height: 50px;
position: relative;
margin: 50px;
background: -webkit-linear-gradient(top, #99c739 0%,#4eb739 100%);
background: -moz-linear-gradient(top, #99c739 0%, #4eb739 100%);
}
div.a3:after {
z-index: -1;
content: "";
display: block;
position: absolute;
right: -75px;
top: -50px;
margin: 50px;
height: 50px;
width: 50px;
-webkit-transform:rotate( -45deg );
-moz-transform:rotate( -45deg );
transform:rotate( -45deg );
background: -webkit-linear-gradient(135deg, #99c739 0%, #4eb739 50%, #ffffff 50%, #ffffff 100%);
background: -moz-linear-gradient(135deg, #99c739 0%, #4eb739 50%, #ffffff 50%, #ffffff 100%);
}
div{
width: 200px;
height: 100px;
margin: 50px 0;
position:relative;
background: #d72200;
background: -moz-linear-gradient(left, #d72200 0%, #d72200 20%, #9ac739 20%, #6bbe39 100%);
background: -webkit-gradient(linear, left top, right top, color-stop(0%,#d72200), color-stop(20%,#d72200), color-stop(20%,#9ac739), color-stop(100%,#6bbe39));
background: -webkit-linear-gradient(left, #d72200 0%,#d72200 20%,#9ac739 20%,#6bbe39 100%);
background: -o-linear-gradient(left, #d72200 0%,#d72200 20%,#9ac739 20%,#6bbe39 100%);
background: -ms-linear-gradient(left, #d72200 0%,#d72200 20%,#9ac739 20%,#6bbe39 100%);
background: linear-gradient(to right, #d72200 0%,#d72200 20%,#9ac739 20%,#6bbe39 100%);
}
div:after{
content:'';
width: 100px;
height: 100px;
position: absolute;
left: 100%;
top: 0;
background: #4eb739;
background: -moz-linear-gradient(45deg, #4eb739 0%, #6bbe39 50%, #6bbe39 100%);
background: -webkit-gradient(linear, left bottom, right top, color-stop(0%,#4eb739), color-stop(50%,#6bbe39), color-stop(100%,#6bbe39));
background: -webkit-linear-gradient(45deg, #4eb739 0%,#6bbe39 50%,#6bbe39 100%);
background: -o-linear-gradient(45deg, #4eb739 0%,#6bbe39 50%,#6bbe39 100%);
background: -ms-linear-gradient(45deg, #4eb739 0%,#6bbe39 50%,#6bbe39 100%);
background: linear-gradient(45deg, #4eb739 0%,#6bbe39 50%,#6bbe39 100%);
-moz-transform: scale(1) rotate(45deg) translate(0px, 0px) skew(0deg, 0deg);
-webkit-transform: scale(1) rotate(45deg) translate(0px, 0px) skew(0deg, 0deg);
-o-transform: scale(1) rotate(45deg) translate(0px, 0px) skew(0deg, 0deg);
-ms-transform: scale(1) rotate(45deg) translate(0px, 0px) skew(0deg, 0deg);
transform: scale(1) rotate(45deg) translate(0px, 0px) skew(0deg, 0deg);
z-index: -2;
margin: 0 0 0 -50px;
}
div:before{
content:'';
position:absolute;
top: 0;
right: 0;
height: 100%;
padding: 22px 0;
z-index: -1;
background: #fff;
margin: -22px 0;
width: 100%;
}
Below the code seems to create an arrow.
Is it what you are looking for ?
div.a3 {
width: 100px;
height: 50px;
position: relative;
margin: 50px;
background: -webkit-linear-gradient(left, #1e5799 0%,#2989d8 100%);
background: -moz-linear-gradient(left, #1e5799 0%, #2989d8 100%);
}
div.a3:after {
z-index: -1;
content: "";
display: block;
position: absolute;
right: -75px;
top: -50px;
margin: 50px;
height: 50px;
width: 50px;
background: #000;
transform:rotate( -45deg );
background: -webkit-linear-gradient(135deg, #1e5799 0%, #2989d8 50%, #ffffff 50%, #ffffff 100%);
background: -moz-linear-gradient(135deg, #1e5799 0%, #2989d8 50%, #ffffff 50%, #ffffff 100%);
}