Solved

Div Tag in HTML

Posted on 2010-11-30
11
305 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

911 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

22 Experts available now in Live!

Get 1:1 Help Now