left and right col same height after dynamically inserted content - html

I have some html:
<div id="content">
<div id="leftCol"></div>
<div id="rightCol"></div>
</div>
css like:
#content {
position:absolute;
width:98%;
margin-left:1%;
margin-right:1%;
min-height: 100%;
height: 100%;
padding:0;
}
#leftCol {
position:absolute;
min-height:100%;
float:left;
width:60%;
overflow: hidden;
border-top:1px solid #acacac;
border-left:1px solid #dfdfdf;
border-right:1px solid #dfdfdf;
}
#rightCol {
float:right;
width:40%;
min-height:100%;
border-right:1px solid #dfdfdf;
border-top:1px solid #acacac;
}
When content is added to #leftCol the height 100% is only applied to the 100% when document is loaded. I have a system the dynamically inserts content into #rightContent.
I want to "syncronize" so #leftCol is same height #rightCol after insertion of content. Is this possible with pure css? I could of course use js to achieve this, but css would be nicer :-)

demo
#main {
display: table;
width: 500px;
}
#left, #right {
display: table-cell;
padding: 5px;
}
#left {
background: none repeat scroll 0 0 red;
width: 250px;
}
#right {
background: none repeat scroll 0 0 green;
}

Try this:
#content {
position:absolute;
width:98%;
margin-left:1%;
margin-right:1%;
min-height: 100%;
height: 100%;
padding:0;
display: table;
}
#leftCol {
display: table-cell;
width:60%;
overflow: hidden;
border-top:1px solid #acacac;
border-left:1px solid #dfdfdf;
border-right:1px solid #dfdfdf;
}
#rightCol {
display: table-cell;
width:40%;
min-height:100%;
border-right:1px solid #dfdfdf;
border-top:1px solid #acacac;
}

Fiddle link with css and HTML. In your css file you are using id but in html you are adding class.
*{
padding:0;
margin:0;
}
#content {
width:98%;
margin:1% 1%;
padding:0;
border:1px solid #999999;
display:table;
}
#leftCol {
width:58%;
padding:1%;
background-color:#99FFCC;
display:table-cell;
}
#rightCol {
width:38%;
padding:1%;
background-color:#CCCCCC;
display:table-cell;
}
<div id="content">
<div id="leftCol">
<p>Whether you're preparing a romantic valentine's dinner or having friends over to watch the big game, our meal planning guide can help.</p>
</div>
<div id="rightCol"><p>The right glass of wine or beer can turn a good meal into a great one. Let us help you take the mystery out of beer and wine shopping.</p></div>
</div>

Related

Two Column for portrait and three columns for landscape responsive layouts using css

I need two column layout for mobile portrait view for max width 480 pixels, for landscape view I need to display three columns. Here is my css code for two columns layout working, but I have no idea how to display three columns for landscape view. Please give an idea.
html
<div id="sides">
<div id="left"></div>
<div id="right"></div>
</div>
css
#sides{
margin:0;
}
#left{
float:left;
margin-left: 5%;
width:40%;
border:1px solid #000;
min-height:100px;
overflow:hidden;
}
#right{
float:left;
margin-left: 5%;
width:40%;
border:1px solid #000;
min-height:100px;
overflow:hidden;
}
#media screen and (max-width: 300px) {
#left {
width:100%;
margin: 1px;
border:1px solid #000;
min-height:100px;
}
#right {
width:100%;
margin: 1px;
border:1px solid #000;
min-height:100px;
}
}
I have created demo in jsfiddle click here
Try below code :
<div id="sides">
<div id="left"></div>
<div id="centre"></div>
<div id="right"></div>
</div>
#sides {
margin:0;
}
#left {
float:left;
margin-left: 5%;
width:25%;
border:1px solid #000;
min-height:100px;
overflow:hidden;
}
#right {
float:left;
margin-left: 5%;
width:25%;
border:1px solid #000;
min-height:100px;
overflow:hidden;
}
#centre {
float:left;
margin-left: 5%;
width:25%;
border:1px solid #000;
min-height:100px;
overflow:hidden;
}
#media screen and (max-width: 300px) {
#left {
width:50%;
float: left;
margin: 1px;
border:1px solid #000;
min-height:100px;
}
#right {
width:50%;
margin: 1px;
border:1px solid #000;
min-height:100px;
}
#centre {
width:100%;
float: right;
margin: 1px;
border:1px solid #000;
min-height:100px;
}
}
JSFiddle : https://jsfiddle.net/0yugy4s2/

