I am trying to make a website that looks like a giant ticket, so no matter how much content there is on the page, it should always look like a ticket.
Requirements:
Ticket should always cover entire page;
Bottom part should support overflowing content;
Scrollbar should be on ticket/page and not on part of the ticket;
Here is what I have so far:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
html {
box-sizing: border-box;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
html,
body {
/* height: 100%; */
margin: 0;
}
body {
background-color: white;
}
#container {
overflow-y: auto;
}
#ticket {
position: fixed;
top: 0;
left: 0;
padding: 5px;
height: 100%;
width: 100%;
filter: drop-shadow(-1px 6px 3px rgba(50, 50, 0, 0.5));
}
#topPart {
clip-path: polygon(
0% 0%,
100% 0%,
100% 67px,
calc(100% - 25px) 77px,
25px 77px,
0% 67px
);
background-color: tomato;
height: 75px;
width: 100%;
border-bottom: 2px dashed white;
}
#bottomPart {
background-color: tomato;
clip-path: polygon(
25px -2px,
calc(100% - 25px) -2px,
100% 8px,
100% 100%,
0% 100%,
0% 8px
);
height: calc(100% - 75px - 5px);
border-top: 2px dashed white;
padding: 5px;
overflow-y: auto;
}
#content {
height: 300vh;
}
</style>
</head>
<body>
<div id="container">
<div id="ticket">
<div id="topPart"></div>
<div id="bottomPart">
<div id="content">content</div>
</div>
</div>
</div>
</body>
</html>
As you can see, the scrollbar is currently on the bottom part of the ticket, which is undesirable.
So I tried moving the scrollbar up to it's parent element, like this:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
html {
box-sizing: border-box;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
html,
body {
/* height: 100%; */
margin: 0;
}
body {
background-color: white;
}
#container {
overflow-y: auto;
}
#ticket {
position: fixed;
top: 0;
left: 0;
padding: 5px;
height: 100%;
width: 100%;
filter: drop-shadow(-1px 6px 3px rgba(50, 50, 0, 0.5));
overflow-y: auto;
}
#topPart {
clip-path: polygon(
0% 0%,
100% 0%,
100% 67px,
calc(100% - 25px) 77px,
25px 77px,
0% 67px
);
background-color: tomato;
height: 75px;
width: 100%;
border-bottom: 2px dashed white;
}
#bottomPart {
background-color: tomato;
clip-path: polygon(
25px -2px,
calc(100% - 25px) -2px,
100% 8px,
100% 100%,
0% 100%,
0% 8px
);
height: calc(100% - 75px - 5px);
border-top: 2px dashed white;
padding: 5px;
}
#content {
height: 300vh;
}
</style>
</head>
<body>
<div id="container">
<div id="ticket">
<div id="topPart"></div>
<div id="bottomPart">
<div id="content">content</div>
</div>
</div>
</div>
</body>
</html>
But as you can see, this makes the fixed ticket longer than the actual page and allows you to scroll past the ticket, which is undesirable.
I have also tried solutions from this thread:
CSS Stretch content container height if empty overflow if too big
But unfortunately none of them worked for me.
This solution might be (admittedly) very hacky, but solves your requirements. Placing the content outside of the fixed elements and using z-index values on fixed elements can allow you to hide (or show) what is visible (see snippet). I added filler content to demonstrate the results.
I moved the #content ID out of the #ticket element to separate it from its former parents and allow it to scroll and not be fixed in position. I added a few other position, z-index and other position and style values on the ticket elements to keep the appearance you are looking for.
I am assuming you want the scrollbar outside of the ticket and want the scrollbar track to be the height of the ticket/page. I added some other elements (#filler and #dash) to cover up the overflow text on top with the same color as the ticket and recreate the top/bottom border between the top and bottom parts. If you need content in the top part of the ticket, it can be added below the "ticket" (outside the #container #ticket IDs). If you want to adjust the height of the top area a variable can be set and used to replace some of the heights in the CSS, with some additional adjustments.
Again, I would stress this is an imperfect solution, but your requirements are not part of the typical functionality of standard HTML and CSS. If anyone has another approach in HTML and CSS I encourage them to share, and if you would like to use JavaScript there are other options with that, as well.
Techniques can be reviewed in the MDN Web docs for z-index and MDN Web docs for position. Disclaimer: I have not done cross-browser checking for the solution to your question.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
html {
box-sizing: border-box;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
html,
body {
/* height: 100%; */
margin: 0;
}
body {
background-color: white;
}
#container {
overflow-y: auto;
}
#ticket {
position: fixed;
top: 0;
left: 0;
padding: 5px;
height: 100%;
width: 100%;
filter: drop-shadow(-1px 6px 3px rgba(50, 50, 0, 0.5));
}
#topPart {
position: fixed;
top: 5px;
left: 5px;
clip-path: polygon(0% 0%, 100% 0%, 100% 67px, calc(100% - 25px) 77px, 25px 77px, 0% 67px);
background-color: tomato;
height: 75px;
width: calc(100% - 10px);
z-index: 4;
}
#bottomPart {
position: fixed;
top: 80px;
left: 5px;
background-color: tomato;
clip-path: polygon(25px -2px, calc(100% - 25px) -2px, 100% 8px, 100% 100%, 0% 100%, 0% 8px);
height: calc(100% - 75px - 10px);
width: calc(100% - 10px);
border-top: 2px dashed white;
padding: 5px;
z-index: -1;
}
#content {
position: absolute;
top: 6px;
left: 25px;
height: calc(100vh - 12px);
width: calc(100% - 25px);
padding-right: 25px;
padding-top: 80px;
overflow-y: auto;
z-index: 1;
}
#filler {
position: fixed;
top: 5px;
left: 25px;
height: 80px;
width: calc(100% - 50px);
background-color: tomato;
z-index: 2;
}
#dash {
position: fixed;
top: 80px;
left: 25px;
height: 4px;
width: calc(100% - 50px);
background-color: tomato;
border-top: 2px dashed white;
border-bottom: 2px dashed white;
z-index: 3;
}
</style>
</head>
<body>
<div id="container">
<div id="ticket">
<div id="topPart"></div>
<div id="bottomPart"></div>
</div>
<!-- filler and dash border -->
<div id="filler"></div>
<div id="dash"></div>
<!-- text content, with more added for demonstration -->
<div id="content">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque tincidunt nisi suscipit sem dignissim bibendum. Etiam a vehicula nisl. Maecenas dignissim, urna non facilisis hendrerit, metus urna interdum tellus, quis rutrum justo mauris vitae
massa. Nunc eu ultrices sapien. Morbi ultrices gravida maximus. Sed sit amet lectus leo. Donec vulputate arcu vitae orci facilisis elementum a a lorem. In accumsan, erat ac commodo molestie, ligula tellus consectetur odio, non congue ante urna
eu erat. Morbi nec iaculis mauris. Vivamus suscipit rhoncus metus, eu rhoncus ipsum bibendum sed. Curabitur maximus pellentesque tincidunt. Nulla nunc dolor, sagittis a metus at, hendrerit elementum leo. Aliquam congue nibh diam, nec ornare odio
feugiat ac. Maecenas mollis dui ac libero consectetur, vel hendrerit felis hendrerit. Aenean felis sapien, condimentum non ante at, luctus suscipit augue. Aenean faucibus ullamcorper urna, a tempor augue ultrices ut. </p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque tincidunt nisi suscipit sem dignissim bibendum. Etiam a vehicula nisl. Maecenas dignissim, urna non facilisis hendrerit, metus urna interdum tellus, quis rutrum justo mauris vitae
massa. Nunc eu ultrices sapien. Morbi ultrices gravida maximus. Sed sit amet lectus leo. Donec vulputate arcu vitae orci facilisis elementum a a lorem. In accumsan, erat ac commodo molestie, ligula tellus consectetur odio, non congue ante urna
eu erat. Morbi nec iaculis mauris. Vivamus suscipit rhoncus metus, eu rhoncus ipsum bibendum sed. Curabitur maximus pellentesque tincidunt. Nulla nunc dolor, sagittis a metus at, hendrerit elementum leo. Aliquam congue nibh diam, nec ornare odio
feugiat ac. Maecenas mollis dui ac libero consectetur, vel hendrerit felis hendrerit. Aenean felis sapien, condimentum non ante at, luctus suscipit augue. Aenean faucibus ullamcorper urna, a tempor augue ultrices ut. </p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque tincidunt nisi suscipit sem dignissim bibendum. Etiam a vehicula nisl. Maecenas dignissim, urna non facilisis hendrerit, metus urna interdum tellus, quis rutrum justo mauris vitae
massa. Nunc eu ultrices sapien. Morbi ultrices gravida maximus. Sed sit amet lectus leo. Donec vulputate arcu vitae orci facilisis elementum a a lorem. In accumsan, erat ac commodo molestie, ligula tellus consectetur odio, non congue ante urna
eu erat. Morbi nec iaculis mauris. Vivamus suscipit rhoncus metus, eu rhoncus ipsum bibendum sed. Curabitur maximus pellentesque tincidunt. Nulla nunc dolor, sagittis a metus at, hendrerit elementum leo. Aliquam congue nibh diam, nec ornare odio
feugiat ac. Maecenas mollis dui ac libero consectetur, vel hendrerit felis hendrerit. Aenean felis sapien, condimentum non ante at, luctus suscipit augue. Aenean faucibus ullamcorper urna, a tempor augue ultrices ut. </p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque tincidunt nisi suscipit sem dignissim bibendum. Etiam a vehicula nisl. Maecenas dignissim, urna non facilisis hendrerit, metus urna interdum tellus, quis rutrum justo mauris vitae
massa. Nunc eu ultrices sapien. Morbi ultrices gravida maximus. Sed sit amet lectus leo. Donec vulputate arcu vitae orci facilisis elementum a a lorem. In accumsan, erat ac commodo molestie, ligula tellus consectetur odio, non congue ante urna
eu erat. Morbi nec iaculis mauris. Vivamus suscipit rhoncus metus, eu rhoncus ipsum bibendum sed. Curabitur maximus pellentesque tincidunt. Nulla nunc dolor, sagittis a metus at, hendrerit elementum leo. Aliquam congue nibh diam, nec ornare odio
feugiat ac. Maecenas mollis dui ac libero consectetur, vel hendrerit felis hendrerit. Aenean felis sapien, condimentum non ante at, luctus suscipit augue. Aenean faucibus ullamcorper urna, a tempor augue ultrices ut. </p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque tincidunt nisi suscipit sem dignissim bibendum. Etiam a vehicula nisl. Maecenas dignissim, urna non facilisis hendrerit, metus urna interdum tellus, quis rutrum justo mauris vitae
massa. Nunc eu ultrices sapien. Morbi ultrices gravida maximus. Sed sit amet lectus leo. Donec vulputate arcu vitae orci facilisis elementum a a lorem. In accumsan, erat ac commodo molestie, ligula tellus consectetur odio, non congue ante urna
eu erat. Morbi nec iaculis mauris. Vivamus suscipit rhoncus metus, eu rhoncus ipsum bibendum sed. Curabitur maximus pellentesque tincidunt. Nulla nunc dolor, sagittis a metus at, hendrerit elementum leo. Aliquam congue nibh diam, nec ornare odio
feugiat ac. Maecenas mollis dui ac libero consectetur, vel hendrerit felis hendrerit. Aenean felis sapien, condimentum non ante at, luctus suscipit augue. Aenean faucibus ullamcorper urna, a tempor augue ultrices ut. </p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque tincidunt nisi suscipit sem dignissim bibendum. Etiam a vehicula nisl. Maecenas dignissim, urna non facilisis hendrerit, metus urna interdum tellus, quis rutrum justo mauris vitae
massa. Nunc eu ultrices sapien. Morbi ultrices gravida maximus. Sed sit amet lectus leo. Donec vulputate arcu vitae orci facilisis elementum a a lorem. In accumsan, erat ac commodo molestie, ligula tellus consectetur odio, non congue ante urna
eu erat. Morbi nec iaculis mauris. Vivamus suscipit rhoncus metus, eu rhoncus ipsum bibendum sed. Curabitur maximus pellentesque tincidunt. Nulla nunc dolor, sagittis a metus at, hendrerit elementum leo. Aliquam congue nibh diam, nec ornare odio
feugiat ac. Maecenas mollis dui ac libero consectetur, vel hendrerit felis hendrerit. Aenean felis sapien, condimentum non ante at, luctus suscipit augue. Aenean faucibus ullamcorper urna, a tempor augue ultrices ut. </p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque tincidunt nisi suscipit sem dignissim bibendum. Etiam a vehicula nisl. Maecenas dignissim, urna non facilisis hendrerit, metus urna interdum tellus, quis rutrum justo mauris vitae
massa. Nunc eu ultrices sapien. Morbi ultrices gravida maximus. Sed sit amet lectus leo. Donec vulputate arcu vitae orci facilisis elementum a a lorem. In accumsan, erat ac commodo molestie, ligula tellus consectetur odio, non congue ante urna
eu erat. Morbi nec iaculis mauris. Vivamus suscipit rhoncus metus, eu rhoncus ipsum bibendum sed. Curabitur maximus pellentesque tincidunt. Nulla nunc dolor, sagittis a metus at, hendrerit elementum leo. Aliquam congue nibh diam, nec ornare odio
feugiat ac. Maecenas mollis dui ac libero consectetur, vel hendrerit felis hendrerit. Aenean felis sapien, condimentum non ante at, luctus suscipit augue. Aenean faucibus ullamcorper urna, a tempor augue ultrices ut. </p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque tincidunt nisi suscipit sem dignissim bibendum. Etiam a vehicula nisl. Maecenas dignissim, urna non facilisis hendrerit, metus urna interdum tellus, quis rutrum justo mauris vitae
massa. Nunc eu ultrices sapien. Morbi ultrices gravida maximus. Sed sit amet lectus leo. Donec vulputate arcu vitae orci facilisis elementum a a lorem. In accumsan, erat ac commodo molestie, ligula tellus consectetur odio, non congue ante urna
eu erat. Morbi nec iaculis mauris. Vivamus suscipit rhoncus metus, eu rhoncus ipsum bibendum sed. Curabitur maximus pellentesque tincidunt. Nulla nunc dolor, sagittis a metus at, hendrerit elementum leo. Aliquam congue nibh diam, nec ornare odio
feugiat ac. Maecenas mollis dui ac libero consectetur, vel hendrerit felis hendrerit. Aenean felis sapien, condimentum non ante at, luctus suscipit augue. Aenean faucibus ullamcorper urna, a tempor augue ultrices ut. </p>
</div>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
html {
box-sizing: border-box;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
html,
body {
/* height: 100%; */
margin: 0;
}
body {
background-color: white;
}
#container {
width:100%;
height:100vh;
}
#ticket {
position: fixed;
top: 0;
left: 0;
padding: 5px;
height: 100%;
width: 100%;
filter: drop-shadow(-1px 6px 3px rgba(50, 50, 0, 0.5));
}
#topPart {
clip-path: polygon(
0% 0%,
100% 0%,
100% 67px,
calc(100% - 25px) 77px,
25px 77px,
0% 67px
);
background-color: tomato;
height: 75px;
width: 100%;
border-bottom: 2px dashed white;
}
#bottomPart {
overflow-y: auto;
background-color: tomato;
clip-path: polygon(
25px -2px,
calc(100% - 25px) -2px,
100% 8px,
100% 100%,
0% 100%,
0% 8px
);
height: calc(100% - 75px - 5px);
border-top: 2px dashed white;
padding: 5px;
}
</style>
</head>
<body>
<div id="container">
<div id="ticket">
<div id="topPart"></div>
<div id="bottomPart">
<div id="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam ullamcorper ligula in metus faucibus varius. Vivamus dignissim justo sit amet nibh varius, vel eleifend dolor finibus. Sed vestibulum dui sit amet laoreet mollis. Duis at aliquam nibh. Nullam nec volutpat orci. Vivamus vel leo eros. Nam commodo condimentum laoreet. Vivamus vulputate et mauris a bibendum. Sed bibendum mi vel massa tempor porttitor. Cras sed lectus ac lorem imperdiet suscipit ut sed dolor. Fusce convallis dolor sit amet risus vestibulum, a dictum orci bibendum.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam ullamcorper ligula in metus faucibus varius. Vivamus dignissim justo sit amet nibh varius, vel eleifend dolor finibus. Sed vestibulum dui sit amet laoreet mollis. Duis at aliquam nibh. Nullam nec volutpat orci. Vivamus vel leo eros. Nam commodo condimentum laoreet. Vivamus vulputate et mauris a bibendum. Sed bibendum mi vel massa tempor porttitor. Cras sed lectus ac lorem imperdiet suscipit ut sed dolor. Fusce convallis dolor sit amet risus vestibulum, a dictum orci bibendum.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam ullamcorper ligula in metus faucibus varius. Vivamus dignissim justo sit amet nibh varius, vel eleifend dolor finibus. Sed vestibulum dui sit amet laoreet mollis. Duis at aliquam nibh. Nullam nec volutpat orci. Vivamus vel leo eros. Nam commodo condimentum laoreet. Vivamus vulputate et mauris a bibendum. Sed bibendum mi vel massa tempor porttitor. Cras sed lectus ac lorem imperdiet suscipit ut sed dolor. Fusce convallis dolor sit amet risus vestibulum, a dictum orci bibendum.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam ullamcorper ligula in metus faucibus varius. Vivamus dignissim justo sit amet nibh varius, vel eleifend dolor finibus. Sed vestibulum dui sit amet laoreet mollis. Duis at aliquam nibh. Nullam nec volutpat orci. Vivamus vel leo eros. Nam commodo condimentum laoreet. Vivamus vulputate et mauris a bibendum. Sed bibendum mi vel massa tempor porttitor. Cras sed lectus ac lorem imperdiet suscipit ut sed dolor. Fusce convallis dolor sit amet risus vestibulum, a dictum orci bibendum.</div>
</div>
</div>
</div>
</body>
</html>
Inspired by the answer of Katie, I tried playing around with lots of fixed elements and clip-paths. After a couple of failed attempts I found a workable solution:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
/* Usefull links:
https://css-tricks.com/inheriting-box-sizing-probably-slightly-better-best-practice/
https://stackoverflow.com/questions/34570944/css-stretch-content-container-height-if-empty-overflow-if-too-big
https://stackoverflow.com/questions/58283119/create-a-transparent-window-in-a-div-background-with-css-and-javascript
*/
html {
box-sizing: border-box;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
html,
body {
/* height: 100%; */
margin: 0;
}
body {
background-color: white;
}
#BottomContent {
margin: 10px;
margin-top: 83px;
width: calc(100% - 10px - 10px);
background-color: purple;
}
#fixedTicket {
width: 100%;
height: 100%;
}
#background {
position: fixed;
top: 0;
bottom: 0;
background-color: white;
clip-path: polygon(
0% 0%,
0% 100%,
5px 100%,
5px calc(100% - 5px),
/* Linker inham begin*/ 5px 87px,
25px 77px,
5px 67px /* Linker inham eind */,
5px 5px,
calc(100% - 5px) 5px,
/* Rechter inham begin */ calc(100% - 5px) 67px,
calc(100% - 25px) 77px,
calc(100% - 5px) 87px /* Rechter inham eind */,
calc(100% - 5px) calc(100% - 5px),
5px calc(100% - 5px),
5px 100%,
100% 100%,
100% 0%
);
width: 100%;
height: 100%;
}
/* TOP */
#bottomTop {
background-color: tomato;
clip-path: polygon(
5px 67px,
24px 77px,
calc(100% - 24px) 77px,
calc(100% - 5px) 67px,
calc(100% - 5px - 5px) 64px,
calc(100% - 23px) 70px,
23px 70px,
10px 64px
);
width: 100%;
height: 77px;
position: fixed;
top: 0px;
left: 0px;
border-bottom: 2px dashed white;
}
#leftTop {
left: 5px;
top: 5px;
background-color: tomato;
position: fixed;
width: 5px;
height: 62px;
}
#rightTop {
right: 5px;
top: 5px;
background-color: tomato;
position: fixed;
width: 5px;
height: 62px;
}
#topTop {
top: 5px;
left: 5px;
background-color: tomato;
position: fixed;
height: 5px;
width: calc(100% - 5px - 5px);
}
/* Top CONTENT */
#topContent {
background-color: tomato;
position: fixed;
left: 10px;
top: 10px;
width: calc(100% - 10px - 10px);
height: 62px;
clip-path: polygon(
0 0,
100% 0,
100% 55px,
calc(100% - 12px) 61px,
12px 61px,
0 55px
);
}
/* BOTTOM */
#topBottom {
background-color: tomato;
clip-path: polygon(
5px 10px,
24px 0px,
calc(100% - 24px) 0px,
calc(100% - 5px) 10px,
calc(100% - 5px - 5px) 12px,
calc(100% - 22px) 6px,
22px 6px,
10px 12px
);
width: 100%;
height: 13px;
position: fixed;
top: 77px;
left: 0px;
border-top: 2px dashed white;
}
#leftBottom {
background-color: tomato;
position: fixed;
left: 5px;
bottom: 5px;
height: calc(100% - 77px - 10px - 5px);
width: 5px;
box-shadow: -3px 2px 3px rgba(0, 0, 0, 0.2);
}
#rightBottom {
background-color: tomato;
position: fixed;
right: 5px;
bottom: 5px;
height: calc(100% - 77px - 10px - 5px);
width: 5px;
box-shadow: 3px 2px 2px rgba(50, 50, 0, 0.2);
}
#bottomBottom {
background-color: tomato;
position: fixed;
left: 5px;
bottom: 5px;
height: 5px;
width: calc(100% - 5px - 5px);
box-shadow: 0px 3px 3px rgba(50, 50, 0, 0.2);
}
</style>
</head>
<body>
<div id="ticket">
<div id="bottomContent">
<div style="height: 100vh; background-color: purple"></div>
<div style="height: 100vh; background-color: orange"></div>
<div style="height: 100vh; background-color: tomato"></div>
</div>
<div id="fixedTicket">
<!-- White background -->
<div id="background"></div>
<!-- Actual ticket shapes -->
<div id="top">
<div id="topTop"></div>
<div id="bottomTop"></div>
<div id="leftTop"></div>
<div id="rightTop"></div>
</div>
<div id="topContent"></div>
<div id="bottom">
<div id="topBottom"></div>
<div id="leftBottom"></div>
<div id="rightBottom"></div>
<div id="bottomBottom"></div>
</div>
</div>
</div>
</body>
</html>
This solution can be simplified even more by using larger clip-paths, but I decided for more separate fixed elements, since it's easier to control shadows that way (which I will need later on).
If you want to go the clip-path way, make sure to take a look at this:
Create a transparent window in a div background with css and javascript
I made HTML page, with left side navbar(vertical), position fixed , so it will not move when i scroll down the other div(the guide with text),
after that div with text.
I am trying to make it responsive, but since it is fixed position it won't help.
Is there any trick to fix this?
example (not extacly as mine, since its very long code above 200 lines with css and everything)
but still it is the same idea.
notice because the navbar is fixed position it will hide the guide div when screen pixels go down
.sidenav {
height: 100%;
width: 260px;
position: fixed;
z-index: 1;
top: 140px;
left: 135px;
background: #eee;
overflow-x: hidden;
padding: 8px 0;
border-radius: 5px;
}
.sidenav a {
padding: 6px 8px 6px 16px;
text-decoration: none;
font-size: 22px;
color: #2b8bc6;
display: block;
}
.sidenav h3 {
padding: 6px 8px 6px 16px;
text-decoration: none;
font-size: 22px;
color: black;
display: block;
}
.box22 {
background-color: #fff;
max-width: 1000px;
margin: auto;
margin-top: 20px;
border-radius: 8px;
}
<body>
<div class="sidenav">
HTML 1 editors
HTML 2 editors
HTML 3 editors
</div>
<div class="box22">
<h1>HTML part 1 intro</h1>
<p>text</p>
</div>
</body>
Use a relative CSS Unit like vw, which is equivalent to 1% of the total viewport.
Right now, you've got it set to an absolute size, 260px. Change that to something like 10vw.
For more info on CSS units, including a list of relative units, check out this W3 page.
.sidenav {
height: 100%;
width: 10vw;
position: fixed;
z-index: 1;
top: 140px;
left: -6px;
background: #eee;
overflow-x: hidden;
padding: 8px 0;
border-radius: 5px;
}
.sidenav a {
padding: 6px 8px 6px 16px;
text-decoration: none;
font-size: 22px;
color: #2b8bc6;
display: block;
}
.sidenav h3 {
padding: 6px 8px 6px 16px;
text-decoration: none;
font-size: 22px;
color: black;
display: block;
}
.box22 {
background-color: #fff;
max-width: 1000px;
margin: auto;
margin-top: 20px;
margin-left: 11vw;
border-radius: 8px;
}
<body>
<div class="sidenav">
HTML 1 editors
HTML 2 editors
HTML 3 editors
</div>
<div class="box22">
<h1>HTML part 1 intro</h1>
<p>text</p>
</div>
</body>
Could you do something with a bit of jQuery and more traditional nav layout for smaller responsive designs? Here's an idea: (fiddle: https://jsfiddle.net/moqb29cr/)
HTML:
HTML 1 editors
HTML 2 editors
HTML 3 editors
<h1>HTML part 1 intro</h1>
<div id="responsive_nav">
☰
</div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent eu maximus turpis. Cras non leo et felis consectetur tristique. Fusce rutrum erat non facilisis suscipit. Quisque id mi dictum, vestibulum massa sit amet, pharetra justo. Sed rutrum, ligula iaculis mattis sagittis, nisi urna commodo diam, eu auctor mi nunc eu odio. Quisque vel odio viverra, imperdiet augue at, rhoncus orci. Nullam fringilla id tortor vel rutrum. Morbi interdum egestas luctus. Suspendisse nec lacus lacinia, mollis massa auctor, consectetur nisi. Quisque interdum iaculis turpis vitae posuere. Aenean sollicitudin blandit interdum. Nulla vel bibendum nibh, at semper ex.Sed ornare dolor dui, sit amet efficitur lacus varius eget. Nunc ut urna at risus tristique cursus. Nulla rutrum rhoncus odio, vel volutpat nibh hendrerit sed. Nulla tempus id erat nec dictum. Phasellus laoreet pretium posuere. Etiam fringilla ipsum ut porttitor euismod. Mauris auctor nisi vitae sapien lacinia, porta tempor est consequat. Phasellus auctor bibendum varius. Duis convallis justo vitae nibh finibus, et vestibulum enim congue. Sed id nulla quam. Quisque sed cursus eros. Integer ut telVestibulum malesuada elementum diam non tincidunt. Integer et pharetra mi, nec tempus erat. Integer tempor dictum feugiat. Duis vel elit tellus. Etiam ornare consequat accumsan. Fusce sit amet sapien vitae mauris vestibulum mattis a sit amet odio. Maecenas volutpat orci tincidunt ante suscipit eleifend. Sed tempor faucibus ligula, vitae vulputate tortor viverra id. Phasellus ultricies, erat et fermentum tincidunt, augue nisl cursus nulla, id facilisis nunc ante commodo quam.Praesent euismod varius eros non euismod. Fusce posuere nisl lacus, a condimentum nunc efficitur eu. Ut et molestie tortor. Nunc vitae magna at felis rutrum blandit vel ut est. Aenean condimentum ipsum nec lorem condimentum convallis. Donec nec diam vel enim dapibus pretium eu at tortor. Maecenas vulputate sed diam ac aliquam. Aenean pharetra ullamcorper nisi, at egestas justo. Interdum et malesuada fames ac ante ipsum primis in faucibus.Morbi malesuada dui vitae ex pretium, eget congue nisi viverra. Donec hendrerit lorem non augue aliquet dictum. Vivamus molestie in justo in pharetra. Nunc finibus, velit sit amet malesuada bibendum, turpis elit maximus tortor, et vehicula ex tellus non lectus. Donec rhoncus erat placerat, pulvinar est eu, tincidunt neque. Donec ligula enim, bibendum non est non, porta blandit risus. In et facilisis lorem, ut commodo ipsum. Nulla feugiat felis vel rhoncus ultrices. Vivamus vitae orci tincidunt, mattis risus a, mattis dui. Curabitur congue enim at lorem lobortis, nec venenatis leo interdum. Quisque id euismod felis, ut congue nunc.</p>
jQuery:
$("#responsive_nav").click(function(){
$(".sidenav").toggle();
});
And CSS:
p {
position:relative;
display:block;
width:75%;
left:28%;
}
.sidenav {
height: 100%;
width: 25%;
position: fixed;
z-index: 1;
top: 85px;
left;0px;
background: #eee;
overflow-x: hidden;
padding: 8px 0;
border-radius: 5px;
}
.sidenav a {
padding: 6px 8px 6px 16px;
text-decoration: none;
font-size: 22px;
color: #2b8bc6;
display: block;
}
.sidenav h3 {
padding: 6px 8px 6px 16px;
text-decoration: none;
font-size: 22px;
color: black;
display: block;
}
.box22 {
background-color: #fff;
max-width: 1000px;
margin: auto;
margin-top: 20px;
border-radius: 8px;
}
#responsive_nav {
display:none;
}
#media only screen and (max-width: 600px) {
.sidenav {
display:none;
}
#responsive_nav {
display:block;
position:fixed;
top:15px;
left:80%;
cursor:pointer;
border-radius:6px;
border:thin solid #ccc;
padding:10px;
}
#responsive_nav:hover {
background-color:#ccc;
border-radius:6px;
padding:10px;
}
p {
width:90%;
left:0%;
}
}
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
How do you achieve this kind thing on the bottom of a div in CSS? Is it possible?
Currently I use an image solution but I think it's not a good way.
Thanks!
For those questioning, I did research, and this is the thing I tried and it looked ugly.
width: 100%;
border-left: 800px solid transparent;
border-right: 800px solid transparent;
border-top: 84px solid #15C4CB;
It will look like this:
Not even centered or responsive.
The ideea is to use vw units instead of regular px; 50vw means half the viewport. This way you will always have them scaled related to your viewport;
#someid{
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 50px;
background: #15C4CB;
text-align: center;
}
#someid::before{
content: "";
display: block;
position: absolute;
top: 100%;
width: 100%;
border-left: 50vw solid transparent;
border-right: 50vw solid transparent;
border-top: 80px solid #15C4CB;
box-sizing: border-box;
}
<div id="someid"> Bla bla bla </div>
you could give a try to pseudo, rotate and box shadow:
p {
/* or any other wrapper, here = demo purpose , so is width */
width: 50%;
margin: 1em auto;
padding-bottom: 3%;
/* == 3% width */
position: relative;
overflow: hidden;
}
p:before,
p:after {
content: '';
position: absolute;
z-index: -1;
width: 100.2%;
height: 100%;
top: 100%;
}
p:before {
left: -50%;
transform-origin: top right;
transform: rotate(5deg);
box-shadow: -1000px -1000px 0 1000px #00C4CC;
}
p:after {
right: -50%;
box-shadow: 1000px -1000px 0 1000px #00C4CC;/* adapt here values to average max-height your containers could be (safe value) */
transform-origin: top left;
transform: rotate(-5deg);
}
<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. Mauris
placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, 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. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis
luctus, metus</p>
<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. Mauris
placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, 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. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis
luctus, metus</p>
PLease help!
This is what I have so far: http://beauxlent.com/nicole
When you click "one" "two" or "three", it takes you to a div that is still on the same page. However, I would like the div to stay within the right div and still on the same page used #tags. I've seen this done before.
<style type="text/css">
{
padding: 0;
margin: 0;
}
body {
text-align: justify;
overflow: hidden;
background: #F8F8F8;
font: -blocked- arial;
}
table, p {
display: none;
}
div {
width: 100%;
}
.container {width: 800px; display:block; margin:0px auto}
.left {width:200px; float:left; background: #eee; display:block; height:200px;
line- height:2}
.right {width:600px; float:right; background: #808080; display:block; height: 200px;
line-height:2; }
#o {position:absolute; right: 2000px;}
.blog {
background: 0;
position: absolute;
top: 150px;
left: 500px;
width: 290px;
height: 140px;
}
#omg {
z-index: 7;
position: absolute;
top: 1000px;
right: 0;
color: #000;
height: 1000px;
}
#plz {
z-index: 7;
position: absolute;
top: 9000px;
right: 0;
color: #000;
height: 9000px;
}
}
#nande a:hover {
color: #000;
}
#nande {
z-index: 7;
position: absolute;
top: 7000px;
right: 0;
color: #000;
height: 1000px;
}
body, table {
color: #fff;
}
font, table, tr, td, br, p {
font: -blocked- franklin gothic medium;
color: #fff;
}
#content {
width: 100%;
}
#main, #content {
border: 0px none;
background: #fff;
}
}
.framed {
background: #fff;
padding: 5px;
overflow: auto;
position: absolute;
top: 20px;
left: 0px;
}
</style>
<div id="boxed">
<div class="container">
<div class="left">
1
2
3
</div>
<div class="right">
<div id="omg">
<a name="uno"></a>
<div class="framed">
one
</div>
</div>
<div id="nande">
<a name="dos"></a>
<div class="framed">
two
</div>
</div>
<div id="plz">
<a name="tres"></a>
<div class="framed">
three
</div>
</div>
</div>
Tabbings you mean. This can be done too in CSS. Try to check it here -> http://css-tricks.com/functional-css-tabs-revisited/
HTML code:
<div class="tab">
<input type="radio" id="tab-1" name="tab-group-1" checked>
<label for="tab-1">Tab One</label>
<div class="content">
stuff
</div>
</div>
<div class="tab">
<input type="radio" id="tab-2" name="tab-group-1">
<label for="tab-2">Tab Two</label>
<div class="content">
stuff
</div>
</div>
<div class="tab">
<input type="radio" id="tab-3" name="tab-group-1">
<label for="tab-3">Tab Three</label>
<div class="content">
stuff
</div>
</div>
</div>
CSS code:
.tabs {
position: relative;
min-height: 200px; /* This part sucks */
clear: both;
margin: 25px 0;
}
.tab {
float: left;
}
.tab label {
background: #eee;
padding: 10px;
border: 1px solid #ccc;
margin-left: -1px;
position: relative;
left: 1px;
}
.tab [type=radio] {
display: none;
}
.content {
position: absolute;
top: 28px;
left: 0;
background: white;
right: 0;
bottom: 0;
padding: 20px;
border: 1px solid #ccc;
}
[type=radio]:checked ~ label {
background: white;
border-bottom: 1px solid white;
z-index: 2;
}
[type=radio]:checked ~ label ~ .content {
z-index: 1;
}
Take a look at jQuery UI Tabs - very easy to implement.
Include
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.8.3.js"></script>
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
The jQuery
$(function() {
$( "#tabs" ).tabs();
});
The HTML
<div id="tabs">
<ul>
<li>Nunc tincidunt</li>
<li>Proin dolor</li>
<li>Aenean lacinia</li>
</ul>
<div id="tabs-1">
<p>Proin elit arcu, rutrum commodo, vehicula tempus, commodo a, risus. Curabitur nec arcu. Donec sollicitudin mi sit amet mauris. Nam elementum quam ullamcorper ante. Etiam aliquet massa et lorem. Mauris dapibus lacus auctor risus. Aenean tempor ullamcorper leo. Vivamus sed magna quis ligula eleifend adipiscing. Duis orci. Aliquam sodales tortor vitae ipsum. Aliquam nulla. Duis aliquam molestie erat. Ut et mauris vel pede varius sollicitudin. Sed ut dolor nec orci tincidunt interdum. Phasellus ipsum. Nunc tristique tempus lectus.</p>
</div>
<div id="tabs-2">
<p>Morbi tincidunt, dui sit amet facilisis feugiat, odio metus gravida ante, ut pharetra massa metus id nunc. Duis scelerisque molestie turpis. Sed fringilla, massa eget luctus malesuada, metus eros molestie lectus, ut tempus eros massa ut dolor. Aenean aliquet fringilla sem. Suspendisse sed ligula in ligula suscipit aliquam. Praesent in eros vestibulum mi adipiscing adipiscing. Morbi facilisis. Curabitur ornare consequat nunc. Aenean vel metus. Ut posuere viverra nulla. Aliquam erat volutpat. Pellentesque convallis. Maecenas feugiat, tellus pellentesque pretium posuere, felis lorem euismod felis, eu ornare leo nisi vel felis. Mauris consectetur tortor et purus.</p>
</div>
<div id="tabs-3">
<p>Mauris eleifend est et turpis. Duis id erat. Suspendisse potenti. Aliquam vulputate, pede vel vehicula accumsan, mi neque rutrum erat, eu congue orci lorem eget lorem. Vestibulum non ante. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Fusce sodales. Quisque eu urna vel enim commodo pellentesque. Praesent eu risus hendrerit ligula tempus pretium. Curabitur lorem enim, pretium nec, feugiat nec, luctus a, lacus.</p>
<p>Duis cursus. Maecenas ligula eros, blandit nec, pharetra at, semper at, magna. Nullam ac lacus. Nulla facilisi. Praesent viverra justo vitae neque. Praesent blandit adipiscing velit. Suspendisse potenti. Donec mattis, pede vel pharetra blandit, magna ligula faucibus eros, id euismod lacus dolor eget odio. Nam scelerisque. Donec non libero sed nulla mattis commodo. Ut sagittis. Donec nisi lectus, feugiat porttitor, tempor ac, tempor vitae, pede. Aenean vehicula velit eu tellus interdum rutrum. Maecenas commodo. Pellentesque nec elit. Fusce in lacus. Vivamus a libero vitae lectus hendrerit hendrerit.</p>
</div>
</div>
I want to try to code a fixed-header that is a bit transparent.
Any ideas, sample code, tutorials? I want to achieve it with CSS only, if possible. Playing with the opacity (CSS3) is needed, I guess.
Example
Full screen jsFiddle: http://fiddle.jshell.net/NathanJohnson/LrNBt/show/
jsFiddle: http://jsfiddle.net/NathanJohnson/LrNBt/
Code
HTML:
<div id="header">
<div id="header-content">
<h1>Here is some heading text :)</h1>
<p>Here is some more content of the header...</p>
</div>
</div>
CSS:
body {
font-family: arial, sans-serif;
padding: 0;
margin: 0;
}
#header {
background-color: black;
/*Opacity start*/
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
filter: alpha(opacity=80);
-moz-opacity: 0.80;
-khtml-opacity: 0.8;
opacity: 0.8;
/*Opacity end*/
color: white;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 150px;
padding: 0;
margin: 0;
}
#header #header-content {
margin: 10px;
}
Or, you could just use rgba() instead of opacity:
#header {
background-color: rgba(0, 0, 0, 0.8);
color: white;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 150px;
padding: 0;
margin: 0;
}
#header #header-content {
margin: 10px;
}
I hope this helps.
Use Firebug to analyze their code:
#header {
left: 0;
position: fixed;
top: 0;
width: 100%;
z-index: 90;
background: url("../images/bg-header.png") repeat-x scroll 0 0 transparent;
height: 247px;
}
Instead of using an image use:
background: #000;
filter:alpha(opacity=50);
-moz-opacity:0.5;
-khtml-opacity: 0.5;
opacity: 0.5;
You can also make a glassy (translucent) background using the new backdrop-filter property:
header {
top: 0;
position: sticky;
background: transparent;
backdrop-filter: blur(5px);
}
header {
top: 0;
position: sticky;
background: transparent;
backdrop-filter: blur(5px);
padding: 24px;
font-size: 24px;
font-weight: bold;
}
p {
width: 200px;
}
<header>This is a sticky header</header>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris magna elit, consectetur in ultricies nec, imperdiet sit amet turpis. Sed ligula eros, pellentesque ac ligula eu, mollis iaculis est. Donec tempus massa in libero consectetur, laoreet feugiat tortor rhoncus. Aliquam ac risus et risus finibus sodales. Suspendisse et ipsum mollis, convallis elit ac, interdum nibh. Etiam finibus odio urna, eu pretium arcu varius ut. Aliquam erat volutpat.
Duis volutpat mollis turpis, at posuere ipsum semper in. In in ligula tortor. Integer eget lorem nec ex ultricies molestie. Proin convallis sagittis orci nec tempus. Pellentesque luctus condimentum libero in fermentum. Mauris ornare sem nec tellus bibendum, eu interdum nisl mollis. Morbi et lectus sodales, blandit urna et, posuere metus. Praesent sodales eu tortor eu vestibulum. Mauris eu quam sit amet neque faucibus facilisis. Sed tincidunt enim egestas elit finibus, id tempor erat luctus. Ut sed faucibus ante. Suspendisse non lacus augue. Duis porta lorem sed enim lobortis, a malesuada leo scelerisque. Nam neque massa, tempus sit amet velit nec, tincidunt bibendum dui. Praesent neque tortor, blandit in nunc vehicula, suscipit fringilla turpis.
</p>