How to vertical align my images with Texts - html

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;
}

Related

Two div in a line and other two on the next line

i am try css to display div in line
this is my html
<body>
<div id="main">
<div id="div1">div1</div>
<div id="div2">div2</div>
</div>
<div id="main_new">
<div id="div1_new">div1_new</div>
<div id="div2_new">div2_new</div>
</div>
</body>
this is my css
#div1{
border: solid 1px #000000;
background-color: #0066CC;
float: left;
}
#div2{
border: solid 1px #000000;
background-color: #66CC00;
float: right;
}
JSfiddle
here i am set only first div sub two div in one line
but i want to set another two div same as this
div1_new is in below on div1
div2_new is in below on div2
thanks.
Try this fiddle
http://jsfiddle.net/J7mJX/47/
You need to apply a clearfix
.clearfix:after {
content: "";
display: table;
clear: both;
}
CSS for your html:
#div1, #div1_new {
border: solid 1px #000000;
background-color: #0066CC;
float: left;
}
#div2, #div2_new {
border: solid 1px #000000;
background-color: #66CC00;
float: right;
}
#main, #main_new {
overflow:hidden;
}
I think this is what you want.
Changed the id names to classes instead. I also put a br tag to separate the divs!
<body>
<div id="main">
<div class="divs1">div1</div>
<div class="divs1">div2</div>
</div>
<br/>
<div id="main_new">
<div class="divs2">div1_new</div>
<div class="divs2">div2_new</div>
</div>
</body>
(display:inline-block; is the code you probably were missing)
And here's the adjusted Css:
.divs1{
border: solid 1px #000000;
background-color: #0066CC;
width:70px;
display:inline-block;
}
.divs2{
border: solid 1px #000000;
background-color: #66CC00;
width:70px;
display:inline-block;
}
Here's a fiddle link to help:
http://jsfiddle.net/Anicefry/t3Lmw/
Is that what you want? http://jsfiddle.net/ugktn/
<body>
<div id="left-col">
<div>div1</div>
<div>div1_new</div>
</div>
<div id="right-col">
<div>div2</div>
<div>div2_new</div>
</div>
<div id="main_new">
middle text
</div>
</body>
Css:
body{
margin: 0;
}
#left-col{
border: solid 1px #000000;
background-color: #0066CC;
float: left;
}
#right-col{
border: solid 1px #000000;
background-color: #66CC00;
float: right;
}
Specify your desired width for all div.Include this in all
width:100px;
float:left;
Try to use less divs :-)
<!DOCTYPE html>
<html lang="en">
<head>
<title> Bla! </title>
<style type='text/css'>
div {width:50%; float:left}
div.divRed { background-color:red; }
div.divGreen { background-color:Green; }
</style>
</head>
<body >
<div class='divRed'> div1 </div>
<div class='divGreen'> div2 </div>
<div class='divGreen'> div1 new </div>
<div class='divRed'> div2 new </div>
</body>
</html>
Add a <div style="clear:both;"></div> before first container ends
DEMO
#main {
width:50%;
float:left;
}
#main_new {
width:50%;
float:right;
}
#div1{
border: solid 1px #000000;
background-color: #0066CC;
}
#div2{
border: solid 1px #000000;
background-color: #66CC00;
}
#div1_new{
border: solid 1px #000000;
background-color: red;
}
#div2_new{
border: solid 1px #000000;
background-color: yellow;
}
If you don't want to change your actual code and use css calculation do this in your css:
body{
margin: 0;
}
#main{
border: solid 1px #000000;
background-color: #0066CC;
float: left;
}
#main_new{
border: solid 1px #000000;
background-color: #66CC00;
float: right;
}
http://jsfiddle.net/J7mJX/51/
or if you want them side by side add a width to the body:
body{
margin: 0;
width: 113px;
}
#main{
border: solid 1px #000000;
background-color: #0066CC;
float: left;
}
#main_new{
border: solid 1px #000000;
background-color: #66CC00;
float: right;
}
http://jsfiddle.net/J7mJX/52/
Html:
<div id="main-div">
<div style="float:left">div1</div>
<div style="float:right">div2</div>
<div style="clear:both"></div>
</div>
<div id="main-div1">
<div style="float:left">div3</div>
<div style="float:right">div4</div>
<div style="clear:both"></div>
</div>
Css:
#main-div,.main-div1{
width:90px;
}

div alignment based on the content

I want to design the layout like below screenshot.
I tried to do this by using following code.
<div class="salesDiv">
<div>
Quarter To Date
</div>
<div>
830
</div>
<div>
<img src="~/Images/navigation-unit-actionplan.png" />
</div>
<div class="offtier">
<span>OFF TIER2</span>
</div>
<br />
</div>
<br />
<br />
<div class="salesDiv">
<div>
Rolling 3 Month
</div>
<div>
835
</div>
<div>
<img src="~/Images/navigation-unit-actionplan.png" />
</div>
<div class="offtier">
<span>National 852</span>
</div>
<br />
</div>
css :
.salesDiv {
width: 313px;
margin-left: 10px;
border: solid 1px gray;
border-radius: 4px;
height: 20px;
display: inline-block;
}
.salesDiv > div {
float:left;
margin-left:20px;
}
.offtier {
border-left-style: dotted;
background-color: green;
height: 20px;
width: 88px;
}
but it didn't give the same layout as like above screenshot. I want to do like above screenshot. What's going wrong? Please anyone look into this.
http://jsfiddle.net/zHLMS/
spacing also not good. I need equal spacing for all the content inside the border.
I need to maintain the same width for both the element.
Thanks,
Siva
You need to apply
display: inline-block;
float:right;
to the sales > divs and float: right to the offtier divs
Here's the modified code
Try this....Updated Link
.salesDiv {
width: 313px;
margin-left: 10px;
border: solid 1px gray;
-webkit-border-radius:5px;
border-radius:5px;
height: 20px;
display: inline-block;
position:relative;
}
.salesDiv > div {
float:left;
margin-left:20px;
}
.offtier {
-webkit-border-radius: 0 5px 5px 0;
border-radius: 0 5px 5px 0;
background-color: green;
height: 20px;
width: 88px;
right:0;
position:absolute;
}
Good Luck..Enjoy

