Auto Adjust Div Height - html

I want the div that's on the right side to match the height of the div that's on the left. The div on the right should always be the same height as the div on the left. The div on the left auto adjust its height. Both divs should always have the same height. A picture is worth a thousand words so please take a look at the picture below.
Here's the image that explains my problem.
http://i44.tinypic.com/24pcpwj.jpg
JSFIDDLE
http://jsfiddle.net/zFqNH/
HTML
<div style="width:1053px;">
<section id="inside" style="overflow: hidden; width:310px; float:right; border-left:0;">
<ul>
<p class="title">Funny</p>
<li class="list">
<img src="http://cdn.dashburst.com/wp-content/uploads/2013/01/Grumpy-Cat.jpg" width="100" height="67" style="float:left;padding-right:15px;" /></a>
<h3 style="font-size:20px;">Grumpy Cat</h3>
</li>
</ul>
</section>
<section id="inside">
<h2 class="subheading">Grumpy Cat<br/><p style="font-size:14px; margin-top:0px; font-weight:normal;"></p></h2><h2 style="border-bottom: 1px solid #dddddd; padding-top:10px;"></h2>
<p class="section"></p>
<img src="http://cdn.dashburst.com/wp-content/uploads/2013/01/Grumpy-Cat.jpg" border="0" style="display:block; margin: 0 auto;" height="396" width="700">
<br/>
<img src="http://cdn.dashburst.com/wp-content/uploads/2013/01/Grumpy-Cat.jpg" border="0" style="display:block; margin: 0 auto;" height="396" width="700">
<br/>
<img src="http://cdn.dashburst.com/wp-content/uploads/2013/01/Grumpy-Cat.jpg" border="0" style="display:block; margin: 0 auto;" height="396" width="700">
<br/>
</div></div></section>
CSS
#inside {
width:700px;
border-right: 1px solid #dddddd;
border-left: 1px solid #dddddd;
min-height: 600px;
overflow: hidden;
padding-bottom:15px;
}
.title{
width:300px;
padding-top:3px;
padding-bottom:7px;
color:#fff;
height:20px;
margin-top:125px;
background:#2c2c2c;
font-size: 18px;
}
.section{
padding-left:30px;
padding-bottom:15px;
margin-bottom: 1px;
font-size: 28px;
color: #657B83;
}
.subheading {
background:#fff;
font-size:50px;
height:100px;
position: relative;
}
.bottom {
border-top: 1px solid #dddddd;
border-right: 1px solid #dddddd;
padding-top: 20px;
text-align: center;
padding-bottom: 10px;
width:1053px;
position:relative;
margin: 0 auto;
font-size:15px;
color: #fff;
}
.list{
width:300px;
border-bottom: 1px solid #dddddd;
padding-bottom:10px;
display: inline-block;
margin-top:20px;
}

Insert JavaScript below the two divs and use document.getElementById to get the height of the left div, then use document.getElementById to change the height of the right div.
<script>
var height = document.getElementById('div1').style.height;
document.getElementById('div2').style.height = height;
</script>
Documentation:
http://www.w3schools.com/jsref/prop_style_height.asp

Related

CSS BODY is unexpectedly wider than expected on mobile devices