Aligning a div with 2 divs inside it in Center

Currently im trying to get 2 divs to align in center, but not quite sure how to do it. They go to the Left side by default.
I had margin-left:14 % and it would align it somewhat in the center, but when you re-sized the window it would look weird because it aligned to the right side.
tried with with with marign-left/right:auto, but no result.
html
<div id="panels">
<div id="panel-left">
</div>
<div id="panel-right">
</div>
css
#panels{
padding-top:15px;
margin-left: auto;
margin-right: auto;
}
#panel-left{
width:32%;
min-width:209px;
overflow:hidden;
background-color:white;
float:left;
padding-left:25px;
height:473px;
}
#panel-right{
width:32%;
min-width:209px;
height:473px;
background-color:white;
float:left;
padding-left:25px;
}
Try this:
CSS
#panels{
padding-top:15px;
text-align:center;
display: block;
}
#panel-left{
width:32%;
min-width:209px;
overflow:hidden;
background-color:black;
height:473px;
display: inline-block;
}
#panel-right{
width:32%;
min-width:209px;
height:473px;
background-color:orange;
display: inline-block;
}
DEMO HERE
Try this style, I have used the box sizing css property to take care of the inherent 1px space that occurs during inline styling.
Fiddle here
Of course there was an un-closed div element in your initial code which is fixed now.
So the CSS looks like,
#panels {
padding-top:15px;
margin: 0 auto;
background: cyan;
width:50%; /* u need this */
height:500px;
}
#panel-left {
width:50%;
box-sizing:border-box;
/* min-width:209px; By doing this you are pretty much giving the width to be 100 % */
overflow:hidden;
background-color:gray;
float:left;
padding-left:25px;
height:473px;
border:1px solid #000;
}
#panel-right {
width:50%;
box-sizing:border-box;
/*min-width:209px;*/
height:473px;
background-color:white;
float:left;
padding-left:25px;
border:1px solid #000;
}
Code snippet::
#panels {
padding-top: 15px;
margin: 0 auto;
background: cyan;
width: 50%;
/* u need this */
height: 500px;
}
#panel-left {
width: 50%;
box-sizing: border-box;
/* min-width:209px; By doing this you are pretty much giving the width to be 100 % */
overflow: hidden;
background-color: gray;
float: left;
padding-left: 25px;
height: 473px;
border: 1px solid #000;
}
#panel-right {
width: 50%;
box-sizing: border-box;
/*min-width:209px;*/
height: 473px;
background-color: white;
float: left;
padding-left: 25px;
border: 1px solid #000;
}
<div id="panels">
<div id="panel-left">left</div>
<div id="panel-right">right</div>
</div>
Hope this helps. Happy Coding :)

Float Two Divs Side By Side

I'm really sorry to post this. I've read dozens of posts on this same issue, but I just can't solve this. How do I place the blue and green boxes side-by-side? I've got plenty of space in my wrapping div, and I think that I am dealing with float correctly, but still incorrect results. What gives?
<div class="titleframe" >
<div class="image" >
<img id="thief" src="thief.png">
</div>
<div class="titletext">
<h1>My Title</h1>
<p>Line1<br>Line2<br>Line3</p>
</div>
</div>
.titleframe {
margin:0 auto;
width:750px;
clear:left;
height:300px;
border: 1px solid red;
}
.image {
width:100px;
height:250px;
border: 1px solid blue;
}
.titletext{
position:relative;
float:left;
padding-left:25px;
padding-top:0px;
height:150px;
width:250px;
border: 1px solid green;
}
Add float:left; to your .image class. Here is a fiddle: http://jsfiddle.net/36KP5/
.image {
width:100px;
height:250px;
border: 1px solid blue;
float:left;
}
Fiddle
You can either float the first one left, and add margin-left to the second one:
.titleframe {
margin:0 auto;
width:750px;
clear:left;
height:300px;
border: 1px solid red;
}
.image {
width:100px;
height:250px;
border: 1px solid blue;
float:left;
}
.titletext{
position:relative;
margin-left: 101px;
padding-left:25px;
padding-top:0px;
height:150px;
width:250px;
border: 1px solid green;
}
Or you can float them both left.

