Auto Scroll Div Based on Content - html

I can't work out how to make a parent div auto scrollable based on it's childs content.
I've got a menu that expands on click event and need it to scroll if the childs height exceeds the parent's.
This is my html for the menu wrapper.
<div class="menu-box">
<div class="page-links">
<div class="pl-inner">
<div class="pl-box">
<div class="pl-content">
<p>menu content goes here......Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
</div>
</div>
</div>
</div>
This is my CSS
.menu-box {
width: 100%;
min-height: 100%;
background-color: #000;
position: fixed;
z-index: 10;
transition: all 1.5s ease-in;
}
.page-links {
width: 100%;
height: 100%;
position: relative;
top: 0px;
left: 0px;
overflow-y: auto;
-webkit-overflow-scrolling: touch;
}
.pl-inner {
position: relative;
width: 100%;
}
.pl-box {
position: relative;
top: 0px;
right: 0px;
bottom: 0px;
left: 0px;
padding: 120px 50px 180px 50px;
overflow: hidden;
}
.pl-content {
width: 100%;
display: inline-block;
opacity: 1;
color: white;
}
I have a working example https://codepen.io/eddywoods/pen/bGvopmL
I thought if I added overflow-y: auto to the parent element it would auto scroll the content but even when I shrink the screen vertically is doesn't want to auto scroll. Where am I going wrong?

Here at line 12 in css.
body {
overflow-y: hidden !important; // This needs to be auto so that your body can scroll
overflow-x: hidden;
}
you have set the overflow-y of body to hidden. So, your body isn't scrollable. and that's causing the issue.

