Full page responsive background of nested divs - css

I made a BG made of CSS clipping in several divs (nested in .background) how do I configure the whole thing to be responsive? When I set width or height to 100% the background does not render at all.
body,
html {
margin: 0px;
}
.bg0 {
position: relative;
width: 1366px;
height: 675px;
background-color: #3B3B3B;
background-repeat: no-repeat;
background-size: cover;
background-position: center;
}
.bg1 {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: #333333;
background-repeat: no-repeat;
background-size: cover;
-webkit-clip-path: polygon(0 0, 80% 0, 35% 50%, 0 12%);
clip-path: polygon(0 0, 80% 0, 35% 50%, 0 12%);
}
.bg2 {
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: 100%;
background-color: #2D2D2D;
background-repeat: no-repeat;
background-size: cover;
-webkit-clip-path: polygon(0 12%, 0 86%, 35% 50%);
clip-path: polygon(0 12%, 0 86%, 35% 50%);
}
#wrapper {
position: relative;
width: 200px;
height: 200px;
}
.content {
position: relative;
}
.background {
position: absolute;
}
<div id="wrapper">
<div class="background">
<div class="bg0"></div>
<div class="bg1"></div>
<div class="bg2"></div>
</div>
<div class="content">
<h1>Content!!</h1>
</div>
</div>

First....Why are you using fixed width to the bg0 class and also you are giving width to bg0 class grater than its parent element #wrapper...
I don think it's required...Just set the width and height of .background class
Stack Snippet
body,
html {
margin: 0px;
}
.bg0 {
position: relative;
width: 100%;
height: 100%;
background-color: #3B3B3B;
background-repeat: no-repeat;
background-size: cover;
background-position: center;
}
.bg1 {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: #333333;
background-repeat: no-repeat;
background-size: cover;
-webkit-clip-path: polygon(0 0, 80% 0, 35% 50%, 0 12%);
clip-path: polygon(0 0, 80% 0, 35% 50%, 0 12%);
}
.bg2 {
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: 100%;
background-color: #2D2D2D;
background-repeat: no-repeat;
background-size: cover;
-webkit-clip-path: polygon(0 12%, 0 86%, 35% 50%);
clip-path: polygon(0 12%, 0 86%, 35% 50%);
}
#wrapper {
position: relative;
width: 200px;
height: 200px;
}
.content {
position: relative;
}
.background {
position: absolute;
top:0;
left:0;
width:100%;
height:100%;
}
<div id="wrapper">
<div class="background">
<div class="bg0"></div>
<div class="bg1"></div>
<div class="bg2"></div>
</div>
<div class="content">
<h1>Content!!</h1>
</div>
</div>

Related

View background with Border with 4 cuff-off corner

I am trying to give a div 4 cutoff corners
Like this
This is what I have done so far
But the problem with clip-path is that I can't get the background image present(in the body tag)enter image description here, I have to add the background image again in the innerWrap which does not look consistent.
is there any way to achieve the cut-off corner and without loosing the background image present in the body
.heroWrapper {
display: flex;
align-content: center;
justify-content: center;
padding: 0.06rem;
height: 100%;
background-color: v.$secondary;
clip-path: polygon(
0 0%,
10% 0,
90% 0,
100% 10%,
100% 90%,
90% 100%,
10% 100%,
0% 90%,
0% 10%
);
.heroInnerWrap {
width: 100%;
height: 100%;
margin: auto;
background: url("../bgImage.png");
background-size: contain;
clip-path: polygon(
0 0%,
10% 0,
90% 0,
100% 10%,
100% 90%,
90% 100%,
10% 100%,
0% 90%,
0% 10%
);
.borders {
position: absolute;
width: 15rem;
height: 15rem;
background: v.$primary;
}
}
.topright {
top: 0rem;
right: 0rem;
transform: rotate(45deg);
}
}
Just create a type of hexagon and mask it with it.
.hexagon {
top: 30vh;
left: 40%;
position: absolute;
margin: 0 auto;
background-color: blue;
border-radius: 10px;
width: 100px;
height: 63px;
box-sizing: border-box;
transition: all 1s;
border: 0.4vh solid transparent;
}
/* Creating pseudo-class */
.hexagon:before, .hexagon:after {
content: "";
border: inherit;
position: absolute;
top: -0.5vh;
left: -0.5vh;
background-color: dodgerblue;
border-radius: inherit;
height: 100%;
width: 100%;
}
/* Align them in such a way
that they form a hexagon */
.hexagon:before {
transform: rotate(60deg);
}
.hexagon:after {
transform: rotate(-60deg);
}
<!DOCTYPE html>
<html>
<head>
<title>
Draw a Curved Edge
Hexagon using CSS
</title>
<style>
</style>
</head>
<body style="text-align: center;">
<!-- Hexagon Division -->
<div class="hexagon"
id="hexagon">
</div>
</body>
</html>