Auto Adjust Div Height

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

Image over flow fix?

I have two columns; first column goes for image and the second holds detail.
My problem is the image over flows to the next line
Adding overflow:auto; or inline-block; to div.portfolioitems_wrap didn't help me
list http://img577.imageshack.us/img577/7002/screenshot20121204at135.png
Maker
<div class="portfolioitems_wrap">
<div class="portfolioitems_column1">first image</div>
</div>
<div class="portfolioitems_column2">information of the institute</div>
<div class="portfolioitems_wrap">
<div class="portfolioitems_column1">first image</div>
</div>
<div class="portfolioitems_column2">information of the institute</div>
<div class="portfolioitems_wrap">
<div class="portfolioitems_column1"><img src="/image/nature.jpg" class="thumbnail" alt="nature" />
</div>
</div>
<div class="portfolioitems_column2">information of the institute
</div>
<div class="portfolioitems_wrap">
<div class="portfolioitems_column1">first image</div>
</div>
<div class="portfolioitems_column2">information of the institute</div>
<div class="clear"></div>
CSS
div.portfolioitems_wrap{
float: left;
width:100%;
color:#555555;
border-bottom: 1px solid #eee;
height: 1.5em;
margin-bottom: 1em;
}
div.portfolioitems_column1{
margin-right: 10px;
}
div.portfolioitems_column2{
float: left;
color:#555555;
width: 300px;
margin-left: -300px;
font-size: 80%;
}
div.portfolioitems_column1 .thumbnail
{
float:left;
margin-right:20px;
border:1px solid #979390;
width:80px;
margin-bottom: 5px;
}
div.clear{
clear: both;
}
Further to my comment above: http://jsfiddle.net/hp7dY/
Just the min-height seems to be enough to fix this
It looks like your DIV organization is a little confused, which is adding to your problem. I'm assuming that the portfolioitems_wrap DIV is supposed to enclose both columns. That said, the problem is more that you're fixing the height of each table row, instead of allowing it to be flexible based on the content.
Removing the height:1.5em; entry from allows your elements to fit in the DIV. You might also consider displaying the column elements as inline-block.
div.portfolioitems_wrap{
float: left;
width:100%;
color:#555555;
border-bottom: 1px solid #eee;
// height: 1.5em;
margin-bottom: 1em;
}
div.portfolioitems_column1{
margin-right: 10px;
display:inline-block;
width:100px;
float:left;
}
div.portfolioitems_column2{
color:#555555;
font-size: 80%;
display:inline-block;
width:300px;
float:left;
}
div.portfolioitems_column1 .thumbnail {
float:left;
border:1px solid #979390;
width:80px;
margin: 0px 10px 5px 10px;
}
div.clear{
clear: both;
}
Here's a working fiddle with some other minor adjustments to make it pretty:
http://jsfiddle.net/72HML/
Hope that helps.

Any idea how to do this in css?

Any idea how to do this using css ?
I'm looking for a good and clear way to do this.
HTML
<div class="line"></div>
<span>OR</span>
<div class="line"></div>​
CSS
div.line
{
width:1px;
background-color:Gray;
height:40px;
margin:10px;
}
span
{
font-weight:bold;
}
Live Sample
​
HTML
<div class="orWrapper">Or</div>​
CSS
.orWrapper {
text-transform: uppercase;
}
.orWrapper:before,
.orWrapper:after {
content: "";
display: block;
height: 50px;
margin-left: 10px;
border-left: 1px solid #000000;
}
​
DEMO
The easiest way to do it is just use three divs and border property:
your html:
<div class="vertical">
</div>
<div>
OR
</div>
<div class="vertical">
</div>
your css :
.vertical{
border-left:thin solid black;
height:30px;
margin-left:10px;
}​
fiddle for testing: http://jsfiddle.net/SURzN/
working example: http://jsfiddle.net/fTGuV/
css:
.line
{
height:30px;
float:left;
margin-left:10px;
border: solid 0px #000000;
width:1px;
border-left-width: 2px;
}
html:
<div class="line">
</div>
<div style="clear:both;"></div>
<div>OR</div>
<div class="line">
</div>
<div style="clear:both;"></div>
HTML
<div class="line"><div class="txt">Or</div> <span></span></div>​
CSS
span{height:100%; display:block; margin:0 15px; border-left:1px solid black}
.line{width:30px; margin:10px; position:relative; height:200px; text-align:center}
.txt{position:absolute; top:45%; left:4px; width:20px; height:25px; background:white}
DEMO
​
Easiest thing i did :-
​<div Class="myclass"></div>
<div>OR</div>
<div Class="myclass"></div>​
CSS
​.myclass{
width:1px;
height:30px;
background-color:black;
margin-left:10px;
}
DEMO
I would keep it all in the same box...
HTML
<span class="vertical-bar">
<span>Or</span>
</span>​
CSS
.vertical-bar {
background: url(http://dl.dropbox.com/u/2179487/black_pixel.png) center top repeat-y;
float: left;
padding: 100px 0;
}
.vertical-bar span {
background-color: white;
text-transform: uppercase;
}​
Demo: http://jsfiddle.net/PjPAU/