Do you mean like this?? Take a look at it in full screen and let me know.
$('.burger-wrapper').on('mousedown' , function(){
$('.content-wrapper').toggleClass('show');
});
html, body {
margin: 0;
padding: 0;
background-color: rgba(244, 244, 244, 0.9);
width: 100%;
height: 100%;
}
body {
overflow-y: scroll ;
overflow-x: hidden;
position: relative
}
div {
display: block;
}
.menu-box {
width: 100%;
min-height: 100%;
background-color: #000;
position: fixed;
z-index: 10;
transition: all 1.5s ease-in;
}
.page-links {
width: 100%;
height: 100%;
position: relative;
top: 0px;
left: 0px;
overflow-y: auto;
-webkit-overflow-scrolling: touch;
}
.pl-inner {
position: relative;
width: 100%;
}
.pl-box {
position: relative;
top: 0px;
right: 0px;
bottom: 0px;
left: 0px;
padding: 120px 50px 180px 50px;
overflow: hidden;
}
.pl-content {
width: 100%;
display: inline-block;
opacity: 1;
color: white;
}
.plink {
font-size: 100px;
font-weight: 800;
color: #f4f4f4;
text-transform: uppercase;
margin: 0 0 10px 0;
padding-bottom: 5px;
letter-spacing: -3px;
text-align: left;
text-align: -webkit-left;
display: block;
}
.pspacer {
width: 100%;
height: 10px;
}
/* ---------------------------------------------------------*/
.burger-wrapper {
position: fixed;
top: 41px;
right: 41px;
width: auto;
height: auto;
padding: 5px;
/*background-color: #333;*/
background-color: rgba(228, 228, 228, 0.9);
z-index: 99;
}
.content-wrapper {
position: absolute;
top: 0%;
left: 0%;
width: 100%;
height: 100%;
transition: all 1s cubic-bezier(.36, .17, .06, 1.02);
z-index: 40;
background-color: rgba(244, 244, 244, 1.0);
}
.show {
top: 90%;
}
.logo-wrapper {
position: fixed;
top: 41px;
left: 41px;
font-size: 17px;
font-weight: 900;
letter-spacing: 0px;
text-transform: uppercase;
color: rgba(204, 204, 204, 0.9) !important;
z-index: 99;
width: 150px;
height: 12px;
/*background-color: #333;*/
background-color: rgba(228, 228, 228, 0.9);
}
.container {
position: absolute;
top: 0px;
left: 0px;
bottom: 20px;
width: 100%;
height: 100%;
}
.block {
width: 100%;
height: 80px;
background-color: rgba(244, 244, 244, 0.9);
position: absolute;
z-index: 89;
}
.grid-wrapper {
position: absolute;
width: 100%;
height: 100%;
}
.thumb-grid {
position: absolute;
top: 0px;
right: 0px;
bottom: 0px;
left: 0px;
overflow-y: scroll;
-webkit-overflow-scrolling: touch;
overflow-x: scroll;
padding: 130px 5% 150px 5%;
}
.box {
width: 100%;
height: 200px;
background-color: #333; ;
}
.box:nth-child(even) {
background-color: #999;
}
#media (max-width: 650px){
.plink {
font-size: 56px;
text-align: -webkit-center;
text-align: center;
display: block;
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<div class="menu-box">
<div class="page-links">
<div class="pl-inner">
<div class="pl-box">
<div class="pl-content">
<p>MENU CONTENT goes here......Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean aliquam eget urna et consequat. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse sodales molestie odio a maximus. Pellentesque sit amet augue a leo sollicitudin hendrerit sit amet vel ligula. Nullam placerat dapibus rhoncus. Etiam a nulla sit amet tellus ullamcorper sagittis et pellentesque sapien. Curabitur eu purus eu massa blandit mollis. Vestibulum venenatis faucibus tempus. Curabitur finibus metus ut ipsum semper malesuada. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
</div>
</div>
</div>
</div> <!-- .menu-box end div -->
<div class="logo-wrapper"></div>
<div class="burger-wrapper">click</div>
<div class="content-wrapper">
<div class="container">
<div class="block"></div>
<div class="grid-wrapper">
<div class="thumb-grid">
<p>MAIN PAGE content goes here......Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean aliquam eget urna et consequat. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse sodales molestie odio a maximus. Pellentesque sit amet augue a leo sollicitudin hendrerit sit amet vel ligula. Nullam placerat dapibus rhoncus. Etiam a nulla sit amet tellus ullamcorper sagittis et pellentesque sapien. Curabitur eu purus eu massa blandit mollis. Vestibulum venenatis faucibus tempus. Curabitur finibus metus ut ipsum semper malesuada. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Nunc orci sapien, eleifend a risus quis, accumsan aliquet quam. Cras dolor ex, fringilla quis egestas eget, finibus ut velit. Donec lacinia rutrum enim. Nunc at viverra metus, ac pharetra urna. Sed dui turpis, tincidunt quis sem mattis, consectetur sagittis augue. Aenean porttitor, eros vehicula dapibus egestas, dolor nibh venenatis libero, eu viverra arcu ipsum quis dolor. Ut enim odio, vestibulum eu elit vitae, blandit commodo risus. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Maecenas imperdiet ligula quis ornare ullamcorper. Fusce eu facilisis lectus. Duis ultricies rhoncus eros, eget facilisis dui pulvinar nec. Morbi posuere enim dolor, id finibus eros sagittis id. Cras accumsan lacus.</p>
</div>
</div>
</div> <!-- .container end div -->
</div> <!-- .content-wrapper end div -->

Ok so after a little trial and error I found the answer is to set the position of .page-linksto absolute
Literally no idea if this is a good way to laying stuff out but seems to work. I've updated the Code Pen here

Related

Word-wrap text in overlay

I have the following issue where I don't really know on how to word-wrap the overlay text to my desires. I want the text to cut-off at the bottom of the overlay (or a few pixels above the bottom) and I want it to end it with a triple dot, so something like this: eu dolor sed, euismod ...
$('.container').mouseenter (function () {
//alert($(this).find('.soverlay').innerHeight()); //returns 56.8 px
var hgt = 'calc(100% - ' + parseInt($(this).find('.soverlay').innerHeight()+5) + 'px)';
$(this).find('.overlay').css({'height' : hgt});
});
$('.container').mouseleave (function () {
//alert($('.container .soverlay').innerHeight()); //returns 56.8 px
$(this).find('.overlay').css({'height' : '0px'});
});
.container {
position: relative;
width: 50%;
max-width: 250px;
}
.image {
border-radius: 10px;
display: inline-block;
width: 100%;
height: auto;
box-sizing: border-box;
}
.soverlay {
border-radius: 10px 10px 0px 0px;
box-sizing: border-box;
position: absolute;
top: 0;
background: rgb(0, 0, 0);
background: rgba(0, 0, 0, 0.5); /* Black see-through */
color: #f1f1f1;
width: 100%;
transition: .5s ease;
color: white;
font-size: 16px;
padding: 10px;
text-align: center;
overflow: hidden; /* remove on hover-in; add on hover-out*/
white-space: nowrap; /*remove on hover-in; add on hover-out */
text-overflow: ellipsis;
}
.overlay {
border-radius: 0px 0px 10px 10px;
position: absolute;
bottom: 4px;
left: 0;
right: 0;
background-color: #008CBA;
overflow: hidden;
width: 100%;
height: 0;
transition: .5s ease;
background: rgb(0, 0, 0);
background: rgba(0, 0, 0, 0.5); /* Black see-through */
font-size: 12px;
color: white;
}
.container:hover .overlay {
/* height: calc(100% - 57px); /* change height depending on 'soverlay' height */
border-top: 3px solid yellow;
}
.container:hover .soverlay{
overflow: unset;
white-space: unset;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html>
<body>
<h2>Image Overlay Title</h2>
<p>Hover over the image to see the effect.</p>
<div class="container">
<img src="https://www.w3schools.com/howto/img_avatar.png" alt="Avatar" class="image">
<div class="soverlay">Some people just have very long names</div>
<div class="overlay">This is a very long job description which doesn't really fit in this div. Now the question is how do I cut of the text at the bottom of the overlay. </br></br>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce hendrerit convallis ligula, eget sollicitudin dolor lobortis ut. Duis venenatis, est vel volutpat dictum, magna mi pellentesque dolor, eu suscipit ligula augue eleifend justo. Nunc eleifend diam velit, id maximus eros tristique et. Donec sagittis mattis velit. Morbi gravida tincidunt metus in suscipit. Curabitur pharetra orci nec nunc sodales cursus. Morbi hendrerit id orci non vulputate. Duis nulla turpis, bibendum eu dolor sed, euismod mollis velit. Nullam tellus enim, condimentum porta rutrum ac, feugiat in ex. Sed tristique metus nunc, ut elementum elit hendrerit et. Quisque sed interdum ipsum. Etiam posuere.
</div>
</div>
</body>
</html>
I've managed to make a work-around using PHP by just cutting the length of each string at a certain length and appending the triple dots, but I actually want to try and do it with CSS only (to further improve my front-end skills).
You should add fix width to the .soverlay Div
.soverlay{width:250px;}
and then use the following CSS property
word-wrap: break-word;

Split div with diagonal line

How would you split a div into 2 parts (both containing horizontal text) by a diagonal line?
e.g. see this where 1 has a rectangular background image and 2 has text with a background color:
You can do it with a pseudo element rotated like this:
body {
background-color: #00bcd4;
}
.main {
margin: 50px;
overflow: hidden;
position: relative;
width: 350px;
}
.image {
background: url(https://s-media-cache-ak0.pinimg.com/564x/ca/9b/ca/ca9bca4db9afb09158b76641ea09ddb6.jpg) center center no-repeat;
background-size: cover;
height: 200px;
}
.text {
background-color: white;
padding: 30px;
position: relative;
}
.text > div {
position: relative;
z-index: 1;
}
.text:before {
content: "";
background-color: white;
position: absolute;
height: 100%;
width: 120%;
top: -20px;
left: -10%;
transform: rotate(5deg);
z-index: 0;
}
<div class="main">
<div class="image"></div>
<div class="text">
<div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent vitae gravida purus. Ut quis elit magna. Fusce et mattis sapien. Sed venenatis magna ut ligula facilisis, eget vulputate neque aliquet. Nulla lacinia condimentum leo non aliquet. Integer
et enim dapibus, tempor ipsum non, fringilla enim. Cras semper fermentum dolor, at pharetra dolor ornare sit amet. Morbi eu dictum orci, tincidunt pretium nisi. Sed finibus vulputate eleifend. Nulla ac leo facilisis, fermentum tellus in, feugiat
risus. Curabitur in sem luctus, pellentesque justo nec, aliquet velit. Nam euismod est sit amet ultrices consequat.
</div>
</div>
</div>
As per my knowledge, its cannot be done using any single CSS property directly, you will have to hack it via using pseudo-elements, or best approach will be do it using SVG
.container {
width: 90%;
margin: 0 auto;
}
.box {
width: 200px;
height: 150px;
text-align: center;
}
.box-1 {
background: #ff6347;
}
.box-2 {
background: #0ff;
}
.box-2:before {
display: inline-block;
margin: 0;
margin-top: -30px;
margin-left: -30px;
content: '';
border: 30px solid transparent;
border-right: 200px solid #0ff;
}
<div class="container">
<div class="box box-1"></div>
<div class="box box-2">
TITLE 1
</div>
</div>
.container {
width: 400px;
margin: 0 auto;
}
.box {
width: 200px;
height: 150px;
text-align: center;
float: left;
}
.box-1 {
background: #ff4500;
}
.box-2 {
background: #0ffab9;
}
.box-2:before {
display: inline-block;
margin: 0;
margin-left: -101px;
margin-top: -1px;
position: absolute;
content: '';
width: 0;
height: 0;
border-bottom: 151px solid #0ffab9;
border-left: 30px solid transparent;
}
<div class="container">
<div class="box box-1">
</div>
<div class="box box-2">
TITLE 1
</div>
</div>

Why does span class get moved? [duplicate]

This question already has answers here:
Why is the paragraph not floating beside the profilePic?
(3 answers)
Closed 6 years ago.
Why does making span float:left or display:inline-block or both move the span class below the profilePic?
.content {
margin-top: 30px;
margin-left: 20px;
padding-bottom: 20px;
float: left;
}
.mainContent {
width: 1000px;
float: left;
}
.infoBit {
display: inline-block;
font-size: 1.1em;
padding-right: 10px;
padding-top: 10px;
}
.profilePic {
border: 1px blue solid;
height: 59px;
display: inline-block;
width: 44px;
margin: 0px;
float: left;
margin-right: 3px;
}
span {
margin-top: 0px;
float: left;
}
<div class="content">
<div class="mainContent">
<div class="infoBit">
<div class="profilePic"></div>
<span> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam quis enim ut sapien sodales commodo. Fusce congue, elit a finibus fermentum, diam eros mollis massa, at eleifend sapien dui eget mauris. Donec nec diam enim. Vivamus commodo placerat risus vitae auctor. Cras leo elit, egestas eget dolor vitae, facilisis consequat sem. Mauris facilisis ipsum in porttitor ullamcorper. Nam vel massa sed quam venenatis facilisis. Quisque vitae mollis urna. In egestas nunc sed felis consequat, in malesuada dolor feugiat. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</span>
<div class="social">
<div class="Like"></div>
<div class="Dislike"></div>
<div class="share"></div>
</div>
</div>
</div>
</div>
you need to float only one thing
try this
CSS
.content
{
margin-top : 30px;
margin-left: 20px;
padding-bottom: 20px;
}
.mainContent
{
width: 1000px;
float: left;
}
.infoBit
{
display: inline-block;
font-size: 1.1em;
padding-right: 10px;
padding-top: 10px;
}
.profilePic
{
border:1px blue solid;
height: 59px;
display: inline-block;
width: 44px;
margin: 0px;
float: left;
margin-right: 3px;
}
span
{
margin-top: 0px;
}

Parent div not aligning to center when window scaled

Whenever I rescale/resize my window to smaller size (smartphone sized) all of the three inner div's (.left .center .right) red,green,blue respectively, below each other doesn't align to the center. Please see the attached screenshot to understand. I want all of these three div's to be in the center of the main .container div (pink) whenever the window is scaled down. Would appreciate your inputs.
html,body {
width: 100%;
left: 0px;
top: 0px;
margin: 0px;
height: 100%;
}
.container {
width: auto;
left: 0px;
top: 0px;
float: none;
width: auto;
max-width: auto;
position: relative;
background-color: rgba(216, 86, 112, 0.5);
height: 100%;
margin-top: auto;
margin-right: 5%;
margin-left: 5%;
display: block;
right: 0px;
}
.top {
width: 100%;
left: 0px;
top: 0px;
background-color: rgba(204, 51, 0, 1);
height: 10%;
position: relative;
margin: 0px;
text-align: center;
}
.left {
float: left;
height: auto;
width: 331px;
background-color: rgba(255, 0, 0, 1);
margin-left: auto;
margin-right: auto;
position: relative;
left: auto;
top: 0px;
}
.center {
float: left;
height: auto;
width: 331px;
background-color: rgba(0, 255, 0, 1);
margin-left: 0px;
margin-right: auto;
position: relative;
left: 0px;
}
.right {
float: left;
height: auto;
width: 331px;
background-color: rgba(0, 0, 255, 1);
margin-left: 0px;
margin-right: auto;
position: relative;
left: 0px;
top: 0px;
}
<div class="container">
<div class="top"></div>
<div class="left">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vehicula quis dolor sed euismod. Fusce id tellus est. Nam eu rutrum urna. Donec mattis a libero faucibus euismod. Suspendisse iaculis placerat sapien in ultrices.
</div>
<div class="center">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vehicula quis dolor sed euismod. Fusce id tellus est. Nam eu rutrum urna. Donec mattis a libero faucibus euismod. Suspendisse iaculis placerat sapien in ultrices.
</div>
<div class="right">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vehicula quis dolor sed euismod. Fusce id tellus est. Nam eu rutrum urna. Donec mattis a libero faucibus euismod. Suspendisse iaculis placerat sapien in ultrices.
</div>
</div>
My method is to have separate code for css that overwrites the code when the conditions are met. For this you would decide what you want to max width to be before it changes and add the code:
#media only screen and (max-width: 1187px)
{
new css here
}
For your particular project you would just have to change the floats and margins (and the width that you want (the 1187 here)) so:
#media only screen and (max-width: 1187px)
{
.left {
margin-right:auto;
margin-left:auto;
float:none;
}
.center {
margin-right:auto;
margin-left:auto;
float:none;
}
.right {
margin-right:auto;
margin-left:auto;
float:none;
}
}
UPD. Three blocks int the center of the parent
I have seen the cooment about three blocks< which are centered like - - -. This is my solution.
html, body {
margin: 0px;
height: 100%;
}
.container {
background-color: rgba(216, 86, 112, 0.5);
height: 100%;
margin: 0 5%;
text-align: center;
}
.top {
width: 100%;
background-color: rgba(204, 51, 0, 1);
height: 10%;
}
.left,
.center,
.right {
display: inline-block;
width: 331px;
}
.left { background-color: rgba(255, 0, 0, 1); }
.center { background-color: rgba(0, 255, 0, 1); }
.right { background-color: rgba(0, 0, 255, 1); }
<div class="container">
<div class="top"></div>
<div class="left">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vehicula quis dolor sed euismod. Fusce id tellus est. Nam eu rutrum urna. Donec mattis a libero faucibus euismod. Suspendisse iaculis placerat sapien in ultrices.
</div>
<div class="center">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vehicula quis dolor sed euismod. Fusce id tellus est. Nam eu rutrum urna. Donec mattis a libero faucibus euismod. Suspendisse iaculis placerat sapien in ultrices.
</div>
<div class="right">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vehicula quis dolor sed euismod. Fusce id tellus est. Nam eu rutrum urna. Donec mattis a libero faucibus euismod. Suspendisse iaculis placerat sapien in ultrices.
</div>
</div>
Media query
I prefer the mobile first design. The first step is to adjust the webpage for a smartphone. Then determine the changes that occur when the screen becomes wider. Then describe the changes for an even wider screen. And so on.
Let's calculate the width of the screen, in which the three blocks will fit in the same row. Three 331px wide blocks occupied by 993px. This is 90% of the screen width. 10% falls on the margins of the container. Therefore
993px x 100% / 90% = 1104px
So I've added a media query for this breakpoint.
Also I've commented out the parts that are not needed to solve described problem. Please check the result.
html, body {
margin: 0px;
height: 100%;
/*
width: 100%;
left: 0px;
top: 0px;
*/
}
.container {
background-color: rgba(216, 86, 112, 0.5);
height: 100%;
margin-right: 5%;
margin-left: 5%;
/*
margin-top: auto;
display: block;
right: 0px;
width: auto;
left: 0px;
top: 0px;
float: none;
width: auto;
max-width: auto;
position: relative;
*/
}
.top {
width: 100%;
background-color: rgba(204, 51, 0, 1);
height: 10%;
text-align: center;
/*
left: 0px;
top: 0px;
position: relative;
margin: 0px;
*/
}
.left,
.center,
.right {
width: 331px;
margin-left: auto;
margin-right: auto;
}
#media (min-width: 1104px) {
.left,
.center,
.right {
float: left;
height: auto;
width: 331px;
/*
position: relative;
left: auto;
top: 0px;
*/
}
}
.left { background-color: rgba(255, 0, 0, 1); }
.center { background-color: rgba(0, 255, 0, 1); }
.right { background-color: rgba(0, 0, 255, 1); }
<div class="container">
<div class="top"></div>
<div class="left">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vehicula quis dolor sed euismod. Fusce id tellus est. Nam eu rutrum urna. Donec mattis a libero faucibus euismod. Suspendisse iaculis placerat sapien in ultrices.
</div>
<div class="center">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vehicula quis dolor sed euismod. Fusce id tellus est. Nam eu rutrum urna. Donec mattis a libero faucibus euismod. Suspendisse iaculis placerat sapien in ultrices.
</div>
<div class="right">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vehicula quis dolor sed euismod. Fusce id tellus est. Nam eu rutrum urna. Donec mattis a libero faucibus euismod. Suspendisse iaculis placerat sapien in ultrices.
</div>
</div>
Is this what you want ? https://jsfiddle.net/xofoh5yp/
Just removed floats and left position styles.
<div class="container">
<div class="top"></div>
<div class="left">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vehicula quis dolor sed euismod. Fusce id tellus est. Nam eu rutrum urna. Donec mattis a libero faucibus euismod. Suspendisse iaculis placerat sapien in ultrices.
</div>
<div class="center">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vehicula quis dolor sed euismod. Fusce id tellus est. Nam eu rutrum urna. Donec mattis a libero faucibus euismod. Suspendisse iaculis placerat sapien in ultrices.
</div>
<div class="right">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vehicula quis dolor sed euismod. Fusce id tellus est. Nam eu rutrum urna. Donec mattis a libero faucibus euismod. Suspendisse iaculis placerat sapien in ultrices.
</div>
</div>
html,body {
width: 100%;
left: 0px;
top: 0px;
margin: 0px;
height: 100%;
}
.container {
width: auto;
left: 0px;
top: 0px;
float: none;
width: auto;
max-width: auto;
position: relative;
background-color: rgba(216, 86, 112, 0.5);
height: 100%;
margin-top: auto;
margin-right: 5%;
margin-left: 5%;
display: block;
right: 0px;
}
.top {
width: 100%;
left: 0px;
top: 0px;
background-color: rgba(204, 51, 0, 1);
height: 10%;
position: relative;
margin: 0px;
text-align: center;
}
.left {
height: auto;
width: 331px;
background-color: rgba(255, 0, 0, 1);
margin-left: auto;
margin-right: auto;
position: relative;
}
.center {
width: 331px;
background-color: rgba(0, 255, 0, 1);
margin-left: auto;
margin-right: auto;
position: relative;
}
.right {
height: auto;
width: 331px;
background-color: rgba(0, 0, 255, 1);
margin-left: auto;
margin-right: auto;
position: relative;
}
Here is the code if you want them to be in one line :
Fiddle: https://jsfiddle.net/xofoh5yp/1/
Basically, added container DIV and then added % widths.
<div class="container">
<div class="top"></div>
<div>
<div class="left">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vehicula quis dolor sed euismod. Fusce id tellus est. Nam eu rutrum urna. Donec mattis a libero faucibus euismod. Suspendisse iaculis placerat sapien in ultrices.
</div>
<div class="center">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vehicula quis dolor sed euismod. Fusce id tellus est. Nam eu rutrum urna. Donec mattis a libero faucibus euismod. Suspendisse iaculis placerat sapien in ultrices.
</div>
<div class="right">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vehicula quis dolor sed euismod. Fusce id tellus est. Nam eu rutrum urna. Donec mattis a libero faucibus euismod. Suspendisse iaculis placerat sapien in ultrices.
</div>
</div>
</div>
html,body {
width: 100%;
left: 0px;
top: 0px;
margin: 0px;
height: 100%;
}
.container {
width: auto;
left: 0px;
top: 0px;
float: none;
width: auto;
max-width: auto;
position: relative;
background-color: rgba(216, 86, 112, 0.5);
height: 100%;
margin-top: auto;
margin-right: 5%;
margin-left: 5%;
display: block;
right: 0px;
}
.top {
width: 100%;
left: 0px;
top: 0px;
background-color: rgba(204, 51, 0, 1);
height: 10%;
position: relative;
margin: 0px;
text-align: center;
}
.left {
height: auto;
width: 33%;
background-color: rgba(255, 0, 0, 1);
margin-left: auto;
margin-right: auto;
position: relative;
float:left;
}
.center {
width: 33%;
background-color: rgba(0, 255, 0, 1);
margin-left: auto;
margin-right: auto;
position: relative;
float:left;
}
.right {
height: auto;
width: 34%;
background-color: rgba(0, 0, 255, 1);
margin-left: auto;
margin-right: auto;
position: relative;
float:left;
}
Another fiddle with margin : https://jsfiddle.net/xofoh5yp/2/

How to make an image display above the background of an :after element

Not sure how else to title this (if someone else has a better title feel free to edit the post) but essentially the clients wants responsive aarced lines along the top one pink and one purple as shown here in the screenshot:
Im currently accomplishing this (since an image is not responsive enough) using the element (pink) a ::before (the purple area) and an ::after (the pink line) Now i need an image slider to peek in below it but currently its being covered by the layers before it:
it needs to look like this mockup:
Is there any way i can acomplish this?
html:
<div class="topbar">
<div class="container">
<div class="logo"></div>
</div>
</div>
<div class="container firstbelow"></div>
css:
.topbar {
position: relative;
width: 100%;
height: 200px;
background: pink;
overflow: hidden;
z-index: 5;
}
.topbar:after {
position: absolute;
content: "";
left: -20%;
top: 50%;
width: 140%;
height: 300px;
background: rgb(250, 244, 255);
background-repeat: no-repeat;
background-position: center top;
border-radius: 100% 0 0 0 / 90%;
border-top: 5px solid #ff88bb;
z-index: 5;
}
.topbar:before {
position: absolute;
content: "";
left: -20%;
top: 42%;
width: 140%;
height: 150%;
background: #8855bb;
box-shadow: inset 10px -10px 5px -10px #000;
border-radius: 80% 0 0 0 / 60%;
-ms-transform: rotate(-3deg);
-webkit-transform: rotate(-3deg);
transform: rotate(-1deg);
z-index: 5;
}
.firstbelow {
margin-top: -95px;
height: 300px;
background-image: url(../images/slider/Commercial.png);
z-index: 4
}
(Note: Yes, i am aware that the ::after element has a white background. if it does not then the pink and putple layers show through and i still cannot see the slider image)
you may also use a container in a fixed position and set a padding-top or margin top to the content that it may also slide underneath.
You can also play with gradient , shadow and radius to draw your shape:
snippet below or codepen
header {
position: fixed;
left: 0;
width: 100%;
}
header div {
background: linear-gradient(165deg, #FFC0CB 31%, transparent 31.5%), linear-gradient(175deg, #FFC0CB 41%, transparent 41.5%), linear-gradient(179.5deg, #FFC0CB 32.5%, transparent 33%);
padding-top: 30px;
position: relative;
top: 0;
left: 0;
right: 0;
width: 100%;
z-index: 1;
height: 220px;
}
header:after {
z-index: -1;
content: '';
display: block;
height: 200px;
pointer-events: none;
left: 0px;
width: 100%;
top: 120px;
margin: -55px 0 0 0;
border-radius: 1500px 0 0 0 / 150px 0 0 0;
box-shadow: inset 50px 80px 0 -70px #FFC0CB, inset 20px 90px 0 -70px #8855BB, inset 30px 80px 0 -50px #FF88BB;
position: absolute;
box-sizing: border-box;
border-top: solid #FFC0CB 0;
}
body {
margin: 0 auto;
width: 800px;
max-width:100%;
}
nav {
width: 800px;
max-width:100%;
margin: auto;
display: flex;
justify-content: space-between;
}
nav img {
border-radius: 50% / 3em;
box-shadow: 0 0 5px;
height: 80px;
width: 80px;
}
nav a {
vertical-align: top;
margin: 0 1em;
color: gray
}
main {
padding-top: 160px;
color: #FF88BB;
text-shadow: 1px 1px gray;
text-align: justify
}
h1,
h2,
h3,
pre {
color: gray;
display: table;
border-bottom: solid #FFC0CB;
padding: 0 0.25em;
line-height: 0.8em;
}
pre {
background: lightgray;
}
li {
color: #8855BB
}
<header>
<div>
<nav>
<a href="#">
<img src="http://lorempixel.com/90/100/food/8" />
</a>
<span> link
link
link
link
link
link
</span>
</nav>
</div>
</header>
<main>
<h1>HTML Ipsum Presents</h1>
<p><strong>Pellentesque habitant morbi tristique</strong> 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. <em>Aenean ultricies mi vitae est.</em> Mauris
placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, <code>commodo vitae</code>, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis
tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis.</p>
<h2>Header Level 2</h2>
<ol>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
<li>Aliquam tincidunt mauris eu risus.</li>
</ol>
<blockquote>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus magna. Cras in mi at felis aliquet congue. Ut a est eget ligula molestie gravida. Curabitur massa. Donec eleifend, libero at sagittis mollis, tellus est malesuada tellus, at luctus turpis
elit sit amet quam. Vivamus pretium ornare est.</p>
</blockquote>
<h3>Header Level 3</h3>
<ul>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
<li>Aliquam tincidunt mauris eu risus.</li>
</ul>
<pre><code>
#header h1 a {
display: block;
width: 300px;
height: 80px;
}
</code></pre>
</main>
Put the topbar as an absolute element at the top of the page
.topbar {
top: 0;
left: 0;
position: absolute;
width: 100%;
height: 200px;
background: pink;
z-index: 5;
height: <static_dimension>;
}