The page looks as expected on desktop browsers e.g. Firefox, etc. The problem is with display on mobile devices.
When displayed correctly, the dark background of the "BODY" of the page should appear only as a thin frame, with the white background of the "mainFrame" div appearing as central with all contents inside it.
I have tied to change the width of the "mainFrame" class to 100% but it didn't help.
What changes should be made to the css to allow correct display on not desktop and mobile devices browsers?
Please see the CSS and HTML below.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html dir='ltr'>
<head>
<style>
html, body{height:100%;text-align: center;background:#646464;}
body{padding:0px;margin:0px; text-align: center;}
.mainFrame{
width: auto;
min-height:100%;
height: 100%;
background: white;
border: 5px solid #CCCCCC;
margin:auto;
}
html>body .mainFrame {width:auto; height: auto;}
th{
text-align: center;
padding: 9px 0px 9px 0px;
background: #E8E8FF;
font: bold 12px TAHOMA;
color: #404040;
}
td {
font: 11px Tahoma;
background: #DFEFFF;
padding: 8px 5px 8px 3px;
}
td.blank{
padding: 12px 0px;
background: WHITE;
}
.logosmallContainer {
position: relative;
width: 960px;
top: 22px;
}
.logosmallContainer1 {
position: relative;
width: 720px;
top: 22px;
}
.logosmall {
float:right;
}
.jobtabs{
position: relative;
top:40px;
width: 720px;
}
.upperTabs{
position: relative;
font-size: 12px;
width: 720px;
clear:both;
}
.uprTabs {
width:120px;
text-align:center;
padding:0px;
font: 12px tahoma;
float:right;
}
.uprTabs a {
width:120px;
height: 30px;
line-height:30px;
background-color: #EEEEEE;
text-decoration: none;
border-top: 1px #F5F5F5 solid;
border-left: 1px #F5F5F5 solid;
border-bottom: 1px #F5F5F5 solid;
border-right: 1px #F5F5F5 solid;
}
html>body .uprTabs a {width:118px; display:table; }
.uprTabs a:hover{
background-color: #C3E2DB;
text-decoration: none;
border-top: 1px solid #31557f;
border-left: 1px solid #31557f;
border-bottom: 1px solid #E6E6E6;
border-right: 1px solid #E6E6E6;
}
.lowerTabs{
position: relative;
font-size: 12px;
width: 720px;
border-top: solid #007FC0 5px;
clear:both;
}
html>body .lowrTabs a {width:118px; display:table;}
.lowrTabs {
width:120px;
background-color: #EEEEEE;
text-decoration: none;
text-align:center;
font: 12px tahoma;
float:right;
height: 27px;
line-height:27px;
}
.lowrTabs a {
width:120px;
height: 25px;
line-height:25px;
background-color: #EEEEEE;
text-decoration: none;
border-top: 1px #F5F5F5 solid;
border-left: 1px #F5F5F5 solid;
border-bottom: 1px #F5F5F5 solid;
border-right: 1px #F5F5F5 solid;
float:right;
}
.lowrTabs a:hover{
background-color: #C3E2DB;
text-decoration: none;
border-top: 1px #31557f solid;
border-left: 1px #31557f solid;
border-bottom: 1px #E6E6E6 solid;
border-right: 1px #E6E6E6 solid;
}
.vMsg2 {
font: bold 22px arial;
position: relative;
top: 78px;
width: 720px;
text-align: center;
direction:rtl;
clear:both;
}
.vMain {
position: relative;
top: 113px;
width:620px;
direction:rtl;
clear:both;
}
.vMainJobs {
position: relative;
top: 30px;
width:620px;
direction:rtl;
clear:both;
}
.pgn1 {
width: 330px;
top:30px;
position: relative;
}
html>body .pgn1 {display:table;}
.pgnbx {
width: 30px;
height: 20px;
line-height:20px;
float:right;
text-decoration: none;
text-align:center;
}
html>body .pgnbx a {display:table;}
.pgnbx a{
width: 30px;
border-width: 1px;
border-color: #ffe #aaab9c #ccc #fff;
border-style: solid;
background: #FFF;
background: #CDF6ED;
}
.pgnbx a:hover{
width: 30px;
background: #B3E1D7;
border-color: #fff #ccc;
text-decoration: none;
}
.mainXJobs {
height:55px;
clear:both;
}
.ad728Y{
position: relative;
width:728px;
border-top: double thick #D3D3D3;
border-bottom: double thick #D3D3D3;
}
</style>
</head>
<body topmargin='0' leftmargin='0' >
<div class="mainFrame" align="center">
<div class="logosmallContainer1">
<div class="logosmall"><img border="0" src="media/small.jpg" alt="logo"></div>
<DIV class=adtop2>
</div>
</div>
<div class="jobtabs">
<div class="upperTabs">
<DIV class=uprTabs><A href="?Category6">Category 6</DIV>
<DIV class=uprTabs>Category 5</DIV>
<DIV class=uprTabs>Category 4</DIV>
<DIV class=uprTabs>Category 3</DIV>
<DIV class=uprTabs> Category 2</DIV>
<DIV class=uprTabs>Category 1</DIV>
</div>
<div class ="lowerTabs">
<DIV class=lowrTabs>Category 7</DIV>
<DIV class=lowrTabs>Category 8</DIV>
<DIV class=lowrTabs>Category 9</DIV>
<DIV class=lowrTabs>Category 10</DIV>
<DIV class=lowrTabs> Category 11</DIV>
<DIV class=lowrTabs>Category 12</DIV>
</div>
</div>
<div class='vMsg2'><H1>
GENERAL LIST
</H1></div>
<br><br><br><br><br><div class="ad300" id="ad"></div><div class='vMainJobs' dir='ltr'> <table border='0' width='100%' dir='ltr' cellspacing='1'>
<tr>
<th width='100%' colspan='2'>DETAILS</th>
</tr>
<tr>
<td width='18%'height='18' valign='top'>LOCATION </td>
<td height='18'>LONDON</td>
</tr>
<tr>
<td width='18%'height='18' valign='top'>LINK</td>
<td height='18'><a href='https://www.example.com'>https://www.example.com</a></td>
</tr>
</table>
<table border='0'>
<tr>
<td class='blank'>
<a href='#top'>top of page</a>
</td>
</tr>
</table>
</div>
<div class="pgn1">
<div class='pgnbx'>
<a href='?jpage=2'>2</a>
</div>
<div class='pgnbx'>
<a href='?page=3'>3</a>
</div>
<div class='pgnbx'>
<a href='?jpage=4'>4</a>
</div>
<div class='pgnbx'>
<a href='?page=5'>5</a>
</div>
<div class='pgnbx'>
<a href='?jpage=6'>6</a>
</div>
<div class='pgnbx'>
<a href='?page=7'>7</a>
</div>
<div class='pgnbx'>
<a href='?jpage=8'>8</a>
</div>
<div class='pgnbx'>
<a href='?page=9'>9</a>
</div>
<div class='pgnbx'>
<a href='?page=10'>10</a>
</div>
<div class='pgnbx'>
<a href='?jpage=11'>11</a>
</div>
<div class='pgnbx'>
<a href='?page=12'>12</a>
</div>
</div>
<div class="mainXJobs"> </div>
<DIV class="ad728Y"> PUT item "Classicus" here HERE</DIV>
<br><br><br>
</div>
</body>
</font>
</html>
The reason your body does not adjust is because you are assigning width using px. Try to change it to "%" or "vw". You can always assign a max-width or min-width if you want to put a limit on how much you want the width to be.
If you need to have the children adjust to the parent container, assign the width: 100%.
You have to use media query for mobile devices.
For example if I want to add background color for the device of maximum 600px, it will show body background color as
lightblue
after 600px it will be the default.
#media only screen and (max-width: 600px) {
body {
background-color: lightblue;
}
}