I want set all <div class="rectangle"> tag borders in a center

_______________________________________________
| |
| Image |
| |
|_______________________________________________|
I want set a above rectangle is in center in a page i created that using div tag as code is
.rectangle
{
width: 73.3%;
margin:0 50 0 0;
border-top:1px solid #46464f;
border-bottom:1px solid #282832;
border-left:1px solid #282832;
border-right:1px solid #282832;
border-bottom-width:medium;
border-left-width:medium;
border-right-width:medium;
border-top-width:medium;
}
I set <div class="rectangle" align="center"> this code not working
HTML:
<div class="setCenter">Content inside a div tag</div>
CSS:
body {
width: 100%;
height: 100%;
margin:auto;
}
.setCenter {
margin:auto;
width:90%;
height:auto;
border:1px solid #000;
color:Green;
}
Here is the DEMO
Try this:
HTML:
<div align="center">
<img src="http://fin6.com/wp-content/uploads/2013/07/fb81531cc9cf1512dce7f0e5f36e40fe.jpg" alt="nature"/>
</div>
CSS:
div{
width: 300px;
background:red;
margin:0 auto;
}
img{
width:150px;
margin:0 auto;
}
Here is a DEMO
UPDATE
As per your updated question, use margin:0 auto; to center div.
.rectangle
{
width: 73.3%;
margin:0 auto;
border-top:1px solid #46464f;
border-bottom:1px solid #282832;
border-left:1px solid #282832;
border-right:1px solid #282832;
border-bottom-width:medium;
border-left-width:medium;
border-right-width:medium;
border-top-width:medium;
}
Updated DEMO
Try this CSS code:
.rectangle
{
width: 73.3%; margin:0 50 0 0;
border-top:1px solid #46464f;
border-bottom:1px solid #282832;
border-left:1px solid #282832;
border-right:1px solid #282832;
border-bottom-width:medium;
border-left-width:medium;
border-right-width:medium;
border-top-width:medium;
text-align:center;
}

How to have a two headings in same line with css?

See this fiddle
JSFiddle
CSS:
.containers {
width:100%;
height:auto;
padding:10px;
margin-bottom:0px;
}
#id4 {
float:right;
margin-right:0;
display:inline;
border:5px solid red;
}
#id5 {
text-align:center;
border:5px solid red;
}
HTML:
<div class='containers'>
<div id='id4'>
margin-right:10px;
</div>
<div id='id5'>
center-text;
</div>
In this fiddle I want center-text to be center of the page, not at the center between left-border and float element.
The below is one possible option by adding position: absolute; right: 10px; to the id4 div. This will make the div always stay at 10px from the right margin. But it has to be noted that the element is no longer a float element.
Note: The texts would overlap if the result window is shrunk beyond a certain level. I will update the answer if and when I manage to find a fix for that.
.containers {
width: 100%;
height: auto;
padding: 10px;
margin-bottom: 0px;
text-align: center;
box-sizing: border-box;
}
#id4 {
display: inline-block;
position: absolute;
right: 10px;
border: 5px solid red;
}
#id5 {
display: inline-block;
border: 5px solid red;
}
.containers {
width:100%;
height:auto;
padding:10px;
margin-bottom:0px;
text-align:center;
}
#id4 {
float:right;
margin-right:0;
display:inline;
border:5px solid red;
}
#id5 {
margin: 0 auto;
display:inline-block;
border:5px solid red;
}
DEMO