Two-column layout with vertically and horizontally alignment, having variable height - html

I want to gain the below layout:
It seems that when the right box is small, the bottom left box wants to move away from the left side and beside the top left box. If the right box is full and tall, then it pushes the bottom left box back to where I want it to be.
HTML
<div class=page>
<div id="stack-vert">
<div id="stack-horz">
<div id="message_center_content">
<h2> Your Messages </h2>
</div>
<div id="message_center_details">
</div>
<div id="message_center_details">
</div>
<div id="clearingdiv2"></div>
</div>
</div>
CSS
.page{
margin: 2em auto;
width: 75em;
border: 5px solid #ccc;
padding: 0.8em; background: white; display:table;
}
#message_center_details{
float:left;
border: solid thin black;
overflow:hidden;
padding: 5px;
width: 25%;
background-color: #ffffcc;
margin: 5px;
}
#message_center_content{
float:right;
border: solid thin black;
padding: 5px;
width: 60%;
background-color: #F0F0F0;
margin: 5px;
}
JS Fiddle
It works in jsFiddle, but now in my browser! Instead the two boxes on the left interfere with each other, the bottom one sits to the right of the top one and below the box on the right.
Any help would be really appreciated.

Something you could do
<div id="Container">
<div id="left">
<div class="section">
</div>
<div class="section">
</div>
</div>
<div id="right">
<div id="message">
<div style="width:100px;height:260px;background:white;">Edit this</div>
</div>
</div>
</div>
#Container {
width: 100%;
min-height: 300px;
background: red;
}
#left {
float: left;
width: 40%;
background: yellow;
min-height: 300px;
box-sizing: border-box;
padding: 10px;
}
.section {
width: 100%;
display: block;
min-height: 120px;
background: red;
box-sizing: border-box;
margin-bottom: 10px;
}
#right {
float: left;
width: 60%;
min-height: 300px;
background: blue;
box-sizing: border-box;
padding: 10px;
}
#message {
width: 100%;
min-height: 200px;
background: red;
}
see fiddle for what i would do. I have added colors so you can see whats happening.
adjust the white div height in the HTML tab to see the message div (the red one on the right) adjust its height.
Your content would just go inside the left divs with a class of section, and the right div id message.
I would stay away from libraries until you know how to do most things yourself.
Great place to learn html/css/js and more

You are maybe after such a solution to have two outer divs side-by-side:
.wrapper{
width: 90%;
margin: auto;
display: flex;
justify-content: space-between;
}
.side{
width: 30%;
}
.side div{
margin-bottom: 10px;
padding: 10px;
}
.side div:last-child{
margin-bottom: 0;
}
.main{
width: 67%;
}
.main div{
padding: 10px;
}
.border{
border: 2px solid black;
}
<div class="wrapper">
<div class="side">
<div class="top border">
<p>These are contents. These are contents. These are contents. </p>
<p>These are contents. These are contents. These are contents. </p>
</div>
<div class="bottom border">
<p>These are contents. These are contents. These are contents. </p>
<p>These are contents. These are contents. These are contents. </p>
<p>These are contents. These are contents. These are contents. </p>
</div>
</div>
<div class="main">
<div class="border">
<p>These are contents. These are contents. These are contents. </p>
<p>These are contents. These are contents. These are contents. </p>
</div>
</div>
</div>

Related

Css table with scalable div on the sides

I have a central div that have 4 others divs arrount it (top, right, left, bottom).
Top and Bottom divs are suposed to be fixed. They don't have to increase neither height nor width.
Right and left divs are ONLY suposed to increase its width.
How?
The "content" div (central) is a table that can have as many rows as the user wants. Then, I want to increase or decrease the height of the left and right divs depending on the height of the "content".
I want to automatically do that .
How can I do that?
I have created an example with what I have done, without success.
https://jsfiddle.net/y6ad2crg/4/
<div class="pantalla">
<div class=" pantallaSup"></div>
<div class="pantallaEsq"></div>
<div class="pantallaDre"></div>
<div class="interiorPantalla">
content<br>
aaa<br>
bbb<br>
ccc<br>
ddd<br>
eee
</div>
<div class="pantallaInf"></div>
</div>
The result I want to get is that:
What am I doing wrong?
Maybe just changing little things in css it may be done, or maybe my html is wrong designed...
change u code
https://jsfiddle.net/p7haf3oo/
.pantalla {
/*position: relative;*/
display: block;
width: 690px;
background-color: gray;
}
.pantallaSup {
height: 200px;
width: 100%;
background: orange;
}
.flex {
display: flex;
align-items: stretch;
}
.pantallaEsq {
width: 69.4px;
border-right: 4px solid black;
background: red;
display: block;
}
.pantallaDre {
width: 69.4px;
border-left: 4px solid black;
background: red;
display: block;
align-self: stretch;
min-height: 100px;
}
.pantallaInf {
height: 200px;
width: 100%;
background: orange;
}
.interiorPantalla {
position: relative;
margin: 0 auto;
border: 1px;
border-color: blue;
border-style: solid;
width: 550px;
background-color: white;
}
<div class="pantalla">
<div class="pantallaSup"></div>
<div class="flex">
<div class="pantallaEsq"></div>
<div class="interiorPantalla">
content
<br> aaa
<br> bbb
<br> ccc
<br> ddd
<br> eee
</div>
<div class="pantallaDre"></div>
</div>
<div class="pantallaInf"></div>
</div>
I believe I have coded what you're looking for -https://jsfiddle.net/Shuaso/vpmn3LLv/
I removed all the unnecessary divs and used CSS borders and background colors to achieve the same effect. You can alter the content in the "content" div and see the dynamic styles. Here's the code:
CSS:
.container {
width: 500px;
background-color: orange;
padding: 20px 0;
}
.content {
border-left: 20px solid red;
border-right: 20px solid green;
background-color: white;
}
HTML:
<div class="container">
<div class="content">
<p>test</p>
<p>test</p>
</div>
</div>