how to center the button inside a table cell

I'm trying to center a button inside the table by : text-align: center
However, it seems doesn't work for me.
Note: I used Display: table-cell combine with Vertical-align: middle to center the text of the button. As you can see the text of the first button "AAAAAAA" is in the middle.
Can someone help me to center the button without affecting the text of the button.
Thank you in advance.
Here's the example code:
http://codepen.io/anon/pen/pAcBx
I usually do
margin:auto;
display:block;
I guess #rhino answer works as well. Remember to remove
display:table-cell;
EDIT:
Keep in mind that doing this will get the a element content vertically centered, but if you also give the a element an arbitrary height, the surrounding background will not be centered.
Example 1: the text is vertically centered. But you set the button height to 32px and that surrounding container isn't:
table, tr, td{
border: solid;
}
.my_table {
width: 312px;
margin: 0 auto;
}
.dashed {
border-bottom:1px dashed #99F;
width:100%;
display:block;
position:absolute;
font-size:0;
top:43px;
}
/*BUTTON TABLE left CELL*/
.left_button_cell{
margin: 0 auto;
text-align: center; /*<---- NOT WORKING */
height: 50px;
padding-top: 10px;
line-height: 22px;
}
/*BUTTON TABLE right CELL*/
.right_button_cell{
text-align: center;
height: 50px;
padding-top: 10px;
line-height: 22px;
}
.inner_button {
-moz-box-shadow:inset 0px 1px 0px 0px #ffffff;
-webkit-box-shadow:inset 0px 1px 0px 0px #ffffff;
box-shadow:inset 0px 1px 0px 0px #ffffff;
background-color:#fbfbfb;
-webkit-border-top-left-radius:8px;
-moz-border-radius-topleft:8px;
border-top-left-radius:8px;
-webkit-border-top-right-radius:8px;
-moz-border-radius-topright:8px;
border-top-right-radius:8px;
-webkit-border-bottom-right-radius:8px;
-moz-border-radius-bottomright:8px;
border-bottom-right-radius:8px;
-webkit-border-bottom-left-radius:8px;
-moz-border-radius-bottomleft:8px;
border-bottom-left-radius:8px;
text-indent:0;
border:2px solid #dcdcdc;
display:block;
margin:auto;
color:#939393;
font-family:arial;
font-size:15px;
font-weight:normal;
font-style:normal;
height:32px;
line-height:16px;
width:104px;
text-decoration:none;
text-align:center;
text-shadow:1px 1px 0px #ffffff;
word-wrap:break-word;
vertical-align:middle;
}
.inner_button:hover {
background-color:#EBEBEB;
}
.inner_button:active {
position:relative;
top:1px;
}
<div class="dashed"></div>
<table class="my_table">
<tbody>
<tr>
<td class="left_button_cell">
<a class="inner_button" href="#">AAAAAAAA</a>
</td>
<td class="right_button_cell">
<a class="inner_button" href="#">BBBBBBBB BBBBBBBB</a>
</td>
</tr>
</tbody>
</table>
You could set the line-height to be also 32px, which would work for the first button, but the second one would break. Also, you could set a button padding of 6px to achieve the same result without declaring an explicit height (as css frameworks like bootstrap or materialize do) but the line break on the second button would result in uneven button sizes.
So, here's my suggested trick: set the a element line height to be 32px, then wrap its inner text in a span element where you reset the line-height to 16px:
table, tr, td{
border: solid;
}
.my_table {
width: 312px;
margin: 0 auto;
}
/*BUTTON TABLE left CELL*/
.left_button_cell{
margin: 0 auto;
text-align: center; /*<---- NOT WORKING */
height: 50px;
padding-top: 10px;
line-height: 22px;
}
/*BUTTON TABLE right CELL*/
.right_button_cell{
text-align: center;
height: 50px;
padding-top: 10px;
line-height: 22px;
}
.inner_button {
-moz-box-shadow:inset 0px 1px 0px 0px #ffffff;
-webkit-box-shadow:inset 0px 1px 0px 0px #ffffff;
box-shadow:inset 0px 1px 0px 0px #ffffff;
background-color:#fbfbfb;
-webkit-border-top-left-radius:8px;
-moz-border-radius-topleft:8px;
border-top-left-radius:8px;
-webkit-border-top-right-radius:8px;
-moz-border-radius-topright:8px;
border-top-right-radius:8px;
-webkit-border-bottom-right-radius:8px;
-moz-border-radius-bottomright:8px;
border-bottom-right-radius:8px;
-webkit-border-bottom-left-radius:8px;
-moz-border-radius-bottomleft:8px;
border-bottom-left-radius:8px;
text-indent:0;
border:2px solid #dcdcdc;
display:block;
margin: 0 auto;
color:#939393;
font-family:arial;
font-size:15px;
font-weight:normal;
font-style:normal;
height:32px;
line-height:32px;
width:104px;
text-decoration:none;
text-align:center;
text-shadow:1px 1px 0px #ffffff;
word-wrap:break-word;
vertical-align:middle;
}
.inner_button span {
line-height:16px;
display:inline-block;
}
.inner_button:hover {
background-color:#EBEBEB;
}
.inner_button:active {
position:relative;
top:1px;
}
<table class="my_table">
<tbody>
<tr>
<td class="left_button_cell">
<a class="inner_button" href="#">
<span>AAAAAAAA
</span>
</a>
</td>
<td class="right_button_cell">
<a class="inner_button" href="#">
<span>BBBBBBBB BBBBBBBB</span>
</a>
</td>
</tr>
</tbody>
</table>
EDIT 2019
You can achieve the same using flexbox. However, this means the border-spacing property does no longer apply so you need to do some fine tuning to the cell margins.
Basically, you set flex properties as:
.my_table tr {
display:flex;
}
.my_table td {
margin: 2px;
height: 60px;
display:flex;
flex-grow:1;
/* centering the button */
align-items:center;
justify-content:center;
}
.inner_button {
display:flex;
/* centering the text inside the button */
align-items:center;
justify-content:center;
/* plus the other properties */
}
With this you no longer need playing with spans, and the alignment of children is controlled explicitly.
table, td{
border: solid;
}
.my_table {
width: 312px;
margin: 0 auto;
}
.my_table tr {
display:flex;
}
.my_table td {
margin: 2px;
height: 60px;
display:flex;
flex-grow:1;
align-items:center;
justify-content:center;
}
.inner_button {
align-items:center;
justify-content:center;
display:flex;
width:104px;
box-shadow:inset 0px 1px 0px 0px #ffffff;
background-color:#fbfbfb;
text-align:center;
border-radius:8px;
border:2px solid #dcdcdc;
color:#939393;
font-family:arial;
font-size:15px;
height:45px;
text-decoration:none;
text-shadow:1px 1px 0px #ffffff;
word-wrap:break-word;
}
.inner_button:hover {
background-color:#EBEBEB;
}
.inner_button:active {
position:relative;
top:1px;
}
<table class="my_table">
<tbody>
<tr>
<td class="left_button_cell">
<a class="inner_button" href="#">
AAAAAAAA
</a>
</td>
<td class="right_button_cell">
<a class="inner_button" href="#">
BBBBBBBB BBBBBBBB
</a>
</td>
</tr>
</tbody>
</table>
Anyway, once you switch to this layout there's no reason to stick to tables, and you might as well convert your layout to divs.
Change display: table-cell to display: inline-block:
.inner_button {
/* ... */
display: inline-block;
/* ... */
}
I added this to the TableCell and it centered my ImageButton. I think we were running into the same issue.
<asp:TableCell HorizontalAlign="Center" style="padding: 0px;">
<asp:ImageButton/>
</asp:TableCell>
Found my answer here: http://forums.asp.net/t/1418752.aspx?image+button+inside+table+cell
You can use the table-cell display property of the container div and set the vertical-align property to middle:
HTML
<div id="table">
<div class="row">
<div class="cell">
I'm your button
</div>
</div>
</div>
CSS
#table {
width: 300px;
display: table;
background: red;
}
.row {
display: table-row;
}
.cell {
display: table-cell;
height: 200px;
background: yellow;
vertical-align: middle;
text-align: center;
}
You can find the fiddle here.
this works
td{
align:center;
}
simple and easy... hope it helps

