40/60 split screen with container - html

I am wondering what is the best way to achieve two background divs (blue and gray) with a container over the top of them (red):
http://s22.postimg.org/44kcq1cqp/screenshot_413.png
I would create two divs for the background colours and 100vh but how would I overlay a container on top so I can make the login area? I'm trying to achieve something like this design:
http://s22.postimg.org/584h1zxdt/screenshot_414.png
Thanks in advance!

here is how I would do that :)
https://fiddle.jshell.net/okjn0oca/
* {
margin: 0;
padding: 0;
}
.content{
width: 100vw;
height: 100vh;
}
.left{
position: absolute;
top: 0;
left: 0;
width: 40vw;
height: 100vh;
background-color: blue;
}
.right {
position: absolute;
right: 0;
top: 0;
height: 100vh;
width: 60vw;
background-color: green
}
.menu {
width: calc(100% - 30px);
height: 50px;
background-color: red;
margin: 15px auto;
}
.logo {
width: 60px;
height: 30px;
background-color: red;
margin: 15px;
}
.text{
position: absolute;
width: 30vw;
height: 100px;
left: 5vw;
top: 50%;
transform: translateY(-50%);
background-color: yellow;
}
<div class="content">
<div class="left">
<div class="logo">
</div>
<div class="text">
</div>
</div>
<div class="right">
<div class="menu">
</div>
</div>
</div>

You could use a 1px background image on the body:
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAFeCAYAAABEunUfAAAAG0lEQVR42mMUYPj/n3GUGCVGiVFilBglhgMBAK5H0KGRPNKKAAAAAElFTkSuQmCC) no-repeat;
background-size: 40% 100%;
Here's a Codepen with the example
With the background size you force the pixel to cover 40% of the width and 100% of the height.
The 1px background is generated with png-pixel.com.

Not sure if you have actually tried anything, but here's something you can try.
Assuming you only want to have split colors for the background, you don't have to use two divs for that. You can do that with gradient (don't forget vendor prefixes). Then it's just a matter of positioning the "overlay" div as you want.
.bg {
width: 100%;
height: 100vh;
position: relative;
background: linear-gradient(to right, rgba(0,56,199,1) 0%, rgba(0,56,199,1) 40%, rgba(74,74,74,1) 40%, rgba(74,74,74,1) 100%);
}
.overlay {
width: 60%;
height: 25%;
position: absolute;
top: 25%;
left: 10%;
background: white;
}
<div class="bg">
<div class="overlay"></div>
</div>

Use a single container.
<style>
.main
{
background:white;
}
.login
{
background:blue;
}
</style>
<div class="main">
<div class="col-md-5 no-margin">
leave it blank
</div>
<div class="col-md-7 no-margin login">
put your page contents here
</div>
</div>

Related

How to make an absolute positioned element align center when it needs to be 50% of window

I have a requirement to make a banner that is 50% of the width of the "content wrapper" and that content wrapper is dynamically sized to a max width (so it can be, in theory, 0px-1330px). The content wrapper is the dark gray box here. It contains the content of the site. Within that content is a banner that comes out from the side of window. The window in this exactly has a boundary of the black outline.
How with HTML/CSS can I make the content of the purple container fit within the dark "content wrapper" even tho it is 50% of the window and the content lines up with left side of the wrapper when I don't know the specific width.
I've tried all kinds of math but I can't quite get it. I'm using CSS vars for the site max width and I can use var or calc to make this work but just no combo is working.
Does this fit your question?
* {
margin: 0;
padding: 0;
list-style: none;
}
.wrap {
width: 100%;
max-width: 500px;
height: 100vh;
margin: auto;
background-color: #aaa;
}
.banner {
width: 50%;
background-color: #a0f;
padding: 20px 20px 20px 0;
position: relative;
box-sizing: border-box;
}
.banner::before {
content: '';
position: absolute;
background-color: #a0f;
top: 0;
left: calc(100% - 50vw);
height: 100%;
width: calc(50vw - 100%);
}
<div class="wrap">
<h1>Content Wrapper</h1>
<div class="banner-wrap">
<div class="banner">
<h2>The title here</h2>
<p>Some other text here</p>
</div>
</div>
</div>
* {
padding: 0px;
margin: 0px;
box-sizing: border-box;
}
body {
overflow: hidden;
}
.window {
width: 100%;
height: 100vh;
border: 2px black solid;
background-color: lightgrey;
display: grid;
align-items: center;
justify-items: center;
}
.wrapper {
height: 75%;
width: 80%;
background-color: darkgrey;
padding:20px 0px;
}
.content {
padding: 20px 0px;
position: relative;
width:50%;
}
p{
position: relative;
z-index:2;
color:white;
}
.banner-container {
height: 100%;
width: 100%;
position: absolute;
top: 0px;
clip-path:inset( -100vw 0vw -100vw -100vw );
}
.banner {
height: 100%;
width: 150vw;
position: absolute;
top: 0px;
left: -50vw;
background-color: purple;
}
<div class="window">
<div class="wrapper">
<div class="content">
<p><b>Some text here</b></p>
<p>Some text here</p>
<div class="banner-container">
<div class="banner">
</div>
</div>
</div>
</div>
</div>