Two boxes, side by side, 50% each, but both are slighty longer and not on same line?

I'm trying to get two side-by-side boxes to take up the entire width of the screen. However, when setting the width at 50%, each of the boxes wants to extend about 10px wider than 50%. What am I doing wrong?
#sides {
padding-top: 40px;
padding-bottom: 40px;
background-color: white;
}
#leftside {
width: 50%;
background-color: grey;
padding: 20px;
margin: 0px;
position: relative;
}
#rightside {
width: 50%;
display: inline-table;
background-color: #018DCA;
float: left;
padding: 20px;
margin-left: 50%;
position: relative;
}
.
.
.
<div id="sides">
<div id="leftside">
<h1>text</h1>
<p>
<h2>text</h2>
<br>
</div>
<div id="rightside">
<h1>text</h1>
<p>
<h2>text</h2>
<br>
</div>
</div>
Both sides need to be floated and make sure that you're using box-sizing: border-box; to ensure that the width is 50% regardless of padding and border size.
I realise that your question has already been solved, but another option to TylerH's solution would be to use flex. Like so:
#sides {
display:flex;
padding: 40px 0px;
background-color: white;
}
.side {
flex:1;
padding: 20px;
margin: 0;
}
#left{background-color: grey;}
#right{background-color: #018DCA;}
<div id="sides">
<div class="side" id="left">
<h1>text</h1>
<h2>text</h2>
</div>
<div class="side" id="right">
<h1>text</h1>
<h2>text</h2>
</div>
</div>
As TylerH rightly pointed out, this does require more modern browsers. Take a look at this website for more information on compatibility.
You don't need to use float (in fact it's not really the right tool for overall document layout; it's more for breaking up text with images without destroying the document flow).
You can achieve this with less CSS by using display: inline-block; and commenting out the white-space between your left and right <div>s. JSFiddle
html, body {
margin: 0;
}
#sides {
padding-top: 40px;
padding-bottom: 40px;
background-color: white;
}
#leftside {
width: 50%;
background-color: grey;
padding: 20px 0;
display: inline-block;
}
#rightside {
width: 50%;
display: inline-block;
background-color: #018DCA;
padding: 20px 0;
}
<div id="sides">
<div id="leftside">
<h1>text</h1>
<p>
<h2>text</h2>
<br>
</div><!--
--><div id="rightside">
<h1>text</h1>
<p>
<h2>text</h2>
<br>
</div>
</div>
Use display:inline-blockAdd font-size:0 to the parent div,this must do. Also try adding vertical-align:top to right div
#sides {
padding-top: 40px;
padding-bottom: 40px;
background-color: white;
}
#leftside {
width: 47%;
background-color: grey;
float: left;
padding:5px;
}
#rightside {
width: 47%;
background-color: #018DCA;
float: right;
padding:5px;
}
<div id="sides">
<div id="leftside">
<h1>text</h1>
<p>
<h2>text</h2>
<br>
</div>
<div id="rightside">
<h1>text</h1>
<p>
<h2>text</h2>
<br>
</div>
</div>

Take padding in account for floating elements

