Solved

Div Tag in HTML

Posted on 2010-11-30
11
304 Views
Last Modified: 2012-06-27
I would like to have 2 div tags as like table columns in my page.

Can someone share your knowledge to do this?

Thanks in advance
0
Comment
Question by:czutshi
  • 4
  • 2
  • 2
  • +3
11 Comments
 
LVL 2

Expert Comment

by:Jogai
ID: 34238589
0
 
LVL 19

Accepted Solution

by:
Bardobrave earned 167 total points
ID: 34238760
Try this:

<div width="49%" style="float:left;"></div><div width="49%" style="float:left"></div>

width at 49% for every div make them to fit both together on your page, float left style make them behave as inline elements, don't making second one to jump into new file.
0
 
LVL 16

Expert Comment

by:s8web
ID: 34239765
Hi Czutshi - I know you said two divs, but you will need a little more than that. Here is an example as to how to replicate a table with divs.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Divs like a table</title>
<style type="text/css">
#holder{
	width:700px; /*If this were a table, this would be the table tag - so define the width here in px or %*/
	}
.column{
	float:left;
	width:50%
	}
.cell{
	border:solid #ebebeb;
	border-width:0 1px 1px 1px;
	}
.cell:first-child{
	border:solid #ebebeb;
	border-width:1px 1px 1px 1px;
	}
.clear{clear:both;}
</style>
</head>

<body>
<div id="holder">
	<div class="column">
		<div class="cell">Column 1</div>
		<div class="cell">&nbsp;</div>
		<div class="cell">&nbsp;</div>
		<div class="cell">&nbsp;</div>
	</div>
	<div class="column">
		<div class="cell">Column 2</div>
		<div class="cell">&nbsp;</div>
		<div class="cell">&nbsp;</div>
		<div class="cell">&nbsp;</div>
	</div>
	<div class="clear"></div><!-- This needs to be last to clear your floats. Otherwise some ugly things can happen. -->
</div>
</body>
</html>

Open in new window

0
 
LVL 8

Assisted Solution

by:Zado
Zado earned 167 total points
ID: 34240634
Depends what you want to have in those columns, if it's text columns, you can use very simple css code (css3):

in <head> section:
<style type="text/css">  
.columns {  
  -moz-column-count: 2;  
  -webkit-column-count: 2;  
}  
</style> 

Open in new window



in <body> section:
<div class="columns">  
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>  
  <p>Lorem ipsum dolor sit amet.</p>  
</div>

Open in new window


Css3 is a very powerful tool in web design, the only defect is, it doesn't work properly in old browsers.
Read about css3 tricks here: http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/CSS/A_4168-New-CSS-techniques-with-CSS3.html?sfQueryTermInfo=1+30+css
(the article will be improved very soon)
0
 
LVL 16

Expert Comment

by:s8web
ID: 34240754
CSS3 columns don't work in IE7 or 8 which unfortunately is most browsers.
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 8

Expert Comment

by:Zado
ID: 34241090
True, and unfortunately IE is used by most people, worst browser ever and nightmare for web designers :-/
There's a lot of things work fine in every browser except IE.
0
 
LVL 2

Assisted Solution

by:Manidf
Manidf earned 166 total points
ID: 34247004
Try this out. i use this technique often.

1. have containing div #row (give this div a width say 600px)
2. inside of #row insert as many divs as you need. apply the "float: left; rule to them,
    ensure that the divs placed inside all cumulatively equal the width of the containing div being #row
    in this case i have 3 divs so they each are 200px wide.
3. you can place as many row divs below as you like. make sure to add "clear: both" to the .row div when stacking them so that they stack one on top of each other.

4. to note one can add a multitude of class names for styling to one div element. so i recommend using CLASS and not ID.  <div class="column green big"></div>
divs.html
0
 
LVL 2

Expert Comment

by:wasim117
ID: 34247196
You can use display:cell css property for
0
 
LVL 8

Expert Comment

by:Zado
ID: 34317461
Please grant the points and close the question, thanks :-)
0
 
LVL 8

Expert Comment

by:Zado
ID: 34384897
Please let us know if any solution provided works for you, otherwise we will continue work on your problem and try to find best possible solution, thanks.
0
 
LVL 2

Expert Comment

by:Manidf
ID: 34391793
Hi hows it going on this have you come to a resolution? take car. Manidf :-)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When writing CSS, there are a few simple rules that will make your life easier.    1. Using ‘* {box-sizing:border-box;}’. Using this will wrap all your elements in a nice little compact box-model that will give you the width you want, like so... …
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now