Diagonal cut images with offset, working on all screen sizes

I need to achieve this block element:
Which can have elements on top/bottom. My problem is to keep the diagonal split always in line in any screen resolution.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
img {
display: inline-block;
width: 100%;
}
.content {
padding: 50px;
height: 50vh;
width: 100vw;
display: flex;
justify-content: center;
align-items: center;
}
.horizontalbar {
display: flex;
height: 500px;
width: 100%;
position: relative;
}
.horizontalbar img {
position: absolute;
-o-object-fit: cover;
object-fit: cover;
height: 100%;
width: calc(100% - 5vw);
}
.horizontalbar img.image1 {
left: 0;
top: 5vw;
-webkit-clip-path: polygon(0 0, calc(100% - 25vw) 0%, 25vw 100%, 0% 100%);
clip-path: polygon(0 0, calc(100% - 25vw) 0%, 25vw 100%, 0% 100%);
}
.horizontalbar img.image2 {
right: 0;
top: -5vw;
-webkit-clip-path: polygon(calc(100% - 25vw) 0, 100% 0%, 100% 100%, calc(25vw) 100%);
clip-path: polygon(calc(100% - 25vw) 0, 100% 0%, 100% 100%, calc(25vw) 100%);
}
<div class="content">
<div class="horizontalbar">
<img src="https://source.unsplash.com/900x1300/?women" alt="" class="image1">
<img src="https://source.unsplash.com/900x1400/?man" alt="" class="image2">
</div>
</div>
live codepen
I assume with some js to keep adjusting the clip according to the screensize, but what math/calculations need to be done here? Is there a better way to achieve this?
simplify your clip-path and control the background-position to create the top and bottom spaces:
.box {
display: flex;
height: 400px;
}
.box>div {
flex: 1;
}
.box>div:first-child {
margin-right: -10vw;
background: url(https://picsum.photos/id/1018/800/800) top 50px center /cover no-repeat;
clip-path: polygon(0 0, 100% 0, calc(100% - 20vw - 5px) 100%, 0 100%);
}
.box>div:last-child {
margin-left: -10vw;
background: url(https://picsum.photos/id/125/800/800) bottom 50px center /cover no-repeat;
clip-path: polygon(calc(20vw + 5px) 0, 100% 0, 100% 100%, 0 100%);
}
<div class="box">
<div></div>
<div></div>
</div>
Also like below:
.box {
display: flex;
height: 400px;
}
.box>div {
flex: 1;
position:relative;
}
.box > div::before {
content:"";
position:absolute;
left:0;
right:0;
height:calc(100% - 50px);
background: var(--i) center /cover no-repeat;
}
.box>div:first-child {
margin-right: -10vw;
clip-path: polygon(0 0, 100% 0, calc(100% - 20vw - 5px) 100%, 0 100%);
}
.box>div:first-child::before {
bottom:0;
}
.box>div:last-child {
margin-left: -10vw;
clip-path: polygon(calc(20vw + 5px) 0, 100% 0, 100% 100%, 0 100%);
}
.box>div:last-child::before {
top:0;
}
<div class="box">
<div style="--i:url(https://picsum.photos/id/1018/800/800)"></div>
<div style="--i:url(https://picsum.photos/id/125/800/800)"></div>
</div>

How do i add CSS repeat y to make border vertical

Need to align the css generated border vertically...how do i use background-repeat: repeat-y here :
.container::after {
position:absolute;
bottom: -50px;
left: 0px;
width: 100%;
content:" ";
background:
radial-gradient(circle at 50% 0%, white 25%, #535353 26%, gray 40%);
background-color: gray;
background-size:50px 100px;
height:50px;
background-repeat: repeat-x;
}
Thanks
You need to convert the vertical values to horizontal values, and vice versa:
.container {
position: relative;
width: 50%;
height: 100vh;
}
.container::after {
position: absolute;
right: -50px; /* bottom: -50px; */
top: 0; /* left: 0 */
width: 50px; /* width: 100% */
height: 100%; /* height: 50px; */
content: "";
background: radial-gradient(circle at 0% 50%, white 45%, #535353 46%, gray 60%);
background-color: gray;
background-size: 50px 50px; /* background-size: 50px 100px; */
background-repeat: repeat-y; /* background-repeat: repeat-x; */
}
<div class="container"></div>

Div with diagonal bottom border

How can I make a div with diagonal bottom and with border?
I know that I can use clip-path, but by this way I can't make a border (example: https://jsfiddle.net/s976/qopxf6mj/4/)
I saw "Creating a diagonal line/section/border with CSS" but it's not about enabling css border for diagonal container.
You can try the use of skew transformation like below:
.container {
width: 300px;
height: 200px;
background: url(https://picsum.photos/id/1002/800/800) center/cover;
overflow: hidden;
}
.box {
height: 70%;
border-bottom: 10px solid red;
transform: skewY(-15deg);
transform-origin: left;
position: relative;
overflow: hidden;
}
.box:before {
content: "";
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: url(https://picsum.photos/id/12/800/800) center/cover;
transform: skewY(15deg);
transform-origin: left;
}
<div class="container">
<div class="box">
</div>
</div>
Or clip-path combined with some gradient like below:
.container {
width: 300px;
height: 200px;
background: url(https://picsum.photos/id/1002/800/800) center/cover;
}
.box {
height: 70%;
border-bottom: 10px solid red;
background:
linear-gradient(to bottom right,transparent 49.5%,red 50%) bottom/100% 80px no-repeat,
url(https://picsum.photos/id/12/800/800) center/cover;
clip-path:polygon(0 0,100% 0, 100% calc(100% - 80px),0 100%)
}
<div class="container">
<div class="box">
</div>
</div>
You can optimze the last code to use only one element and some variables
.container {
width: 300px;
height: 200px;
background: url(https://picsum.photos/id/1002/800/800) center/cover;
--angle:80px; /* Control the angle*/
--thickness:10px; /* Control the thickness of the line */
}
.container:before{
content:"";
display:block;
height: 70%;
border-bottom: var(--thickness) solid red;
background:
linear-gradient(to bottom right,transparent 49.2%,red 50%) bottom/100% var(--angle) no-repeat,
url(https://picsum.photos/id/12/800/800) center/cover;
clip-path:polygon(0 0,100% 0, 100% calc(100% - var(--angle)),0 100%)
}
<div class="container">
</div>
<div class="container" style="--angle:40px;--thickness:5px">
</div>
You can use the clip-path property and manipulate its size.
Try This:-
.right {
position: absolute;
left: 0;
top: 0;
-webkit-clip-path: polygon(0 0, 100% 0%, 100% 23%, 0 83%);
clip-path: polygon(0 0, 100% 0%, 100% 23%, 0 83%);
}
.left {
position: absolute;
left: 0;
top: 0;
-webkit-clip-path: polygon(0 75%, 100% 22%, 100% 100%, 0 100%);
clip-path: polygon(0 75%, 100% 22%, 100% 100%, 0 100%);
}
border {
position: absolute;
left: 0;
top: 0;
width: 400px;
height: 300px;
background-color: black;
-webkit-clip-path:polygon(0 75%, 100% 22%, 100% 28%, 0 83%);
clip-path: polygon(0 75%, 100% 22%, 100% 28%, 0 83%);
}
<!DOCTYPE html>
<html>
<head>
<title>HTML, CSS and JavaScript demo</title>
</head>
<body>
<img class="left" src="https://picsum.photos/400/300?random">
<img class="right" src="https://picsum.photos/400/300">
<border />
</body>
</html>
Well i have an idea for you you can do it with skewY:
<div class="div1"><div class="content"></div></div>
<div class="div2"><div class="content"></div></div>
div1 {
transform: skewY(-10deg)
}
div2 {
transform: skewY(-10deg)
}
After that your content will be also skewed with -10 deg so you need to skew it the other way around:
.content {
transform: skewY(10deg)
}

CSS Navigation Bar within the Parallax Page

I did look for some tutorials about parallax. I want to add navigation bar on it but the results are different from what I'm expecting. I need your help.
This is the CSS code of the navigation Bar:
body{
margin: 0;
}
.navigation{
width: 100%;
background: #313131;
height: 50px;
margin-top: 0px;
}
ul {
list-style-type: none;
padding: 0;
margin: 0;
position: absolute;
margin-top: 5px;
}
li {
float: left;
margin-top: 5px;
padding-left: 25px;
padding-right: 25px;
}
a{
width: 150px;
color: white;
display: block;
text-decoration: none;
font-size: 20px;
text-align: center;
padding: 2px;
border-radius: 4px;
font-family: Century Gothic;
font-weight: bold;
}
a:hover{
background: #669900;
transition: 0.6s;
}
CSS Code of Parallax Page
#import "bourbon";
//Edit these
$farColor: #ffe4c7;
$nearColor: darken(cyan,30%);
$layer: 7; //make sure it is +1 the ammount of layer divs in the html
$perspective: 1;
.bg {
position: absolute;
height: 100%;
width: 100%;
top: 0px;
z-index: 0;
background-color: #ffe4c7;
}
.layer {
position: fixed;
top: 0px;
margin: auto;
width: 100%;
z-index: 100;
min-height: 400px;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-position: top center;
background-repeat: no-repeat;
}
.parallax {
height: 100vh;
overflow-x: hidden;
overflow-y: scroll;
-webkit-perspective: 1px;
perspective: 1px;
}
.parallax-group {
position: relative;
height: 100vh;
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
}
.parallax-group div:nth-child(1) {
background-color: #ffe4c7;
margin-top: 600px;
background-color: #d9d1b8;
-webkit-transform: translateZ(-12px) scale(13);
transform: translateZ(-12px) scale(13);
}
.parallax-group div:nth-child(1):before {
content: "";
width: 100%;
height: 200px;
position: absolute;
bottom: 100%;
left: 0;
background-image: -webkit-linear-gradient(315deg, transparent 66%, #d9d1b8 66.01%), -webkit-linear-gradient(45deg, #d9d1b8 34%, transparent 34.01%);
background-image: linear-gradient(135deg, transparent 66%, #d9d1b8 66.01%), linear-gradient(45deg, #d9d1b8 34%, transparent 34.01%);
background-position: 222px 0px;
background-size: 200px 100%;
background-repeat: repeat-x;
}
.parallax-group div:nth-child(2) {
background-color: #ffe4c7;
margin-top: 900px;
background-color: #b3beaa;
-webkit-transform: translateZ(-10px) scale(11);
transform: translateZ(-10px) scale(11);
}
.parallax-group div:nth-child(2):before {
content: "";
width: 100%;
height: 200px;
position: absolute;
bottom: 100%;
left: 0;
background-image: -webkit-linear-gradient(315deg, transparent 66%, #b3beaa 66.01%), -webkit-linear-gradient(45deg, #b3beaa 34%, transparent 34.01%);
background-image: linear-gradient(135deg, transparent 66%, #b3beaa 66.01%), linear-gradient(45deg, #b3beaa 34%, transparent 34.01%);
background-position: 77px 0px;
background-size: 200px 100%;
background-repeat: repeat-x;
}
.parallax-group div:nth-child(3) {
background-color: #ffe4c7;
margin-top: 1200px;
background-color: #8cab9b;
-webkit-transform: translateZ(-8px) scale(9);
transform: translateZ(-8px) scale(9);
}
.parallax-group div:nth-child(3):before {
content: "";
width: 100%;
height: 200px;
position: absolute;
bottom: 100%;
left: 0;
background-image: -webkit-linear-gradient(315deg, transparent 66%, #8cab9b 66.01%), -webkit-linear-gradient(45deg, #8cab9b 34%, transparent 34.01%);
background-image: linear-gradient(135deg, transparent 66%, #8cab9b 66.01%), linear-gradient(45deg, #8cab9b 34%, transparent 34.01%);
background-position: 117px 0px;
background-size: 200px 100%;
background-repeat: repeat-x;
}
.parallax-group div:nth-child(4) {
background-color: #ffe4c7;
margin-top: 1500px;
background-color: #66988d;
-webkit-transform: translateZ(-6px) scale(7);
transform: translateZ(-6px) scale(7);
}
.parallax-group div:nth-child(4):before {
content: "";
width: 100%;
height: 200px;
position: absolute;
bottom: 100%;
left: 0;
background-image: -webkit-linear-gradient(315deg, transparent 66%, #66988d 66.01%), -webkit-linear-gradient(45deg, #66988d 34%, transparent 34.01%);
background-image: linear-gradient(135deg, transparent 66%, #66988d 66.01%), linear-gradient(45deg, #66988d 34%, transparent 34.01%);
background-position: 183px 0px;
background-size: 200px 100%;
background-repeat: repeat-x;
}
.parallax-group div:nth-child(5) {
background-color: #ffe4c7;
margin-top: 1800px;
background-color: #40867e;
-webkit-transform: translateZ(-4px) scale(5);
transform: translateZ(-4px) scale(5);
}
.parallax-group div:nth-child(5):before {
content: "";
width: 100%;
height: 200px;
position: absolute;
bottom: 100%;
left: 0;
background-image: -webkit-linear-gradient(315deg, transparent 66%, #40867e 66.01%), -webkit-linear-gradient(45deg, #40867e 34%, transparent 34.01%);
background-image: linear-gradient(135deg, transparent 66%, #40867e 66.01%), linear-gradient(45deg, #40867e 34%, transparent 34.01%);
background-position: 71px 0px;
background-size: 200px 100%;
background-repeat: repeat-x;
}
.parallax-group div:nth-child(6) {
background-color: #ffe4c7;
margin-top: 2100px;
background-color: #1a7370;
-webkit-transform: translateZ(-2px) scale(3);
transform: translateZ(-2px) scale(3);
}
.parallax-group div:nth-child(6):before {
content: "";
width: 100%;
height: 200px;
position: absolute;
bottom: 100%;
left: 0;
background-image: -webkit-linear-gradient(315deg, transparent 66%, #1a7370 66.01%), -webkit-linear-gradient(45deg, #1a7370 34%, transparent 34.01%);
background-image: linear-gradient(135deg, transparent 66%, #1a7370 66.01%), linear-gradient(45deg, #1a7370 34%, transparent 34.01%);
background-position: 13px 0px;
background-size: 200px 100%;
background-repeat: repeat-x;
}
.content {
position: relative;
background-color: transparent;
font-family: "Arial";
letter-spacing: 10px;
text-transform: uppercase;
line-height: 40px;
z-index: 10;
width: 100%;
font-size: 15px;
text-align: center;
color: white;
margin-top: 1000px;
-webkit-transform: translateZ(-2px) scale(3);
transform: translateZ(-2px) scale(3);
}
.fill {
height: 80%;
}
HTML Code
</style>
</head>
<body>
<div class="bg"></div>
<div class="parallax">
<div class="parallax-group">
<div class="layer"></div>
<div class="layer"></div>
<div class="layer"></div>
<div class="layer"></div>
<div class="layer"></div>
<div class="layer fill"></div>
</div>
<div class="content">
<h1>Parallax Scrolling</h1>
<p>Using only CSS</p>
</div>
</div>
<div class="navigation">
<ul>
<li><span>Home</span></li>
<li><span>Beach Houses</span></li>
<li><span>Gallery</span></li>
<li><span>Contact</span></li>
</ul>
</div>
</body>
</html>
I want a floating navigation bar within the parallax page
Here is the result that I get:
https://jsfiddle.net/christiands97/s5Ltf6pj/
Put these in the css of your navigation class.
top: 10px;
position: absolute;
change the top value according to your requirement. Also make the 'position' fixed if you want the navigation bar to be fixed at the top.

Resources