Half sliced div triangle in css? using border radius

I'm trying to achieve this type of Design
Where on the left corner there's a div container white background color
and behind of that container there's an image
I'm not sure where to start using css.
But I believe this is possible using css only.
I have this html codes
<div style="background: url("../image.jpg"); background-size:cover; background-repeat: none; ">
<div class="half-triangle"></div>
</div>
You could use transform: rotate() and overflow: hidden on the outer element
.wrapper {
width: 500px;
border: 2px solid;
overflow: hidden;
height: 200px;
position: relative;
}
.background {
background: red;
width: 100%;
height: 100%;
}
.text {
display: flex;
position: absolute;
width: calc(50% + 50px);
height: calc(100% + 200px);
left: 0;
top: 0;
padding-left: 100px;
justify-content: center;
align-items: center;
background: white;
transform: rotate(15deg) translate(-100px, -100px);
}
.inner {
transform: rotate(-15deg);
}
<div class="wrapper">
<div class="text">
<div class="inner">
Some text here..
</div>
</div>
<div class="background">
</div>
</div>
See solution on codepen

Center a div and give color to space of one side

I want a centered div and I wand left side of it to be filled with color (as in my examples).
I have 2 solutions (not using flexbox) here and they both feel like hacks.
body {
margin: 0;
padding: 0;
}
.header {
width: 100%;
height: 60px;
position: fixed;
}
.center-part {
width: 500px;
margin: 0 auto;
height: inherit;
background-color: rgba(0,255,0,0.8);
position: relative;
}
.blue-big {
background-color: blue;
width: 9999px;
height: inherit;
position: absolute;
right: 500px;
}
.equal-side {
display: table-cell;
}
<div class="header" style="top: 0px">
<div class="center-part">
<div class="blue-big">
</div>
</div>
</div>
<div class="header" style="top: 70px; display: table;">
<div class="equal-side" style="background-color: blue">
</div>
<div class="center-part" style="display: table-cell;">
</div>
<div class="equal-side">
</div>
</div>
Top one uses large div and positioning, but second one uses "display: table"
I'd like to know if any of them is good ok kinda practice or should I do this someway else?
Blue Green DIV will not actually be full height, so putting div in background with 50% width is not an option
A more simple solution is to use linear-gradient like this:
.container {
background: linear-gradient(to right, green 50%, transparent 0) 0 0/100% 40% no-repeat;
height: 100px;
background-color:rgba(255,0,0,0.5);
}
.container>div {
width: 300px;
height: 40%;
background:blue;
margin: 0 auto;
}
<div class="container">
<div></div>
</div>
Or consider a pseudo element overflowing:
.container {
overflow:hidden;
height: 100px;
}
.container>div {
width: 300px;
height: 100%;
background:blue;
margin: 0 auto;
position:relative;
}
.container>div:before {
content:"";
position:absolute;
top:0;
right:0;
left:-1000%;
bottom:0;
background:green;
z-index:-1;
}
<div class="container">
<div></div>
</div>
This solution works for me https://codepen.io/anon/pen/GdeYdK?editors=1100
HTML:
<div class="test-header">
<div class="equal-side left-side">
</div>
<div class="center-part">
<div class="center">
SOME TEXT HERE
</div>
</div>
<div class="equal-side right-side">
</div>
</div>
CSS:
.test-header {
position: relative;
width: 100%;
height: 60px;
text-align: center;
}
.equal-side {
display: inline-block;
height: 100%;
width: 49%;
}
.left-side {
background: blue;
}
.right-side {
background: red;
}
.center-part {
background: white;
width: 500px;
height: 60px;
display: block;
position: absolute;
margin-left: -250px; /*half of center element's width*/
left: 50%;
top: 0;
}
.center {
width: 100%;
border: 1px dashed;
}
You can use a linear gradient and need only one element - see also CSS-tricks on this topic. They have great explanations on how to do this kind of thing.
In my original answer I forgot to include the container to center the div. I've updated to two examples - one using flexbox and one without. I'm not quite sure if you cannot use flexbox, or don't want to - so I've included both.
.container {
display: flex;
justify-content: center;
}
.bar {
height: 50px;
width: 400px;
background-image:
linear-gradient(
to right,
red,
red 50%,
orange 50%,
orange 100%
);
}
.bar-noflexbox {
height: 50px;
width: auto;
margin: 1rem 20%;
background-image:
linear-gradient(
to right,
red,
red 50%,
orange 50%,
orange 100%
);
}
<div class="container">
<div class="bar"></div>
</div>
<div>
<div class="bar-noflexbox"></div>
</div>

Adding images on both sides of a div

