I'm trying to set up a banner which features an overlay with a cutout in it. Below the overlay is an image.
I'm trying to figure out how to create this in HTML and CSS, my experiments so far have seen me play with psuedo elements but am struggling to recreate the design in the shape and position shown below.
My current HTML looks like this:
<header class="main" style="background-image: url(./assets/images/bg-hero.jpg)">
<div class="container">
<div class="row">
<div class="col-12">
<div class="row row--no-pad">
<div class="col-6">
<a href="/">
<img src="./assets/images/logo.png" alt="">
</a>
</div>
<div class="col-6">
</div>
</div>
<div class="row">
<div class="banner">
<div class="row">
<div class="col-12">
<h1>Lorem ipsum dolor sit amet</h1>
<p>Lorem ipsum dolor sit amet lorem ipsum dolor sit amet, L lorem ipsum dolor sit amet.</p>
View our services
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</header>
Here's the design:
Thanks,
Ben
What you're looking for is known as image clipping. There are many articles on the web that cover how to do it with CSS (here is one). The process is really straight forward as it only requires one line of CSS to accomplish this task. You'll need to utilize clip-path in order to get this done, and I highly recommend reading the documentation on it.
Building the clip-path can be difficult depending on what you're going for, but Clippy is an online clip path assistant that is very helpful. However, based on the image you supplied, the following will work:
html, body {
margin: 0;
height: 100%;
background-color: #124;
background-image: linear-gradient(to right, #111, #124);
background-image: -webkit-linear-gradient(to right, #111, #124);
}
.background-image {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/2940219/GIF_Koi_Pond.gif');
background-size: cover;
background-position: center;
clip-path: polygon(56% 0, 78% 50%, 56% 100%, 31% 100%, 52% 50%, 28% 0);
}
.main-content {
position: absolute;
top: 0;
left: 0;
color: #fff;
display: flex;
justify-content: center;
flex-direction: column;
height: 100%;
padding: 15px;
}
.main-content h1 {
width: 250px;
margin: 0;
}
.main-content a {
color: #fff;
background-color: #3a7;
text-decoration: none;
padding: 5px 25px;
width: 150px;
text-align: center;
}
<div class="background-image"></div>
<div class="main-content">
<h1>Lorem ipsum dolor sit amet</h1>
<p>Lorem ipsum dolor sit amet lorem ipsum dolor sit amet, L lorem ipsum dolor sit amet.</p>
View our services
</div>
The part you are the most interested in is:
clip-path: polygon(56% 0, 78% 50%, 56% 100%, 31% 100%, 52% 50%, 28% 0);
Also, don't forget that clip-path has a -webkit version that needs to be accounted for.
clip-path: polygon(56% 0, 78% 50%, 56% 100%, 31% 100%, 52% 50%, 28% 0);
-webkit-clip-path: polygon(56% 0, 78% 50%, 56% 100%, 31% 100%, 52% 50%, 28% 0);
Another thing to remember is that when you apply clip-path to an element such as a div, you're not just clipping the background-image, but rather clipping the entire element.
Image clipping is definitely an option, although if you wanted to go for something more traditional you could use borders like this:
#cutBox{
width: 100%;
height: 600px;
background-image: url('https://wallpaperplay.com/walls/full/7/2/4/272374.jpg');
background-size: cover;
display: flex;
}
#leftPane, #rightPane{
background-color: midnightblue;
}
#leftPane, #rightPane{
height: 100%;
width: 40%;
}
#leftTri{
border-left: 100px solid midnightBlue;
border-top: 300px solid transparent;
border-bottom: 300px solid transparent;
margin-right: 200px;
}
#rightTri{
border-left: 100px solid transparent;
border-top: 300px solid midnightblue;
border-bottom: 300px solid midnightblue;
}
#leftPane > .pane-text{
position: relative;
color: white;
top: 40%;
font-size: 26px;
margin-left: 60%;
right: -10px;
}
.subtext{
margin-left: 20px;
font-size: 18px;
}
<div id="cutBox">
<div id="leftPane">
<div class="pane-text">
Lorem Ipsum
<div class="subtext">
dolor sit amet
</div>
</div>
</div>
<div id="leftTri">
</div>
<div id="rightTri">
</div>
<div id="rightPane">
</div>
</div>
It might look a little odd because of the small viewport but it generally works pretty well.
You can use clip-path property to achieve the affect above.
For example this polygon will create a mask that will create a star shape.
.star {
clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
}
Here's a tutorial on clip-path
you can also use multiple background with gradient hiding partially another background-image:
* {
margin: 0;
box-sizing: border-box;
}
header {
background: linear-gradient(60deg, rgb(0, 0, 36) 66.6%, transparent 66.66%, transparent 86%, rgb(0, 0, 36) 86.3%) top left no-repeat, linear-gradient(120deg, rgb(0, 0, 36) 66.6%, transparent 66.66%, transparent 86%, rgb(0, 0, 36) 86.3%) bottom left no-repeat, url(https://placeimg.com/640/480/nature/5) center right;
background-size: 100% 50%, 100% 50%, auto;
/*demo purpose*/
position: relative;
display: flex;
justify-content: space-around;
flex-direction: column;
color: white;
max-width: 800px;
min-height:250px;
box-shadow: 0 0 1px;
padding-right: 250px;
margin: auto;
padding-left:1em;
}
body {
background: rgb(0, 0, 36)
}
nav {
position: absolute;
right: 3%;
top: 3em;
border-top: 3px solid;
border-bottom: 3px solid;
}
nav b {
display: block;
width: 2em;
height: 3px;
background: white;
margin: 5px 0
}
<header>
<nav><b></b></nav>
<h1>title</h1>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est.
thus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p>
<a>link</a>
</header>
tune start/stop gradient values to your needs, this is an example.
Related
I am working on web application using Rect JS and I only have beginners knowledge in HTML and CSS.So can you please suggest me to achieve something like the following with a responsive UI that containing button,text and image.How can I write css styles to curve a div and place another one below it without any blank space.
Can someone please suggest any solution? Any help would be really appreciated.I have tried radial-gradient method like following.
<div className="background1">
....
</div>
<div className="background2">
.....
</div>
.background1 {
width: 100%;
background: radial-gradient(120% 800px at 50% -30px, red 75%,
transparent 75%) no-repeat;
z-index: 2;
position:relative;
margin-bottom: 0px;
}
.background2 {
background-color: #202492;
width: 100%;
background: radial-gradient(120% 800px at 50% -30px,blue 75%,
transparent 75%) no-repeat;
position: relative;
z-index: 1;
margin-top: -50px;
}
But I am getting this
Blockquote
I think you need something like this:
.btn1 {
background: #190b0b;
color: #fff;
padding: 1em 2.5em;
box-shadow: 1px 2px 7px -1px #190b0b;
}
.background1 {
width: 100%;
background: red;
z-index: 2;
position: relative;
margin-bottom: 0px;
padding: 6em 0;
border-radius: 0 0 10em 10em;
text-align: center;
}
.background2 {
background-color: #202492;
z-index: 1;
position: relative;
margin-bottom: 0px;
padding: 6em 0;
border-radius: 0 0 10em 10em;
text-align: left;
width: 100%;
top: -10em;
color: #fff;
}
.background3 {
background-color: blue;
z-index: 0;
position: relative;
margin-bottom: 0px;
padding: 6em 0;
border-radius: 0 0 10em 10em;
text-align: left;
width: 100%;
top: -20em;
color: #fff;
}
.text {
margin-top: 6em;
max-width: 50%;
padding: 0 6em;
}
<div class="background1">
<button class="btn1">Button</button>
</div>
<div class="background2">
<div class="text">
<h2> Text1 </h2>
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse pellentesque, nibh sed tempus bibendum, lacus turpis dictum ipsum, nec consectetur diam nisi eget mauris. </p>
</div>
</div>
<div class="background3">
<div class="text">
<h2> Text2 </h2>
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse pellentesque, nibh sed tempus bibendum, lacus turpis dictum ipsum, nec consectetur diam nisi eget mauris. </p>
</div>
</div>
Just change in border-radius and padding values to have the perfect curve that you want.
You can use border-bottom-left-radius and border-bottom-lright-radius or border-radius: 0px 0px xxxpx xxpx;
div {
height: 300px;
width: 300px;
border-bottom-right-radius: 200px;
border-bottom-left-radius: 200px;
background: black;
}
<div></div>
I'm not the best in css, but when I have a div with a background image, and I overlay a svg that only has a border, the border lines are shown on some devices. It should look like this.
But when I load this on mobile view, the border lines are shown. How can i fix this?
I've tried to add a padding, and tried to use an backgroud position offset, but that didn't work.
* {
box-sizing: border-box;
margin: 0;
padding: 0;
background-origin: content-box;
}
body {
margin: 0;
font-family: Ubuntu;
overflow: hidden;
/* Hide scrollbars */
}
.container {
margin: auto;
}
.column.left {
margin: 0;
float: left;
}
.column.right {
float: right;
}
/* Clear floats after the columns */
.item {
display: block;
overflow: hidden;
position: relative;
background-size: cover;
background-position: left top;
background-origin: content-box;
background-repeat: no-repeat;
/*border-radius: .9rem .9rem 0 .9rem;*/
}
.item h2 {
font-family: Ubuntu, sans-serif;
text-shadow: 0 0 3px rgba(0, 0, 0, .8);
background: -webkit-linear-gradient(top, transparent 0%, #000000);
background: linear-gradient(180deg, transparent 0%, #000000);
bottom: 0;
color: #fff;
font-weight: normal;
left: 0;
margin: 0;
position: absolute;
right: 0;
}
.item1 img,
.item2 img,
.item3 img {
width: 100%;
height: auto;
}
<div class="container">
<div class="content">
<div class="overzicht">
<div class="column left">
<div class="item item1" style="background-image: url('https://i.regiogroei.cloud/552x310/43692b31-6c5e-3c1c-9734-0fda6b587107.jpg'); background-size: cover; background-position: center">
<img src="./StoreplayNEWS_Tekengebied 1.svg" style="position: absolute; z-index: 5; width: 100%; height:100%" alt="">
<h2 class="title">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin tincidunt sed justo sit amet rhoncus</h2>
</div>
</div>
<div class="column right">
<div class="item item2" style="background-image: url('https://i.regiogroei.cloud/552x310/13650346-f88e-3b81-b54a-af81dccd4369.jpg'); background-size: cover; background-position: center">
<img src="./StoreplayNEWS_Tekengebied 1.svg" style="position: absolute; z-index: 5; width: 100%; height:100%" alt="">
<h2 class="title">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin tincidunt sed justo sit amet rhoncus</h2>
</div>
<div class="item item3" style="background-image: url('https://i.regiogroei.cloud/552x310/ee982215-e923-3ea5-b65f-2230e1d36fad.jpg'); background-size: cover; background-position: center">
<img src="./StoreplayNEWS_Tekengebied 1.svg" style="position: absolute; z-index: 5; width: 100%; height:100%" alt="">
<h2 class="title">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin tincidunt sed justo sit amet rhoncus</h2>
</div>
</div>
</div>
</div>
</div>
Thanks in advance!
I've found the answer. The problem was that the .item h2's background was overlapping. I've changed that to this and that fixed the problem.
.item h2 {
font-family: Ubuntu, sans-serif;
text-shadow: 0 0 3px rgba(0, 0, 0, .8);
background: -webkit-linear-gradient(top, transparent 0%, #000000);
background: linear-gradient(180deg, transparent 0%, #000000);
bottom: 0;
color: #fff;
font-weight: normal;
left: 0;
margin: 1px;
position: absolute;
right: 0;
}
Try setting the border and outline property to zero on the parent and child elements.
{
border: none;
outline: none
}
What I want to draw is more or less like below, in which the div's size is dynamic (depend on screen size and content in it), and two circle's size is static (in px).
Is there a better way to draw this with shadow?
body {
background: white;
}
.card {
background: #fff;
border-radius: 4px;
box-shadow: 4px 4px 4px 4px red;
width: 200px;
height: 200px;
margin: 20px;
position: relative;
}
.left,
.right {
background: #ccc;
position: absolute;
width: 20px;
height: 20px;
border-radius: 50%;
filter: drop-shadow(1px 0px 0px red);
left: -10px;
top: 50%;
}
.right {
left: 197px;
filter: drop-shadow(-5px 0px 1px red);
}
<div class="card">
<div class="left"></div>
<div class="right"></div>
</div>
Js Fiddle here
Update: below is the actual element that I want to style, in which the box-shadow is been cut by circles.
You can do it like below using radial-gradient as background:
.box {
margin:50px;
border-radius:10px;
width:200px;
height:250px;
background:
radial-gradient(circle 10px at left ,transparent 98%,#fff 100%) left,
radial-gradient(circle 10px at right,transparent 98%,#fff 100%) right;
background-size:51% 100%;
background-repeat:no-repeat;
filter:drop-shadow(0 0 4px red);
}
<div class="box">
</div>
Using mask if you want a random background:
.box {
margin:50px;
border-radius:10px;
width:200px;
height:250px;
overflow:hidden;
filter:drop-shadow(0 0 4px red);
position:relative;
z-index:0;
}
.box::before {
content:"";
position:absolute;
z-index:-1;
top:0;
left:0;
bottom:0;
right:0;
background:linear-gradient(60deg,lightgreen,lightblue); /* OR url() */
-webkit-mask:
radial-gradient(circle 10px at left ,transparent 98%,#fff 100%) left,
radial-gradient(circle 10px at right,transparent 98%,#fff 100%) right;
-webkit-mask-size:51% 100%;
-webkit-mask-repeat:no-repeat;
}
<div class="box">
</div>
UPDATE
In order to consider dynamic content you can do like below:
.box {
margin: 10px;
border-radius: 10px;
width: 200px;
display:inline-block;
overflow: hidden;
filter: drop-shadow(0 0 4px red);
}
.box>div {
position: relative;
z-index: 0;
padding:10px;
}
.box>div:first-child {
}
.box div::before {
content: "";
position: absolute;
z-index: -1;
top: 0;
left: 0;
bottom: 0;
right: 0;
-webkit-mask:
radial-gradient(circle 10px at var(--p, bottom) left, transparent 98%, #fff 100%) left,
radial-gradient(circle 10px at var(--p, bottom) right, transparent 98%, #fff 100%) right;
-webkit-mask-size: 51% 100%;
-webkit-mask-repeat: no-repeat;
background: grey;
}
.box div:last-child::before {
--p: top;
border-top:2px dotted red;
}
<div class="box">
<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla lectus leo, tincidunt at justo malesuada, consectetur sollicitudin nulla. Integer quis condimentum ipsum. Morbi hendrerit porttitor turpis, ac fringilla ipsum posuere vel. Suspendisse non interdum lorem, id iaculis augue. </div>
<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla lectus leo, tincidunt</div>
</div>
<div class="box">
<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla</div>
<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla lectus leo, tincidunt</div>
</div>
<div class="box">
<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla</div>
<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla lectus leo, tincidunt , tincidunt at justo malesuada, consectetur sollicitudin nulla. Integer quis condimentum ipsum. Morbi hendrerit </div>
</div>
I'm making a site and using a grid for my body. Now I'm trying to make a footer for my site but my footer is getting placed right of my main body.
I think the problem might be something with my container though I'm not really sure...
.container {
display: grid;
grid-template-columns: 50% auto;
height: auto;
align-self: center;
margin: 0 65px;
height: 90% auto;
}
I really wouldn't know how to fix this. Can somebody please help me?
This is my HTML & CSS:
body,
html {
height: 100%;
margin: 0;
width: 100%;
}
body {
font-family: "Montserrat";
display: grid;
grid-template-columns: 100% auto;
grid-template-rows: 90% auto;
background-color: rgb(27, 27, 27);
color: white;
}
.bg,
.bg2 {
width: 100%;
height: 100%;
position: absolute;
}
.bg {
-webkit-clip-path: polygon(66% 67%, 100% 0, 100% 100%, 0% 100%);
clip-path: polygon(66% 67%, 100% 0, 100% 100%, 0% 100%);
z-index: -1;
background-color: #053970;
}
.bg2 {
z-index: -2;
background-color: #004288;
-webkit-clip-path: polygon(49% 67%, 100% 0, 100% 100%, 0% 100%);
clip-path: polygon(49% 67%, 100% 0, 100% 100%, 0% 100%);
}
.container {
display: grid;
grid-template-columns: 50% auto;
height: auto;
align-self: center;
margin: 0 65px;
height: 90% auto;
}
a {
color: black;
}
a:visited {
color: black;
}
ul {
list-style-type: none;
perspective: 1000px;
}
ul a li {
display: grid;
grid-template-columns: 20% auto;
border-radius: 10px;
padding: 15px;
cursor: pointer;
transform: rotateY(-30deg) rotateX(15deg);
position: absolute;
opacity: 0.8;
border-bottom: 4px solid rgba(0, 0, 0, .2);
mix-blend-mode: multiply;
width: 500px;
}
ul a:nth-child(1) li {
background: #a9cfe2;
top: -105px;
z-index: 2;
}
ul a:nth-child(2) li {
background: #85b890;
z-index: 1;
top: 0px;
}
ul a:nth-child(3) li {
background: #cca6a6;
z-index: 0;
top: 105px;
}
ul a li:hover {
transform: rotateY(-22deg) rotateX(7deg) scale(1.05);
transition: transform .45s ease-out;
z-index: 3;
mix-blend-mode: normal;
}
footer {
height: 10%;
width: 100%;
background-color: #333;
bottom: 0;
left: 0;
display: initial;
float: bottom;
}
img {
margin-top: 5;
width: 70px;
}
h1 {
font-size: 3em;
margin-top: 0;
margin-bottom: 0;
}
h2 {
font-size: 2em;
margin-top: 0;
}
#left>p {
color: #aaa;
line-height: 1.5em;
}
#right {
margin-left: 15%;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Index</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" media="screen" href="styles/main.css">
<link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet">
</head>
<body>
<div class="bg"></div>
<div class="bg2"></div>
<div class="container">
<div id="left">
<h1>Supercool Website</h1>
<h2>Supercool website for cool kids only</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras ac quam augue. Suspendisse potenti. Phasellus at vestibulum nunc. Phasellus suscipit elit odio, feugiat varius quam hendrerit sed. Mauris fringilla blandit maximus. Cras magna metus,
imperdiet congue convallis eu, finibus eget urna. In ac porttitor diam, sit amet sagittis tellus. Nullam consequat luctus ornare. Nulla vitae lectus vitae nisi dapibus ultricies. Aenean tempus nisl sit amet augue luctus pulvinar. Phasellus scelerisque
aliquet lorem.</p>
</div>
<div id="right">
<ul>
<a href="#">
<li>
<img src="img/img1.png">
<span>
<strong>Option 1</strong>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</span>
</li>
</a>
<a href="#">
<li>
<img src="img/img2.png">
<span>
<strong>Option 2</strong>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</span>
</li>
</a>
<a href="#">
<li>
<img src="img/img3.png">
<span>
<strong>Over Ons</strong>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</span>
</li>
</a>
</ul>
</div>
</div>
</body>
</html>
Maybe Your Forgetting
grid-template-rows: auto 1fr auto;?
Check Out This Article Maybe It Might Help.
https://dev.to/niorad/keeping-the-footer-at-the-bottom-with-css-grid-15mf
Hi guys i'm stuck at this.
I have a div but when i creating that same div class it will displayed in the next line. But i wanted to appear the second div next to first div. Can any one suggest one best answer.The code is:
<html>
<head>
<style>
.box3{
margin: 20px auto;
width: 300px;
min-height: 310px;
padding: 10px;
position:relative;
background: -webkit-gradient(linear, 0% 20%, 0% 92%, from(#fff), to(#fff), color-stop(.1,#fff));
border: 1px solid #ccc;
-webkit-border-radius: 60px 5px;
-webkit-box-shadow: 0px 0px 35px rgba(0, 0, 0, 0.1) inset;
}
.box3:before{
content: '';
width: 50px;
height: 50px;
top:0; right:0;
position:absolute;
display: inline-block;
z-index:-1;
-webkit-box-shadow: 10px -10px 8px rgba(0, 0, 0, 0.2);
-webkit-transform: rotate(2deg)
translate(-14px,20px)
skew(-20deg);
}
.box3:after{
content: '';
width: 100px;
height: 100px;
top:0; left:0;
position:absolute;
z-index:-1;
display: inline-block;
-webkit-box-shadow: -10px -10px 10px rgba(0, 0, 0, 0.2);
-webkit-transform: rotate(2deg)
translate(20px,25px)
skew(20deg);
}
.box3 img {
width: 100%;
margin-top: 15px;
}
p{
margin-top: 15px;
text-align: justify;
}
h1{
font-size: 20px;
font-weight: bold;
margin-top: 5px;
text-shadow: 1px 1px 3px rgba(0,0,0,0.3);
}
a{
text-decoration: none;
color: #4A4A4A !important;
}
a:hover{
text-decoration: underline;
color: #6B6B6B !important ;
}
</style>
</head>
<body>
<div>
<div class="box3">
<h1>Sample Box</h1>
<img src="http://www.wpthemegenerator.com/wp- content/uploads/2012/06/Image.jpg">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam luctus consectetur dolor a porttitor. Curabitur id sem sed ante fringilla pulvinar et id lectus. Nullam justo ipsum, hendrerit ut commodo nec, pellentesque nec erat. Pellentesque pharetra.
</p>
<br />
DesignShock.com
</div>
<div class="box3">
<h1>Sample Box</h1>
<img src="http://www.wpthemegenerator.com/wp-content/uploads/2012/06/Image.jpg">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam luctus consectetur dolor a porttitor. Curabitur id sem sed ante fringilla pulvinar et id lectus. Nullam justo ipsum, hendrerit ut commodo nec, pellentesque nec erat. Pellentesque pharetra.
</p>
<br />
DesignShock.com
</div>
</div>
</body>
</html>
There a two different solutions using float or flexbox.
Solution #1 (float)
Add float:left; to the class .box3 - see this fiddle: https://jsfiddle.net/sebastianbrosch/xa27czzL/
Solution #2 (flexbox)
Add a new class to the surrounding div of the boxes like .container and add a new stylesheet for this container with the property display:flex;
.container {
display:flex;
}
See an example on the following fiddle: https://jsfiddle.net/sebastianbrosch/xa27czzL/1/
More information about using flexbox you can find here: https://css-tricks.com/snippets/css/a-guide-to-flexbox/