I need help with this custom layout. Can someone tell me how to create css code for those 3 div's and get this results ?
Considering you don't have any code to start with, here is a beginning spot. Note that a lot of these have vendor prefixes and may of these have shorthand ways of writing them (padding, margin etc..). I just wrote everything out for visual purposes.
div{
display:flex;
flex-direction:column;
align-items:center;
padding-top: 50px;
padding-bottom: 50px;
}
h1{
text-align: center;
}
.black{
position: relative;
background: black;
width: 100%;
height: 100%;
}
h1.black{
color:white;
}
.white{
position:relative;
background: white;
width: 100%;
height: 100%;
border: 3px solid black;
}
div.overlay{
margin-top:140px;
padding-top: 0px;
padding-bottom: 0px;
padding-left: 10px;
padding-right: 10px;
width: 50%;
float: center;
border: 3px solid silver;
background: linear-gradient(silver,#A9A9A9);
position: absolute;
border-radius: 20px;
}
<div class="wrapper">
<div class="black">
<h1 class="black">Div 1</h1>
</div>
<div class="white">
<h1> Div 2</h1>
</div>
<div class="overlay">
<h1>Div 3</h1>
</div>
</div>
as a starting point:
the three div should be contained in the same container,
the container takes 100% of the availible height and is positioned relative.
each background div take 50% of the height and are also positioned relative.
using the .v-centered CSS class we can center elements vertically and horizontally inside of relative containers using : top:50% and transform: translateY(-50%) and horizontally margin: 0 auto.
the foreground has a higher z-index then other .v-centered content to appear on top
the issue you can see is that the content of the background divs is centered inside the divs and does not take into account the height of the foreground div, this is because it is positionned in absolute, if your central div has always the same height, you could add padding to the content of the background to adress that issue.
html,
body {
height:100%;
font-family: sans-serif;
font-weight: bold;
font-size: 30px;
}
.container {
text-align:center;
height:100%;
position:relative;
}
.color--dark {
background: black;
color:white;
}
.color--light {
background: white;
}
.background {
position:relative;
height :50%;
}
.v-centered {
position: absolute;
top:50%;
left: 0;
right: 0;
margin: 0 auto;
transform: translateY(-50%);
}
.foreground {
width:60%;
background:grey;
padding:10px;
border-radius: 20px;
z-index:2;
}
<div class="container">
<div class="background color--dark">
<span class="v-centered"> DIV 1 </span>
</div>
<div class="foreground v-centered"> DIV 2 </div>
<div class="background color--light">
<span class="v-centered"> DIV 3 </span>
</div>
</div>
Here's something that can work.
The trick is to set the middle div .button.-absolute to absolute positioning and make sure its placed within the upper black div .top-black. This element needs position: absolute for this to work. Because of its absolute positioning use bottom and left to align it on the fold of the two colours meeting. No z-index is needed yet, but if you see other items overlapping them, add a higher value e.g. z-index: 10 to the element that needs to be on top. The gradient background can be achieved by using background: linear-gradient(to bottom, #ffffff 0%, #cccccc 100%);
I hope this helps and here's it in action.
body {
font-size: 2rem;
}
.top-black {
text-align: center;
position: relative;
background-color: #333333;
width: 100% min-height: 225px;
content: ' ';
}
.bottom-white {
text-align: center;
background-color: #ffffff;
width: 100% min-height: 200px;
border: 1px solid #ccc;
}
.button {
padding: 3rem 1rem;
margin: 0 auto;
}
.button.-absolute {
padding: 1rem 5rem;
position: absolute;
bottom: -2rem;
left: calc(50% - 7.5rem);
background-color: red;
}
.button.-filled {
border-radius: 10px;
background: #ffffff;
/* Old browsers */
background: -moz-linear-gradient(top, #ffffff 0%, #cccccc 100%);
/* FF3.6-15 */
background: -webkit-linear-gradient(top, #ffffff 0%, #cccccc 100%);
/* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to bottom, #ffffff 0%, #cccccc 100%);
/* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#cccccc', GradientType=0);
/* IE6-9 */
}
.button.-white {
color: #ffffff;
}
<div class="top-black">
<div class="button -white">DIV I</div>
<div class="button -absolute -filled">DIV I</div>
</div>
<div class="bottom-white">
<div class="button">DIV I</div>
</div>
Related
This question already has answers here:
two divs split with diagonal line - CSS
(1 answer)
Responsively Align Slanted Divs
(1 answer)
Closed 1 year ago.
I have created one HTML page which is diagonally split.I have put image in right side and some content and button in left.But i am facing 2 issue with my code
1- right side is not fixed and image is not coming properly.
2- The split is not happen for full page
code is here:-
HTML:-
body {
margin: 0;
font-size: 2em;
}
#landing-area {
width: 100vw;
height: 100vh;
display: flex;
}
#box-left {
width: 50%;
clip-path: polygon(0 0, calc(100% - 10vh) 0, 100% 100%, 0 100%);
-webkit-clip-path: polygon(0 0, calc(100% - 10vh) 0, 100% 100%, 0 100%);
margin-right: -4.2vh;
padding: 5px 11vh 5px 5px;
background-color: #F4FCFF;
text-align: center;
}
#box-right {
width: 50%;
clip-path: polygon(0 0, 100% 0, 100% 100%, calc(0% + 10vh) 100%);
-webkit-clip-path: polygon(0 0, 100% 0, 100% 100%, calc(0% + 10vh) 100%);
margin-left: -4.2vh;
padding: 5px 5px 5px 11vh;
text-align: center;
}
#middle-text {
height: 200px;
width: 400px;
position: fixed;
top: 50%;
left: 25%;
margin-top: -100px;
margin-left: -200px;
}
<body>
<div id="landing-area">
<div id="box-left">
<div id="middle-text">
<img src="images/logo.png">
<h>Header goes here</h>
<p>4 line paragraph goes here</p>
<button>Button name</button></div>
</div>
<div id="box-right">
<img src="images/landingPage.png">
</div>
</div>
</body>
Image:-
I want the page should be look like below
I suggest a slightly different approach because you want to be sure that your text etc within the left block will fit whatever the viewport width. One way of ensuring this is to have the left hand block at width 50% less 10vh. i.e. not try the complicaed business of getting text to fit within a sloping side.
This snippet gives the whole page the pale background color, the left block sized as above and the right block it gives width 50% plus 10vh and clips it (polygon is slightly altered to make it correct for this width).
body {
margin: 0;
font-size: 2em;
}
#landing-area {
width: 100vw;
height: 100vh;
background-color: #F4FCFF;
position: relative;
}
#box-left {
width: calc(50% - 10vh);
padding: 5px 11vh 5px 5px;
text-align: center;
display: inline-block;
height: 100%;
box-sizing: border-box;
}
#box-right {
width: calc(50% + 10vh);
clip-path: polygon(10vh 0, 100% 0, 100% 100%, 0 100%);
padding: 5px 5px 5px 11vh;
text-align: center;
background-image: url(https://picsum.photos/id/131/1024/768?blur=2);
background-size: cover;
background-position: center center;
display: inline-block;
height: 100%;
position: absolute;
box-sizing: border-box;
}
#middle-text {
height: 200px;
width: 400px;
position: fixed;
top: 50%;
left: 25%;
margin-top: -100px;
margin-left: -200px;
}
<div id="landing-area">
<div id="box-left">
<div id="middle-text">
<img src="images/logo.png">
<h>Header goes here</h>
<p>4 line paragraph goes here</p>
<button>Button name</button></div>
</div>
<div id="box-right">
</div>
</div>
Note: you'd need to make your px dimensions currently used for the text into relative ones so that the whole thing is responsive (this is true whether you use the method here or some other method).
You can see the code from codepen. Visit https://codepen.io/chris22smith/pen/vvYBGY
HTML:-
<body>
<div class="view">
<div class="left">
<div class="sun"></div>
</div>
<div class="divider"></div>
<div class="right">
<div class="moon"></div>
</div>
</div>
</body>
CSS:-
body {
overflow:hidden;
}
.view {
bottom:0;
left:0;
position:absolute;
right:0;
top:0;
transform:skew(-10deg);
}
.left,
.right {
bottom:0;
overflow:hidden;
position:absolute;
top:0;
}
.left {
left:-5%;
right:50%;
}
.divider {
background-color:#fc0;
border-left:solid 2px #000;
border-right:solid 2px #000;
bottom:-5%;
left:50%;
position:absolute;
right:50%;
top:-5%;
z-index:1;
}
.right {
left:50%;
right:-5%;
}
.sun,
.moon {
bottom:-5%;
left:-5%;
position:absolute;
right:-5%;
top:-5%;
transform:skew(5deg);
}
.sun {
background-image: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/71829/sun.jpg);
background-position:center center;
background-size:cover;
}
.moon {
background-image: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/71829/moon.jpg);
background-position:center center;
background-size:cover;
}
As you can see, in the title block, only the upper half has background, I want the whole title block to have the same background. Of course, I can set background for the title block itself, but this way the background won't look continuous, as you can see in the fiddle.
Is there a way to achieve this with pure css?
.header {
width: 100%;
padding-top: 30%;
background: url('https://cchc-herald.org/images/discuss_cavatar/titleSampleBG.jpg') no-repeat 50% 50%;
background-size: cover;
position: relative;
}
.title {
position: absolute;
transform: translateY(-50%);
padding: 8px 24px;
font-size: 24px;
background: none;
border-radius: 50px;
border: 4px solid white;
left: 10%
}
body {
background-color: #eee
}
.title.b {
background: url('https://cchc-herald.org/images/discuss_cavatar/titleSampleBG.jpg') no-repeat 50% 50%;
background-size: contain
}
<div class="header">
<div class="title"> Title Title </div>
</div>
<div class="header" style="margin-top:60px">
<div class="title b">
Title Title
</div>
</div>
Fiddle: https://jsfiddle.net/s7pkr2w8/1/
Here is an idea using clipping and masking
.header {
padding-top: 30%;
position: relative; /* relative here !! **/
display:flex;
z-index:0;
}
.title {
font-size: 24px;
color:#fff;
border-radius: 50px;
margin:auto auto 0 10%; /* position the element using flexbox instead of absolute */
-webkit-mask:linear-gradient(#fff 0 0); /* clip the pseudo element to only the title shape*/
}
/* extra div needed for the white border*/
.title > div {
padding: 8px 24px;
border:4px solid #fff;
position:relative;
border-radius: inherit;
}
/**/
/* two pseudo element relative to the container having the same background
to have the continuous effect
*/
.title::before,
.header::before{
content:"";
position:absolute;
z-index:-1;
top:0;
bottom:0;
left:0;
right:0;
background: url('https://cchc-herald.org/images/discuss_cavatar/titleSampleBG.jpg') no-repeat 50% 50%/cover;
}
.header::before {
clip-path:inset(0 0 20px 0); /* cut 20px from the bottom to be around the middle of the title */
}
body{
background-color:#eee
}
<div class="header">
<div class="title">
<div>Title Title</div>
</div>
</div>
you can try to set the background on a parent element or just event to the whole body:
body{
background:url('https://cchc-herald.org/images/discuss_cavatar/titleSampleBG.jpg') no-repeat 50% 50%;
background-size:cover;
}
I am trying to create 3 section breadcrumbs type element with an arrow divider. This is a simple mockup.
There is a weird artefact showing between section 2 and 3. In this case section three's red background is visible (slightly) to the left of the blue arrow of section 2, however the same problem doesn't occur with section 2's background interfering with section 1 arrow. thankfully but weirdly. For me this is only happening on Chrome for Mac too (the browser window isn't zoomed in/out either). Haven't tested Windows etc. Any suggestions as to how to fix this bizarre issue?
A zoomed up view of the weird artefact (the red vertical line) occurring between section 2 and 3:
No such weird artefact occurs between section 1 and 2.
The codepen:
https://codepen.io/reacting/pen/xeewdO
The html:
<div class="container">
<div class="section">section one</div>
<div class="section two">section two</div>
<div class="section">section three</div>
</div>
The css/scss:
.container {
background-color: white;
border: 1px solid grey;
box-sizing: border-box;
width: 100%;
display: flex;
}
.section {
flex: 1;
position: relative;
height: 100px;
background-color: black;
color: white;
display: flex;
justify-content: center;
align-items: center;
&:before {
content:"";
background-color: grey;
-webkit-clip-path: polygon(0% 100%, 100% 50%, 0% 0%);
clip-path: polygon(0% 100%, 100% 50%, 0% 0%);
z-index: 1;
position: absolute;
right: -26px;
top: 0;
width: 25px;
height: 100px;
}
&:after {
content:"";
background-color:black;
-webkit-clip-path: polygon(0% 100%, 100% 50%, 0% 0%);
clip-path: polygon(0% 100%, 100% 50%, 0% 0%);
z-index: 2;
position: absolute;
right: -25px;
top: 0;
width: 25px;
height: 100px;
}
&:last-of-type {
background-color: red;
color: black;
}
&:last-of-type:before {
display: none;
}
&:last-of-type:after {
display: none;
}
&.two {
background-color: blue;
&:after {
background-color: blue;
}
}
}
body {
background-color: #333;
}
I don't just want to change the right: attribute of the before/after pseudo selectors to be less 1 pixel as that just feels hacky and wrong.
Many thanks!
Edit: I wonder if the issue is related to the high resolution of my Mac display - as when I resize the chrome browser window slightly the problem comes and goes and changes to occur for section 1/2 or both section 1/2 and 2/3 or none. depending on the size of the browser window. But strangely in Firefox and Safari this doesn't occur when dragging the window at all.
You can optimize the code and consider clip-path on the element without the need of pseudo element then consider some background coloration to simulate the border
.container {
background-color: white;
border: 1px solid grey;
box-sizing: border-box;
display: flex;
height: 100px;
}
.section {
flex: 1;
color: white;
display: flex;
justify-content: center;
align-items: center;
margin-left:-25px; /* Create an overlap with the previous element */
/* the clip path (note the 25px that is the same as margin*/
-webkit-clip-path: polygon(100% 0, 100% 50%, 100% 100%, 0% 100%, 25px 50%, 0% 0%);
clip-path: polygon(100% 0, 100% 50%, 100% 100%, 0% 100%, 25px 50%, 0% 0%);
/* the border (note the 25px in the gradient)*/
border-left:3px solid grey; /* this will push the background and control the thickness of the border*/
background:
linear-gradient(to top right, grey 48%,transparent 50%) top left /25px 50%,
linear-gradient(to bottom right, grey 48%,transparent 50%) bottom left/25px 50%;
background-repeat:no-repeat;
background-color: black;
}
.section:last-of-type {
background-color: red;
color: black;
}
.section:first-of-type {
/* Remove everything from the first element */
clip-path:none;
margin-left:0;
border-left:0;
background:black;
}
.section.two {
background-color: blue;
}
body {
background-color: #333;
}
<div class="container">
<div class="section">section one</div>
<div class="section two">section two</div>
<div class="section">section three</div>
</div>
Here is the effect I am trying to achieve:
Example
I know how to make the triangle, my issue is that is is being created INSIDE of the box. If I set "left" to 100%, the box will disappear behind the right side of the box instead of going outside of the box over the next one.
Here is the Pen I am working on to try and get this to work:
My Code
HTML:
<div class="square title">
<div class="content">
<div class="table">
<div class="table-cell ">
<ul>This demo shows you can center multiple types of content :
<li>Text</li>
<li>Images</li>
<li>Lists</li>
<li>... (you can also do it with forms)</li>
</ul>
</div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell ">
<p>Hello World!</p>
</div>
</div>
</div>
</div>
CSS:
body {
font-family: sans-serif;
color: #fff;
font-size: 20px;
text-align: center;
}
.square {
float:left;
position: relative;
width: 33%;
padding-bottom : 33%; /* = width for a 1:1 aspect ratio */
/* margin:1.66%; */
background-color:#1E1E1E;
overflow:hidden;
/* border: solid 1px red; */
margin: 5px;
}
.content {
position:absolute;
height:90%; /* = 100% - 2*5% padding */
width:90%; /* = 100% - 2*5% padding */
padding: 5%;
}
.table{
display:table;
width:100%;
height:100%;
}
.table-cell{
display:table-cell;
vertical-align:middle;
}
/* For list */
ul{
text-align:left;
margin:5% 0 0;
padding:0;
list-style-position:inside;
}
li{
margin: 0 0 0 5%;
padding:0;
}
.title::after {
content: "";
position: absolute;
width: 0;
height: 0;
border-top: 50px solid transparent;
border-bottom: 50px solid transparent;
border-left: 50px solid green;
left: 95%;
/* top: 45%; */
/* z-index: 999; */
}
I tried making a whole new div around the square and setting that to have the triangle, but it made the triangle go all the way to the right of the screen, even without setting anything for the left or right.
I also tried z-index but that didn't do anything either.
You can easily achieve this with only background:
.box {
display: inline-block;
width: 150px;
height: 150px;
background: grey;
}
.box:last-child {
background:
linear-gradient(to top right,grey 49.8%,transparent 50%) 0 calc(50% - 15px),
linear-gradient(to bottom right,grey 49.8%,transparent 50%) 0 calc(50% + 15px),
#000;
background-size:30px 30px;
background-repeat:no-repeat;
}
<div>
<div class="box">
</div>
<div class="box">
</div>
</div>
How to make multiple images gradient blend to each other at only certain area as in the attached image below using CSS?
What I've tried:
.container {
position: relative;
display: flex;
height: 200px;
}
.container:before {
content: '';
position: absolute;
width: 80px;
top: 0;
bottom: 0;
right: 50%;
margin-right: -40px;
background: url(https://www.w3schools.com/w3css/img_fjords.jpg);
filter: blur(5px);
-webkit-filter: blur(5px);
}
.container > div {
flex: 1;
background-size: 100% 100%;
}
<div class="container">
<div style="backgroud-image:url(https://www.w3schools.com/w3css/img_fjords.jpg)"></div>
<div style="background-image:url(https://www.w3schools.com/w3css/img_fjords.jpg)"></div>
</div>
However, there's no fading/transition respecting to the background images as shown in below image:
UPDATE
I haven't receive any solid answer for my question but this code seems like the closest answer I can get till date.
A modification from PEN BY Peter Ramsing
<div class="hero-image">
<img src="http://static.peter.coffee/codepen-assets/keyboard-background.jpg" />
</div>
<div class="hero-before">
<img src="http://static.peter.coffee/codepen-assets/keyboard-background.jpg" />
</div>
<style>
img {
/* To contain the image to the confines of the div */
max-width: 100%;
}
.hero-image {
max-width: 100%;
width: 800px;
margin: auto;
}
.hero-before {
max-width: 100%;
width: 800px;
margin: auto;
}
.hero-image::after {
display: block;
position: relative;
background-image: linear-gradient(to bottom, rgba(255, 255, 255, 0) 0, #fff 100%);
margin-top: -50px;
height: 40px;
width: 100%;
content: '';
}
.hero-before::after {
display: block;
position: relative;
background-image: linear-gradient(to bottom, #fff 0%, rgba(255, 255, 255, 0) 100%);
margin-top: -345px;
height: 50px;
width: 100%;
content: '';
}
</style>
You may use some pseudo element that you put between the two images and apply linear gradient on it. By using the same colors you will create this effet. You may notice that the solution will work by using background color and also backround image, you simply need to respect the color used in the background and apply them to the pseudo element.
Here is an example, you may adjust the width of the pseudo element depending on your needs :
.container {
position: relative;
display: flex;
min-height: 100px;
margin-bottom:20px;
}
.container:before {
content: '';
position: absolute;
width: 80px;
top: 0;
bottom: 0;
right: 50%;
margin-right: -40px;
background: linear-gradient(to right, #c3986b, #0a4b67);
}
.container>div {
flex: 1;
background-size:100% 100%;
}
<div class="container">
<div style="background:#c3986b;"></div>
<div style="background:#0a4b67;"></div>
</div>
<div class="container">
<div style="background-image:url(https://dummyimage.com/150x100/c3986b/14151a)"></div>
<div style="background-image:url(https://dummyimage.com/150x100/0a4b67/14151a)"></div>
</div>
Here is another idea with mask that will work with any kind of images
.container {
display: flex;
min-height: 300px;
margin-bottom:20px;
}
.container>div {
flex: 1;
background-size:0 0;
position:relative;
z-index:-1;
}
.container>div::before {
content:"";
position:absolute;
background-image:inherit;
background-size:cover;
background-position:center;
z-index:-1;
top:0;
bottom:0;
}
.container>div:first-child::before {
left:0;
right:-50px;
-webkit-mask:linear-gradient(to left,transparent ,#fff 50px);
mask:linear-gradient(to left,transparent ,#fff 50px);
}
.container>div:last-child::before {
right:0;
left:-50px;
-webkit-mask:linear-gradient(to right,transparent ,#fff 50px);
mask:linear-gradient(to right,transparent ,#fff 50px);
}
<div class="container">
<div style="background-image:url(https://picsum.photos/id/1074/800/800.jpg)"></div>
<div style="background-image:url(https://picsum.photos/id/1060/800/800.jpg)"></div>
</div>
<div class="container">
<div style="background-image:url(https://picsum.photos/id/1070/800/800.jpg)"></div>
<div style="background-image:url(https://picsum.photos/id/1062/800/800.jpg)"></div>
</div>
You can combine the background: linear-gradient() with Flexbox to achieve something like this:
div {
display: flex; /* displays flex-items (children) inline */
justify-content: space-around; /* horizontal alignment / icons are evenly distributed with equal space around them, i.e. all have equal space on both sides, that's why there are two units of space between them / you can also experiment with other values such as: "space-between", "space-evenly", "center" etc. */
align-items: center; /* vertically centered */
height: 100px;
background: linear-gradient(to right, #c3986b 45%, #0a4b67 55%); /* adjust the % to your needs, the sum of both needs to evaluate to 100% */
}
img {border-radius: 50%}
<div>
<img src="http://lorempixel.com/50/50/" alt="icon1">
<img src="http://lorempixel.com/50/50/" alt="icon2">
</div>
In the given example I've made the linear-gradient() to be 10% of parent's width. The number is calculated by subtraction of both values in %, 55% - 45%.
In order to increase its width, if so desired, just increase the bigger number and decrease the lower one, preferably by the same amount of %, e.g. 40% / 60%, to leave it horizontally centered. For decreasing its width, just do the opposite.