can't get div to flush at the top of the page

I can't seem to get the right side/column of the page to flush at the top. I've included a picture to show you guys what I mean.
JSFiddle
http://jsfiddle.net/vDUE7/2/
Picture
http://oi57.tinypic.com/3128hew.jpg
Code
<div class="top-column">
<div class="image"><img src="http://www.hoax-slayer.com/images/blue-tiger- source.jpg" width="730" height="360"></div></div>
<div id="content">
<div class="middle-column">
<article class="in-column">
<img src="http://www.hoax-slayer.com/images/blue-tiger-source.jpg" width="150" height="100">
<b>Bengal Tiger</b></article>
</div>
<div id="side">
<li class="list">
<img src="http://www.hoax-slayer.com/images/blue-tiger-source.jpg" width="120" height="79" />
<p class="side-news">Bengal Tiger</p></a>
</li>
<li class="list">
<img src="http://www.hoax-slayer.com/images/blue-tiger-source.jpg" width="120" height="79" />
<p class="side-news">Bengal Tiger</p></a>
</li>
<li class="list">
<img src="http://www.hoax-slayer.com/images/blue-tiger-source.jpg" width="120" height="79" />
<p class="side-news">Bengal Tiger</p></a>
</li>
<li class="list">
<img src="http://www.hoax-slayer.com/images/blue-tiger-source.jpg" width="120" height="79" />
<p class="side-news">Bengal Tiger</p></a>
</li>
</div></div>
<div class="block">
</div>
</div>
CSS
img {
border: 0px;
display: block;
margin: 0 auto;
}
header#head {
padding-left: 20px;
position: relative;
border-left: 1px solid #dddddd;
border-right: 1px solid #dddddd;
border-bottom: 1px solid #000;
}
.image {
position: relative;
cursor: pointer;
float:left;
}
#container {
width: 1055px;
margin: 0 auto;
text-align: left;
background: #fff;
padding: 0;
margin-top:-26px;
}
#content {
overflow:hidden;
width:1053px;
height:100%;
border: 1px solid #dddddd;
}
#side{
width:312px;
height:100%;
float:left;
margin-top:-10px;
padding-left:10px;
background-color:#f3f3f3;
}
.block {
border-top: 1px solid #dddddd;
text-align: center;
background-color:#000;
width:1053px;
height:365px;
position:relative;
font-size:15px;
color: #fff;
}
.list{
width:300px;
border-bottom: 1px solid #dddddd;
display: inline-block;
margin-top:10px;
}
.middle-column {
width: 730px;
float: left;
border-right: 1px solid #dddddd;
}
article.in-column {
text-align: left;
padding: 15px;
border-bottom:1px solid #dddddd;
height:100%;
}
article.in-column img{
float:left;
margin-right:15px;
}
.list img{
float:left;
margin-right:15px;
border:1px solid #ddd;
margin-bottom:10px;
}
.top-column {
float: left;
width:730px;
height:360px;
border-right: 1px solid #000;
border-left: 1px solid #000;
border-bottom: 1px solid #000;
}
have removed the sidebar from the content div and placed it separately and instead of using float:left i've used display:inline-block. here's the updated fiddle,
http://jsfiddle.net/vDUE7/9/
hope this solves your problem.
HTML
<div class="top-column">
<div class="image"><img src="http://www.hoax-slayer.com/images/blue-tiger-source.jpg" width="730" height="360"></div></div>
<div id="side">
<li class="list">
<img src="http://www.hoax-slayer.com/images/blue-tiger-source.jpg" width="120" height="79" />
<p class="side-news">Bengal Tiger</p></a>
</li>
<li class="list">
<img src="http://www.hoax-slayer.com/images/blue-tiger-source.jpg" width="120" height="79" />
<p class="side-news">Bengal Tiger</p></a>
</li>
<li class="list">
<img src="http://www.hoax-slayer.com/images/blue-tiger-source.jpg" width="120" height="79" />
<p class="side-news">Bengal Tiger</p></a>
</li>
<li class="list">
<img src="http://www.hoax-slayer.com/images/blue-tiger-source.jpg" width="120" height="79" />
<p class="side-news">Bengal Tiger</p></a>
</li>
</div>
<div id="content">
<div class="middle-column">
<article class="in-column">
<img src="http://www.hoax-slayer.com/images/blue-tiger-source.jpg" width="150" height="100">
<b>Bengal Tiger</b></article>
</div>
</div>
<div class="block">
</div>
</div>
CSS
img {
border: 0px;
display: inline-block;
margin: 0 auto;
}
header#head {
padding-left: 20px;
position: relative;
border-left: 1px solid #dddddd;
border-right: 1px solid #dddddd;
border-bottom: 1px solid #000;
}
.image {
position: relative;
cursor: pointer;
float:left;
}
#container {
width: 1055px;
margin: 0 auto;
text-align: left;
background: #fff;
padding: 0;
margin-top:-26px;
}
#content {
overflow:hidden;
height:100%;
border: 1px solid #dddddd;
}
#side{
width:312px;
height:100%;
display:inline-block;
background-color:#f3f3f3;
}
.block {
border-top: 1px solid #dddddd;
text-align: center;
background-color:#000;
width:1053px;
height:365px;
position:relative;
font-size:15px;
color: #fff;
}
.list{
width:300px;
border-bottom: 1px solid #dddddd;
display: inline-block;
margin-top:10px;
}
.middle-column {
width: 730px;
float: left;
border-right: 1px solid #dddddd;
}
article.in-column {
text-align: left;
padding: 15px;
border-bottom:1px solid #dddddd;
height:100%;
}
article.in-column img{
float:left;
margin-right:15px;
}
.list img{
float:left;
margin-right:15px;
border:1px solid #ddd;
margin-bottom:10px;
}
.top-column {
float: left;
width:730px;
height:360px;
border-right: 1px solid #000;
border-left: 1px solid #000;
border-bottom: 1px solid #000;
}
Add a style to the side bar of
position:fixed;
top:0;
left:/*width of whatever width the stuff to the left of the side bar has*/
Hope I helped