I would like to have a main element, with side blocks floating to its right side. I don't know the number of side blocks, neither their final total height. But my main element should have the same height (see the following example for better understanding), without using columns.
(dashed areas are real contents)
To force my main (red) element to fit side blocks height, I use this trick:
padding-bottom: 5000px;
margin-bottom: -5000px;
This works well, but side blocks doesn't care of padding, they just ignore it.
How can I get them to take padding into account?
N.B: HTML markup should not be changed, and I'm not willing to use JS for layout purpose
.container {
width: 600px;
margin: 0 auto;
overflow: hidden;
}
.main {
float: left;
background: tomato;
width: 440px;
padding-bottom: 5000px;
margin-bottom: -5000px;
}
.side {
float: left;
background: forestgreen;
height: 50px;
width: 150px;
margin-left: 10px;
margin-bottom: 10px;
}
<div class="container">
<div class="main"> </div>
<div class="side"> </div>
<div class="side"> </div>
<div class="side"> </div>
</div>
How is this for an option?
No markup change and purely CSS with no change in absolute values already given.
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.container {
width: 600px;
margin: 0 auto;
overflow: hidden;
}
.main {
background: tomato;
width: 440px;
padding-bottom: 5000px;
margin-bottom: -5000px;
float: left;
}
.side {
background: forestgreen;
height: 50px;
width: 150px;
margin-left: 10px;
margin-bottom: 10px;
float: right;
clear: right;
}
.side:last-child {
margin-bottom: 0;
}
<div class="container">
<div class="main"> </div>
<div class="side"> </div>
<div class="side"> </div>
<div class="side"> </div>
</div>
The only way i can come up with a solution is this:
JS FIDDLE
I made a .wrapper div around the 3 (forest)green boxes, and centered that one to the right.
So now you have those 3 boxes floating right of the tomato colored div.
Don't forget to make a clear both under the floating divs, or else everything will overlap the divs. and in you CSS sheet: .clear{ clear: both; }
Hope it helps. :)
I found a solution, using margin-left instead of float: left:
.container {
width: 600px;
margin: 0 auto;
overflow: hidden;
}
.main {
float: left;
background: tomato;
width: 440px;
padding-bottom: 5000px;
margin-bottom: -5000px;
}
.side {
background: forestgreen;
height: 50px;
width: 150px;
margin-left: 450px;
margin-bottom: 10px;
}
<div class="container">
<div class="main"> </div>
<div class="side"> </div>
<div class="side"> </div>
<div class="side"> </div>
</div>
When you float an element, it's effectively taking it out of the document flow, so padding won't have an effect on it. You could use margin-top: 10px; on both of your inner divs.

Content goes out of div

Really can't figure out what's wrong with it, but all the content I add into div, goes out of it, just like it's not in it.
Check it here: JSFiddle!
HTML___
<div id="wrapper">
<div id="container">
<div id="header">
<div id="logo">
TEXT GOES OUTSIDE OF DIV :'((
</div>
</div>
</div>
</div>
CSS___
#container {
width: 960px;
margin: 20px auto 0 auto;
background: yellow;
}
#header {
position: relative;
width: 100%;
background: yellow;
border: 1px solid black;
padding: 2px; /*just to see the div*/
}
#logo {
float: left;
}
You need to clear your floats:
<div id="wrapper">
<div id="container">
<div id="header">
<div id="logo">
TEXT NOW APPEARS INSIDE DIV :)
</div>
<div style="clear: both;"></div>
</div>
</div>
</div>
Because you've floated your logo, any content following it will wrap around it. Which is what is causing the effect you're seeing.
Add overflow:auto to your #header div to restore the expected behavior:
#header {
position: relative;
width: 100%;
background: yellow;
border: 1px solid black;
overflow:auto;
}
jsFiddle example
Floating the child essentially removes it from the flow and the parent collapses. Adding the overflow rule gives you the behavior you expected.
I'd urge you to use flex. It's quite robust and lets you create any kind of layout you want without any issues really. I've added a menu to the right hand side just to illustrate your logo in actual context.
<!-- HTML -->
<div id="wrapper">
<div id="container">
<div id="header">
<div id="logo">
TEXT GOES OUTSIDE OF DIV :'((
</div>
<div id="content-menu">
<div id="menu">
Home
Contact
About
About
</div>
</div>
</div>
</div>
</div>
Corresponding CSS:
/* CSS */
#container {
width: 960px;
margin: 20px auto 0 auto;
background: yellow;
}
#header {
position: relative;
width: 100%;
margin: 1.2em auto;
background: yellow;
border: 1px solid black;
padding: 2px; /*just to see the div*/
display: flex;
}
#logo { flex: 1; }
#content-menu { flex: 4;}
#menu { display: flex; }
#menu > a {
display: inline-block;
text-align: center;
line-height: 32px;
text-decoration: none;
color: #000;
flex: 1;
}

How to put two divs side by side