I'd like to ask, how to add two images on both sides of a div.
See, I got a main container on my site, and I'd like to add a little decoration on both sides, like a shadow which would foreground the actual content and place less emphasis on the background, y'know?
So, I got something like this:
page.html
...
<body>
<div id="container">
<div id="shadow-left"></div>
<div id="shadow-right"></div>
...
</div>
...
</body>
...
main.css
...
#container {
position: relative;
background: #FFF;
width: 840px;
min-height: 100vh;
margin-left: auto;
margin-right: auto;
}
#shadow-left {
// Gotta do that on the left site too
}
#shadow-right {
position: absolute;
top: 80px; // So there's a little space just for the upper nav
left: 840px;
width: 500px;
height: 100vh;
background: url('/res/img/shadow-right.png') 0 0 no-repeat;
}
...
I imagined it to look like this, but there's just NOTHING. How could I accomplish to do that?
Here is a fiddle where the main content is under-shadowed by whatever color you'd like, you can expand the shadow effect by playing around with the css and I'm sure there are plenty of css-shadow generators online. Hope this is what you're looking for.
HTML
<div id="main"></div>
CSS
#main {
width:60%;
margin-left:auto;
margin-right:auto;
background:green;
height:1000px;
box-shadow: 30px 0 19px -4px lightgreen, -30px 0 19px -4px lightgreen;
}
P.S. Excuse the green..
It seems like for this you can use floats, I hope I am understanding your question correctly.
fiddle: https://jsfiddle.net/L4cjz8p9/
HTML
<body>
<div id="container">
<div id="shadow-left"><img src="http://placehold.it/100x300"></div>
<div id="shadow-right"><img src="http://placehold.it/100x300"></div>
Main content
</div>
</body>
CSS
#shadow-left
{
float:left;
}
#shadow-right
{
float:right;
}
#container {
position: relative;
background: #FFF;
width: 840px;
min-height: 100vh;
margin-left: auto;
margin-right: auto;
}
Here is one way to position things outside e.g. a centered container. You could then fill the "shadows" with a background that repeats only over y or no repeat at all if you only would like to have something on the top of the page but not repeat when you scroll down.
The example here just has a 50px wide box at both sides next to the container.
Fiddle: http://jsfiddle.net/60yjen0a/
HTML:
<div class="container">
<div class="shadow left"></div>
<div class="shadow right"></div>
<div class="content"></div>
</div>
CSS:
.container {
position: relative;
width: 600px;
height: 1000px;
margin: 0 auto;
}
.content {
position: absolute;
width: 100%;
height: 100%;
background: #eee;
}
.shadow {
position: absolute;
height: 100%;
top: 0;
background: #ddd;
width: 50px;
}
.left {
left: -50px;
}
.right {
right: -50px;
}
With absolute position you can use left and right
#shadow-left {
position: absolute;
top: 80px;
left: 0px;
width: 500px;
height: 100vh;
background: YOUR_BACKGROUND_URL_FOR_LEFT_SHADOW;
}
#shadow-right {
position: absolute;
top: 80px;
right: 0px;
width: 500px;
height: 100vh;
background: YOUR_BACKGROUND_URL_FOR_RIGHT_SHADOW;
}
Check this on JSfiddle

html5/css3 DIV on DIVs layout issue

i have div area which is devided in to 4 equal parts, like the one atached.
now i need another div to be placed at the bottom area as an overlay to the above div. Imagine it like a text scroll area on the bottom side of the TV and the TV screen is constructed by 4 divs.
I am able to create the 5 divs. now the issue is that the 5th div(scroll area) is not going above the bottom edge of the 2 lower divs (3 and 4). I also had put z-index also but failed
can anybody share a sample for styling this.
You can solve it this way:
HTML:
<div class="area"></div>
<div class="area"></div>
<div class="area"></div>
<div class="area"></div>
<div class="overlay"></div>​
CSS:
.area{
float: left;
width: 49%;
height: 300px;
border: 1px solid black;
}
.overlay{
width: 200px;
height: 100px;
background-color: blue;
clear: both;
position: absolute;
bottom: 30px;
margin: -100px;
left: 50%;
}
​
Please note that I have used hard coded example values. The actual values depends on which context the markup is in.
Without your code it's hard to figure what's not working.
If I understand what you want this is what I would have done:
<div class="container">
<div class="block1"></div>
<div class="block2"></div>
<div class="block3"></div>
<div class="block4"></div>
<div class="overlay"></div>
</div>
css:
.container {
position: relative;
width: 600px; /* use the size you want */
height: 400px;
}
.container div {
position: absolute;
width: 50%;
height: 50%;
}
.container .block1 { top: 0; left: 0; background: pink; }
.container .block2 { top: 50%; left: 0; background: red; }
.container .block3 { top: 0; left: 50%; background: green; }
.container .block4 { top: 50%; left: 50%; background: blue; }
.container .overlay {
position: absolute;
width: 80%;
height: 100px;
left: 10%;
bottom: 30px; /* distance from the bottom */
z-index: 1;
background: yellow;
}