How to vertical align my images with Texts

I have a question regarding a vertical align of my image and text
I have someone like
<div id='div1'>
<div id='div2'>
text here, more and more and more and more texts…….
<img src='test.png' class='img'/>
</div>
</div>
#div2{
border-color: black;
border-style: solid;
border-width: 0 1px 1px 1px;
padding: 10px;
font-size: .8em;
}
#div1{
width: 250px;
}
.img{
float:right;
vertical-align:middle;
}
I want my result like
text here, more and more and more
and more and more and more and more img here
texts
Can anyone help me about it? Thanks a lot!
The image will be in vertical middle no matter how many line of texts I have.
You have to vertical align the text as well as the image
<div id='div1'>
<div id='div2'>
<span>text here, more and more and more and more texts…….</span>
<img src='http://www.designboom.com/cms/images/user_submit/2012/10/asdfg_osi_skystack_d2n_01_m2nl.jpg' class='img' width="100px" height="auto"/>
</div>
</div>
#div2 > * {
vertical-align: middle;
}
Check this
html :
<div id='div1'>
<div id='div2'>
<p> text here, more and more and more and more texts…….</p>
</div><div class="right"><img src='test.png' class='img'/></div>
</div>
css
#div2{padding: 10px;
font-size: .8em;
float:left;
border: 2px solid #ccc;
vertical-align:middle;}
#div1{
width: 350px;
border: 2px solid #000;
height:100px;
}
.right{
float:right;
}
I hope help you.
try this code, check JsFiddle : http://jsfiddle.net/nAHwn/2/
<div id='div1'>
<div id='div2'>
<div id ="div3">text here, more and more and more and more texts……. text here, more and more and more and more texts…….text here, more and more and more and more texts……. text here, more and more and more and more texts……. text here, more and more and more and more texts…….</div>
<img src='http://www.designboom.com/cms/images/user_submit/2012/10/asdfg_osi_skystack_d2n_01_m2nl.jpg' class='img' width="100px" height="auto"/>
</div>
</div>
#div2{
border-color: black;
border-style: solid;
border-width: 0 1px 1px 1px;
padding: 10px;
font-size: .8em;
position:relative;
}
#div1{
width: 250px;
}
.img{
float:right;
vertical-align:middle;
position:absolute;
top:40%;
right:0px;
}
#div3 {width: 100px;
word-wrap:break-word;
}

