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>
Related
I have a modal centered horizontally and vertically where body content scrolls when its big.
However when the body content is less than modal height the modal does not resize down to its content.
I tried to use only max-height an not height but then my modal code breaks ...
Note: Run the code in full page to see the blank space under body content
.cover {
background-color: rgba(0, 0, 0, 0.4);
bottom: 0;
height: 100%;
left: 0;
padding: 0;
position: fixed;
right: 0;
top: 0;
width: 100%;
z-index: 200;
}
.modal {
background-color: white;
margin: 10% auto;
max-width: 400px;
height: 60vh;
max-height: 60vh;
position: relative !important;
}
.scrollView {
position: relative;
border: 2px solid red;
height: calc(60vh - 100px);
margin: 50px 0;
top: 50px;
overflow: scroll;
z-index: 800;
}
div.header {
display: flex;
align-items: center;
height: 50px;
max-height: 50px;
top: 0;
position: absolute;
background: lightgreen;
width: 100%;
z-index: 900;
justify-content: space-between;
}
.header div {
padding: 0 20px;
}
div.footer {
display: flex;
justify-content: center;
align-items: center;
position: absolute;
bottom: 0;
height: 50px;
background: orange;
width: 100%;
}
.body {
overflow-y: scroll;
}
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi porttitor aliquet orci sit amet fringilla. Duis a ligula consequat, ornare elit eu, tincidunt turpis.
</p>
<p>Nulla faucibus ultrices est eu laoreet. Suspendisse accumsan blandit ipsum ultricies congue. Nam eget leo a elit vestibulum tincidunt in elementum nunc. Nunc cursus lacus eu placerat auctor.
</p>
<div class="cover">
<div class="modal">
<div class="header">
<div>Header</div>
<div>Close</div>
</div>
<div class="scrollView">
<div class="body">
Body short content
</div>
</div>
<div class="footer">
Footer
</div>
</div>
</div>
How can I solve this?
You can simplify your code like below and rely on flexbox inside the modal instead of position:absolute;
.cover {
background-color: rgba(0, 0, 0, 0.4);
bottom: 0;
left: 0;
position: fixed;
right: 0;
top: 0;
z-index: 200;
display:flex;
align-items:center;
justify-content:center;
}
.modal {
background-color: white;
max-width: 400px;
width:100%;
max-height: 60vh;
display:flex;
flex-direction:column;
}
.scrollView {
flex-grow:1;
border: 2px solid red;
overflow: auto;
}
div.header,
div.footer{
display: flex;
align-items: center;
justify-content: space-between;
height: 50px;
background: lightgreen;
padding: 0 20px;
flex-shrink:0;
}
div.footer {
background: orange;
justify-content: center;
}
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi porttitor aliquet orci sit amet fringilla. Duis a ligula consequat, ornare elit eu, tincidunt turpis.
</p>
<p>Nulla faucibus ultrices est eu laoreet. Suspendisse accumsan blandit ipsum ultricies congue. Nam eget leo a elit vestibulum tincidunt in elementum nunc. Nunc cursus lacus eu placerat auctor.
</p>
<div class="cover">
<div class="modal">
<div class="header">
<div>Header</div>
<div>Close</div>
</div>
<div class="scrollView">
<div class="body">
Body <br>short <br>content
</div>
</div>
<div class="footer">
Footer
</div>
</div>
</div>
I am trying to make the following banner in bootstrap. The demo of the banner can be seen her.
I cannot figure out how I can make this in bootstrap 3, and where to start. Should the row and col be like this for at start, or should it only be one row? Is it transform there is making the slant line on the image?
<div class="container-fluid">
<div class="row">
<div class="col-md-6">Text here</div>
<div class="col-md-6"><img src="https://image-here.jpg"></div>
</div>
</div>
The original code for the banner is:
.widget-about {
position: relative;
overflow: hidden;
padding: 0;
margin: 0;
}
.widget-about .tg-container {
position: absolute;
left: 50%;
top: 0;
height: 100%;
max-width: 1200px;
transform: translateX(-50%);
}
.widget-about .tg-container .about-content-wrapper {
position: absolute;
left: 0;
top: 0;
width: 50%;
height: 100%;
background: #f9f9f9; }
.widget-about .tg-container .about-content-wrapper .about-block {
position: absolute;
top: 50%;
left: 0;
transform: translateY(-50%);
z-index: 999; }
.widget-about .tg-container .about-content-wrapper .about-block .about-title {
font-size: 28px;
margin: 0;
text-transform: uppercase; }
.widget-about .tg-container .about-content-wrapper .about-block .about-title a {
color: #454545; }
.widget-about .tg-container .about-content-wrapper .about-block .about-sub-title {
color: #00a9e0;
margin: 10px 0;
font-size: 16px;
text-transform: capitalize; }
.widget-about .tg-container .about-content-wrapper .about-block .about-content {
color: #737373;
font-size: 14px;
margin-top: 20px; }
.widget-about .tg-container .about-content-wrapper:before {
content: "";
position: absolute;
width: 1000%;
height: 100%;
background: #f9f9f9;
left: -1000%;
top: 0; }
.widget-about .tg-container .about-content-wrapper:after {
background: #f9f9f9 none repeat scroll 0 0;
content: "";
height: 2000px;
position: absolute;
right: 650px;
top: 50%;
transform: rotate(70deg) translateY(-50%);
width: 2000px;
z-index: 9; }
.about-img {
/* margin: 0; */
}
.about-img img {
width: 100%;
display: block; }
<section id="estore_about-3" class="widget widget-about clearfix">
<div class="section-wrapper">
<figure class="about-img">
<img width="1600" height="310" src="https://demo.themegrill.com/estore/wp-content/uploads/sites/49/2016/02/about.jpg">
</figure>
<div class="tg-container">
<div class="about-content-wrapper">
<div class="about-block">
<h3 class="about-title">
BEST STORE THEME </h3>
<h4 class="about-sub-title">Multicolor & Multipurpose Woocommerce Theme</h4>
<div class="about-content">
Aenean ipsum felis, luctus in hendrerit eget, varius non lacus. Duis et aliquet lacus. Quisque iaculis congue facilisis. Aenean eu dolor vestibulum, lobortis ligula eu, rhoncus diam. Etiam et efficitur augue. Etiam vehicula sem quis risus elementum euismod. Sed id mattis sapien. Ut lacinia aliquam massa eget efficitur. Suspendisse fermentum eget leo suscipit faucibus. Morbi
</div>
</div>
</div><!-- .about-content-wrapper -->
</div><!-- .tg-container -->
</div>
</section>
Edit
You won't be able to exactly match without some custom css, so here's the my minimum using mostly bootstrap classes and some custom css to get the desired styles (little slant) and expected responsive behavior.
.custom-bg {
background-size: cover;
background-position: center right;
min-height: 100px !important;
}
.custom-content:after {
background: transparent;
border-top: 250px solid transparent;
border-bottom: 0px solid transparent;
border-left: 80px solid #f7f7f7;
content: '';
height: 100%;
position: absolute;
right: -80px;
top: 0;
width: 0;
z-index: 10;
}
.custom-row {
margin: 0 !important;
}
#media (max-width: 991px) {
.custom-bg {
background-position: top right;
}
.custom-row {
flex-direction: column-reverse;
}
.custom-content:after {
display: none
}
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row custom-row">
<div class="col-lg-7 col-sm-12">
<div class="p-3 custom-content">
<h3>Best Store Theme</h3>
<h5 class="text-primary">Multicolor & Multipurpose Woocommerce Theme</h5>
<p>Aenean ipsum felis, luctus in hendrerit eget, varius non lacus. Duis et aliquet lacus. Quisque iaculis congue facilisis. Aenean eu dolor vestibulum, lobortis ligula eu, rhoncus diam. Etiam et efficitur augue. Etiam vehicula sem quis risus elementum euismod. Sed id mattis sapien. Ut lacinia aliquam massa eget efficitur. Suspendisse fermentum eget leo suscipit faucibus. Morbi</p>
</div>
</div>
<div class="col-lg-5 col-sm-12 custom-bg" style="background-image: url('https://demo.themegrill.com/estore/wp-content/uploads/sites/49/2016/02/about.jpg')">
</div>
</div>
I'm new at this. I'm not sure what I'm doing wrong. I've tried both the absolute and relative position but I can't get the footer to go at the bottom of the page. I also don't want the fixed option. Can anyone tell what's wrong with it?
<!DOCTYPE html>
<html>
<head>
<title>after hours</title>
<link href="style.css" type="text/css" rel="stylesheet">
</head>
<body>
<div id="banner">
<div class="content">
<h1>as always <br> at this hour </h1>
<h1 class="maroon">time means <br> nothing</h1>
</div>
</div>
<div class="nav">
home
about
blog
portfolio
</div>
<div id="main">
<div class="about">
<p>Aenean ornare velit lacus, ac varius enim ullamcorper eu. Proin aliquam facilisis ante interdum congue. Integer mollis, nisl amet convallis, porttitor magna ullamcorper, amet egestas mauris. Ut magna finibus nisi nec lacinia. Nam maximus erat id euismod egestas. Pellentesque sapien ac quam. Lorem ipsum dolor sit nullam.</p>
</div>
<div class="content">
<p>Aenean ornare velit lacus, ac varius enim ullamcorper eu. Proin aliquam facilisis ante interdum congue. Integer mollis, nisl amet convallis, porttitor magna ullamcorper, amet egestas mauris. Ut magna finibus nisi nec lacinia. Nam maximus erat id euismod egestas. Pellentesque sapien ac quam. Lorem ipsum dolor sit nullam.</p>
<div class="rectangle">
<p>This is a rectangle.</p>
</div>
<div class="rectangle">
<p>This is a rectangle too.</p>
</div>
<div class="rectangle">
<p>This a rectangle as well.</p>
</div>
</div>
</div>
<footer>
<p>Aenean ornare velit lacus, ac varius enim ullamcorper eu. Proin aliquam facilisis ante interdum congue. Integer mollis, nisl amet convallis, porttitor magna ullamcorper, amet egestas mauris. Ut magna finibus nisi nec lacinia. Nam maximus erat id euismod egestas. Pellentesque sapien ac quam. Lorem ipsum dolor sit nullam.</p>
</footer>
</body>
</html>
This is the separate CSS code. I'm not sure if the footer should be a class or it can simply be a tag.
* {
margin: 0;
padding: 0;
}
* {
box-sizing: border-box;
}
body {
font-family: helvetica;
line-height: 25px;
font-size: 15px;
letter-spacing: 0.5px;
}
#banner {
background: url(imgs/1.jpg);
background-size: cover;
width: 100%;
height: 660px;
position: absolute;
}
#banner .content h1 {
text-align: center;
position: absolute;
top: 54%;
left: 42.6%;
padding: 30 30 60 30;
color: #d6d6d6;
font-size: 30px;
font-family: futura;
letter-spacing: 4px;
line-height: 30px;
/*
border: 1.5px solid white;
width: 260px;
height: 80px;
*/
}
#banner .content h1.maroon {
padding-top: 70px;
color: firebrick;
}
.nav {
position: relative;
top: 660px;
background-color: black;
width: 100%;
height: 60px;
text-align: center;
padding: 20px 0px;
margin-bottom: 30px;
}
.nav a {
position: relative;
text-transform: uppercase;
text-align: center;
color: white;
font-family: roboto;
font-weight: normal;
text-decoration: none;
font-size: 13px;
letter-spacing: 5px;
padding: 22px 40px;
display: inline;
}
.nav a:hover {
color: firebrick;
}
#main {
position: relative;
margin: 0 auto;
top: 670px;
width: 80%;
padding: 20px;
}
.about {
float: right;
width: 30%;
padding: 10px;
}
.rectangle {
padding: 30px;
display: inline-block;
text-align: center;
width: 180px;
height: 200px;
}
.content {
float: left;
width: 60%;
padding: 10px;
}
footer {
position: absolute;
right: 0;
bottom: 0;
left: 0;
width: 100%;
padding: 30px;
margin: 0 auto;
height: 300px;
}
Position everything relative, unless you really need to use absolute.
See working snippet using your code.
* {
margin: 0;
padding: 0;
}
* {
box-sizing: border-box;
}
body {
font-family: helvetica;
line-height: 25px;
font-size: 15px;
letter-spacing: 0.5px;
position: relative;
}
#banner {
background: url(imgs/1.jpg);
background-size: cover;
width: 100%;
height: 660px;
position: relative;
}
#banner .content h1 {
text-align: center;
position: absolute;
top: 54%;
left: 42.6%;
padding: 30 30 60 30;
color: #d6d6d6;
font-size: 30px;
font-family: futura;
letter-spacing: 4px;
line-height: 30px;
}
#banner .content h1.maroon {
position: relative;
padding-top: 70px;
color: firebrick;
}
.nav {
position: relative;
background-color: black;
width: 100%;
height: 60px;
text-align: center;
padding: 20px 0px;
margin-bottom: 30px;
clear: both;
}
.nav a {
position: relative;
text-transform: uppercase;
text-align: center;
color: white;
font-family: roboto;
font-weight: normal;
text-decoration: none;
font-size: 13px;
letter-spacing: 5px;
padding: 22px 40px;
display: inline;
}
.nav a:hover {
color: firebrick;
clear: both;
}
#main {
position: relative;
margin: 0 auto;
width: 80%;
padding: 20px;
clear: both;
}
.about {
float: right;
width: 30%;
padding: 10px;
}
.rectangle {
padding: 30px;
display: inline-block;
text-align: center;
width: 180px;
height: 200px;
}
.content {
width: 60%;
padding: 10px;
}
footer {
position: relative;
width: 100%;
padding: 30px;
margin: 0 auto;
height: 300px;
border: 1px solid red;
}
<!DOCTYPE html>
<html>
<head>
<title>after hours</title>
<link href="style.css" type="text/css" rel="stylesheet">
</head>
<body>
<div id="banner">
<div class="content">
<h1>as always <br> at this hour </h1>
<h1 class="maroon">time means <br> nothing</h1>
</div>
</div>
<div class="nav">
home
about
blog
portfolio
</div>
<div id="main">
<div class="about">
<p>Aenean ornare velit lacus, ac varius enim ullamcorper eu. Proin aliquam facilisis ante interdum congue. Integer mollis, nisl amet convallis, porttitor magna ullamcorper, amet egestas mauris. Ut magna finibus nisi nec lacinia. Nam maximus erat id euismod egestas. Pellentesque sapien ac quam. Lorem ipsum dolor sit nullam.</p>
</div>
<div class="content">
<p>Aenean ornare velit lacus, ac varius enim ullamcorper eu. Proin aliquam facilisis ante interdum congue. Integer mollis, nisl amet convallis, porttitor magna ullamcorper, amet egestas mauris. Ut magna finibus nisi nec lacinia. Nam maximus erat id euismod egestas. Pellentesque sapien ac quam. Lorem ipsum dolor sit nullam.</p>
<div class="rectangle">
<p>This is a rectangle.</p>
</div>
<div class="rectangle">
<p>This is a rectangle too.</p>
</div>
<div class="rectangle">
<p>This a rectangle as well.</p>
</div>
</div>
</div>
<footer>
<p>Footer text in here</p>
</footer>
</body>
</html>
If all you want to do is put the div at the botton of the screen then add this to your css:
.footer{
position: absolute;
bottom: 0;
}
When you scroll the footer will also move though. If you want it to stay in the same location then make position: fixed
In your HTML you are closing </footer> instead of close </div>.
And give position: relative to the main parent div and apply
.footer {
position: absolute;
bottom: 0;
}
this will work.
remove position: relative; #main id css.
* {
margin: 0;
padding: 0;
}
* {
box-sizing: border-box;
}
body {
font-family: helvetica;
line-height: 25px;
font-size: 15px;
letter-spacing: 0.5px;
}
#banner {
background: url(imgs/1.jpg);
background-size: cover;
width: 100%;
height: 660px;
}
#banner .content h1 {
text-align: center;
position:relative;
top: 54%;
left: 42.6%;
padding: 30 30 60 30;
color: #d6d6d6;
font-size: 30px;
font-family: futura;
letter-spacing: 4px;
line-height: 30px;
/*
border: 1.5px solid white;
width: 260px;
height: 80px;
*/
}
#banner .content h1.maroon {
padding-top: 70px;
color: firebrick;
position:relative;
}
.nav {
top: 660px;
background-color: black;
width: 100%;
height: 60px;
text-align: center;
padding: 20px 0px;
margin-bottom: 30px;
}
.nav a {
position: relative;
text-transform: uppercase;
text-align: center;
color: white;
font-family: roboto;
font-weight: normal;
text-decoration: none;
font-size: 13px;
letter-spacing: 5px;
padding: 22px 40px;
display: inline;
}
.nav a:hover {
color: firebrick;
}
#main {
/* position: relative;*/
margin: 0 auto;
top: 670px;
width: 80%;
padding: 20px;
}
.about {
float: right;
width: 30%;
padding: 10px;
}
.rectangle {
padding: 30px;
display: inline-block;
text-align: center;
width: 180px;
height: 200px;
}
.content {
float: left;
width: 60%;
padding: 10px;
}
footer {
/* position: absolute;*/
float: left;
right: 0;
bottom: 0;
left: 0;
width: 100%;
padding: 30px;
margin: 0 auto;
height: 300px;
}
<!DOCTYPE html>
<html>
<head>
<title>after hours</title>
<link href="style.css" type="text/css" rel="stylesheet">
</head>
<body>
<div id="banner">
<div class="content">
<h1>as always <br> at this hour </h1>
<h1 class="maroon">time means <br> nothing</h1>
</div>
</div>
<div class="nav">
home
about
blog
portfolio
</div>
<div id="main">
<div class="about">
<p>Aenean ornare velit lacus, ac varius enim ullamcorper eu. Proin aliquam facilisis ante interdum congue. Integer mollis, nisl amet convallis, porttitor magna ullamcorper, amet egestas mauris. Ut magna finibus nisi nec lacinia. Nam maximus erat id euismod egestas. Pellentesque sapien ac quam. Lorem ipsum dolor sit nullam.</p>
</div>
<div class="content">
<p>Aenean ornare velit lacus, ac varius enim ullamcorper eu. Proin aliquam facilisis ante interdum congue. Integer mollis, nisl amet convallis, porttitor magna ullamcorper, amet egestas mauris. Ut magna finibus nisi nec lacinia. Nam maximus erat id euismod egestas. Pellentesque sapien ac quam. Lorem ipsum dolor sit nullam.</p>
<div class="rectangle">
<p>This is a rectangle.</p>
</div>
<div class="rectangle">
<p>This is a rectangle too.</p>
</div>
<div class="rectangle">
<p>This a rectangle as well.</p>
</div>
</div>
</div>
<footer>
<p>this is footer part <br/>Aenean ornare velit lacus, ac varius enim ullamcorper eu. Proin aliquam facilisis ante interdum congue. Integer mollis, nisl amet convallis, porttitor magna ullamcorper, amet egestas mauris. Ut magna finibus nisi nec lacinia. Nam maximus erat id euismod egestas. Pellentesque sapien ac quam. Lorem ipsum dolor sit nullam.</p>
</footer>
</body>
</html>
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>;
}
I need to create a fluid shape with a cut off corner and a border. The shape needs to be able to sit on an unknown background. This in itself isn't an issue but I also need the background of this element/s to be semi-opaque.
Here's what I have so far...
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
body {
background: pink;
}
.sidebar-widget {
border: 1px solid #44AAAB;
border-right: none;
border-bottom: none;
position: relative;
padding: 15px 0 0 15px;
margin-bottom: 20px;
}
.sidebar-widget .inner {
position: relative;
padding: 15px 0 0 15px;
left: -15px;
top: -15px;
background: #f2f2f2;
}
.sidebar-widget .inner:before {
content: "";
width: 100%;
height: 15px;
background: #f2f2f2;
border: 1px solid #44AAAB;
border-right: none;
border-top: none;
position: absolute;
left: -1px;
bottom: -16px;
}
.sidebar-widget .inner .content:after {
content: "";
width: 15px;
height: 100%;
background: #f2f2f2;
border: 1px solid #44AAAB;
border-left: none;
border-bottom: none;
position: absolute;
right: -16px;
top: -1px;
}
.corner {
width: 22px;
height: 22px;
border-right: 1px solid #44AAAB;
background: #f2f2f2;
position: absolute;
right: 4px;
bottom: 4px;
transform: rotate(45deg);
z-index: 1;
}
.sidebar-widget.trans-bg .inner,
.sidebar-widget.trans-bg .inner:before,
.sidebar-widget.trans-bg .inner .content:after,
.trans-bg .corner {
background: rgba(0,0,0,0.5);
}
<div class="sidebar-widget">
<div class="corner"></div>
<div class="inner">
<div class="content">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam tellus felis, faucibus id velit eget, auctor tristique ex. Pellentesque id dolor risus. Donec tincidunt, nisl id laoreet tristique, ligula magna placerat mi, id congue magna diam ut sem. Aenean ornare eros nec sapien porta, laoreet venenatis est lobortis.
</div>
</div>
</div>
<div class="sidebar-widget trans-bg">
<div class="corner"></div>
<div class="inner">
<div class="content">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam tellus felis, faucibus id velit eget, auctor tristique ex. Pellentesque id dolor risus. Donec tincidunt, nisl id laoreet tristique, ligula magna placerat mi, id congue magna diam ut sem. Aenean ornare eros nec sapien porta, laoreet venenatis est lobortis.
</div>
</div>
</div>
This approach works when the element has solid background but as you can see the square element used to create the cut-off corner is clearly visible when using a semi-opaque background. Can anyone think of a way to get around this?
JSFiddle version
For anyone who is interested here is how I ended up doing it.
Wrap the .corner in another element with overflow: hidden;
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
body {
background: pink;
}
.sidebar-widget {
border: 1px solid #44AAAB;
border-right: none;
border-bottom: none;
position: relative;
padding: 15px 0 0 15px;
margin-bottom: 20px;
}
.sidebar-widget .inner {
position: relative;
padding: 15px 0 0 15px;
left: -15px;
top: -15px;
background: #f2f2f2;
}
.sidebar-widget .inner:before {
content: "";
width: 100%;
height: 15px;
background: #f2f2f2;
border: 1px solid #44AAAB;
border-right: none;
border-top: none;
position: absolute;
left: -1px;
bottom: -16px;
}
.sidebar-widget .inner .content:after {
content: "";
width: 15px;
height: 100%;
background: #f2f2f2;
border: 1px solid #44AAAB;
border-left: none;
border-bottom: none;
position: absolute;
right: -16px;
top: -1px;
}
.corner-mask {
width: 15px;
height: 15px;
position: absolute;
right: 0;
bottom: 0;
overflow: hidden;
}
.corner {
width: 22px;
height: 22px;
border-right: 1px solid #44AAAB;
background: #f2f2f2;
position: absolute;
right: 4px;
bottom: 4px;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
transform: rotate(45deg);
z-index: 1;
}
.sidebar-widget.trans-bg .inner,
.sidebar-widget.trans-bg .inner:before,
.sidebar-widget.trans-bg .inner .content:after,
.trans-bg .corner {
background: rgba(0,0,0,0.5);
}
<div class="sidebar-widget">
<div class="corner-mask">
<div class="corner"></div>
</div>
<div class="inner">
<div class="content">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam tellus felis, faucibus id velit eget, auctor tristique ex. Pellentesque id dolor risus. Donec tincidunt, nisl id laoreet tristique, ligula magna placerat mi, id congue magna diam ut sem. Aenean ornare eros nec sapien porta, laoreet venenatis est lobortis.
</div>
</div>
</div>
<div class="sidebar-widget trans-bg">
<div class="corner-mask">
<div class="corner"></div>
</div>
<div class="inner">
<div class="content">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam tellus felis, faucibus id velit eget, auctor tristique ex. Pellentesque id dolor risus. Donec tincidunt, nisl id laoreet tristique, ligula magna placerat mi, id congue magna diam ut sem. Aenean ornare eros nec sapien porta, laoreet venenatis est lobortis.
</div>
</div>
</div>
JSFiddle version
You can use another element inside .corner, see the example below:
<style>
.corner, .corner_inner { /* added .corner_inner to your styles */
width: 22px;
height: 22px;
border-right: 1px solid #44AAAB;
background: #f2f2f2;
position: absolute;
right: 4px;
bottom: 4px;
transform: rotate(45deg);
z-index: 1;
}
.trans-bg .corner {background: transparent} /* overwrite the background above */
.trans-bg .corner_inner { /* set background and position for inner element */
width: 11px;
height: 11px;
right: -1px;
bottom: 0;
background: rgba(0,0,0,0.5);
}
</style>
<div class="sidebar-widget trans-bg">
<div class="corner">
<div class="corner_inner"></div>
</div>
...
</div>
http://jsfiddle.net/6Lyph6zj/3/
I've edited your styles, some properties are overwritten and can be removed. I mean you can understand better what changes I've made.