So I'm quite new to writing code (about a few weeks) and I've hit a wall while writing code for my website. I want to have a layout like this:
But I can't figure out how to put the two boxes side by side. One box will be a video explaining my website, while the other box will be a sign up registration form.
I want the boxes to be next to each other, with about an inch of separation between them.
I also need help with the width of my website's header. Right now it looks like the header doesn't fit on the page, causing a horizontal scroll. Kind of like this:
I want it so that the entire website is like one big box, and all the content is inside that box. Can someone please help me? Much appreciated. Thank you in advance.
http://jsfiddle.net/kkobold/qMQL5/
#header {
width: 100%;
background-color: red;
height: 30px;
}
#container {
width: 300px;
background-color: #ffcc33;
margin: auto;
}
#first {
width: 100px;
float: left;
height: 300px;
background-color: blue;
}
#second {
width: 200px;
float: left;
height: 300px;
background-color: green;
}
#clear {
clear: both;
}
<div id="header"></div>
<div id="container">
<div id="first"></div>
<div id="second"></div>
<div id="clear"></div>
</div>
This will work
<div style="width:800px;">
<div style="width:300px; float:left;"></div>
<div style="width:300px; float:right;"></div>
</div>
<div style="clear: both;"></div>
<div style="display: inline">
<div style="width:80%; display: inline-block; float:left; margin-right: 10px;"></div>
<div style="width: 19%; display: inline-block; border: 1px solid red"></div>
</div>
I am just giving the code for two responsive divs side by side
*{
margin: 0;
padding: 0;
}
#parent {
display: flex;
justify-content: space-around;
}
#left {
border: 1px solid lightgray;
background-color: red;
width: 40%;
}
#right {
border: 1px solid lightgray;
background-color: green;
width: 40%;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="parent">
<div id="left">
lorem ipsum dolor sit emet
</div>
<div id="right">
lorem ipsum dolor sit emet
</div>
</div>
</body>
</html>
This is just a simple(not-responsive) HTML/CSS translation of the wireframe you provided.
HTML
<div class="container">
<header>
<div class="logo">Logo</div>
<div class="menu">Email/Password</div>
</header>
<div class="first-box">
<p>Video Explaning Site</p>
</div>
<div class="second-box">
<p>Sign up Info</p>
</div>
<footer>
<div>Website Info</div>
</footer>
</div>
CSS
.container {
width:900px;
height: 150px;
}
header {
width:900px;
float:left;
background: pink;
height: 50px;
}
.logo {
float: left;
padding: 15px
}
.menu {
float: right;
padding: 15px
}
.first-box {
width:300px;
float:left;
background: green;
height: 150px;
margin: 50px
}
.first-box p {
color: #ffffff;
padding-left: 80px;
padding-top: 50px;
}
.second-box {
width:300px;
height: 150px;
float:right;
background: blue;
margin: 50px
}
.second-box p {
color: #ffffff;
padding-left: 110px;
padding-top: 50px;
}
footer {
width:900px;
float:left;
background: black;
height: 50px;
color: #ffffff;
}
footer div {
padding: 15px;
}
You can do it in three ways:
Float Method
<div class="float-container">
<div class="float-child">
<div class="green">Float Column 1</div>
</div>
<div class="float-child">
<div class="blue">Float Column 2</div>
</div>
</div>
.float-container {
border: 3px solid #fff;
padding: 20px;
}
.float-child {
width: 50%;
float: left;
padding: 20px;
border: 2px solid red;
}
Flexbox Method
<div class="flex-container">
<div class="flex-child magenta">
Flex Column 1
</div>
<div class="flex-child green">
Flex Column 2
</div>
</div>
.flex-container {
display: flex;
}
.flex-child {
flex: 1;
border: 2px solid yellow;
}
.flex-child:first-child {
margin-right: 20px;
}
CSS Grid Method
<div class="grid-container">
<div class="grid-child purple">
Grid Column 1
</div>
<div class="grid-child green">
Grid Column 2
</div>
</div>
.grid-container {
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap: 20px;
}
Source
Have a look at CSS and HTML in depth you will figure this out. It just floating the boxes left and right and those boxes need to be inside a same div. http://www.w3schools.com/html/html_layout.asp might be a good resource.
Regarding the width of your website, you'll want to consider using a wrapper class to surround your content (this should help to constrain your element widths and prevent them from expanding too far beyond the content):
<style>
.wrapper {
width: 980px;
}
</style>
<body>
<div class="wrapper">
//everything else
</div>
</body>
As far as the content boxes go, I would suggest trying to use
<style>
.boxes {
display: inline-block;
width: 360px;
height: 360px;
}
#leftBox {
float: left;
}
#rightBox {
float: right;
}
</style>
I would spend some time researching the box-object model and all of the "display" properties. They will be forever helpful. Pay particularly close attention to "inline-block", I use it practically every day.