Sidebar and Container width CSS problem

I have a simple page for a chat system.
Test page can be found here: http://komasurfer.com/chat-test/
Here's the code:
<html>
<head>
<style type="text/css">
#page-wrap {
margin-top: 10px;
margin-bottom: 10px;
width: 100%;
/*for sidebar*/
margin-right: -110px;
background-color: #AAAAFF;
}
#chat-wrap {
border: 1px solid #eee;
margin: 0 5px 10px 0;
float: left;
/*margin for sidebar*/
margin-right:115px;
border: 1px solid red;
background-color: #600000; }
#chat-area {
width:100%;
height: 400px;
border: 1px solid #666;
float: left;
}
#sidebar {
border: 1px solid green;
float: right;
width: 110px;
padding: 0px 0px 0px 5px;
}
#entry {
background-color: #ffffff;
padding: 5px;
font-size: 1em;
clear: both;
border: 3px solid #999;
height: 40px;
width: 97%; }
#entry-btn {
padding: 18px;
float: right; }
.left {float: left; }
.right {float: right; }
.c {clear: both; }
</style>
</head>
<body>
<div id="page-wrap">
<div id="sidebar">
SIDEBAR
</div>
<div id="chat-wrap">
<div id="chat-area">
<div id="loading">connecting to server...</div>
</div>
</div>
<div class="c"></div>
<form id="send-message-area">
<div>
<table border="0" width="100%" cellpadding="0" cellspacing="0">
<tbody><tr><td align="left" width="98%" style="padding-right:5px;">
<textarea tabindex="1" maxlength="2000" id="entry"></textarea>
</td><td align="right">
<input id="entry-btn" type="button" value="Send">
</td></tr></tbody></table>
</div>
</form>
</div>
</body>
</html>
I've been trying for a very long time now to get the red box (with the contents of the chat) to expand to the sidebar.
If I add a width of 100% to that box, it always disregards the margin that I set for the sidebar and expands to the width of the container box.
How can I make the red chat area expand to the sidebar (minus a safety margin of 5 pixels)?
The layout is a floating one, so I cannot work with absolute measurements. And the sidebar should be 110 pixels.
Remove float:left from chat-wrap and increase the right margin like this:
#chat-wrap {
background-color: #600000;
border: 1px solid red;
margin: 0 136px 10px 0;
}