473,397 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

How to display two div element in one line and align the whole in center?

How to display two div element in one line and align the whole in center?

I know that we can display two div elements in one line by giving float:left;.

But For Example:
Expand|Select|Wrap|Line Numbers
  1. <div class="MainDiv" id="div1">
  2.   <div class="InnerDiv1" id="div2">
  3.     <span>Hello,</span>
  4.   </div>
  5.   <div class="InnerDiv2" id="div3">
  6.     <span>How are u doing?</span>
  7.   </div>
  8. </div>
  9.  
I want the output to be

"Hello, How are u doing?" that to be aligned centered

If we give float:left; we get the text in one line but aligned to left.

Is there any other way to get the desired output?
Aug 13 '10 #1
1 6020
drhowarddrfine
7,435 Expert 4TB
We don't do things this way but to get what you want:
Expand|Select|Wrap|Line Numbers
  1. <style>
  2. #div1{ width:200px; margin:0 auto}
  3. #div2, #div3 {display:inline}
  4. </style>
  5. <div class="MainDiv" id="div1">
  6.   <div class="InnerDiv1" id="div2">
  7.     <span>Hello,</span>
  8.   </div>
  9.   <div class="InnerDiv2" id="div3">
  10.     <span>How are u doing?</span>
  11.   </div>
  12. </div>
  13.  
Aug 13 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

32
by: Axel Dahmen | last post by:
Hi, I'd like to align a <div> within the center of the visual canvas. The text within the div should be left-aligned. How can I possibly achieve this? So far I can only align text blocks...
1
by: 50295 | last post by:
Hi! I'm trying to set the align property/attribute of an IFrame to center but its not working (see below). Can anyone please tell me what's going on, and if there's a work around for this? ...
7
by: ALI-R | last post by:
Hi All, I have two user controls (header and footer) ,,which I've placed in an HTML Table in a page.I set the **align="center"** in the table and the table still is on the left side of the page...
11
by: Ben Amada | last post by:
Hello, When centering a block of HTML, in the past, I've always used: <div align="center"> ... </div> However, in VS 2005, I get the following warning: "Validation (XHTML 1.0...
1
by: Rabbit | last post by:
Dear All I'm new to use ASP.Net for developement, can someone tell me how can I create a web form with size say 300px x 300px, align vertically center on the page Because so far I can use Div...
1
by: Michael R | last post by:
Hello. I have a rather simply question - how to display a line number in an empty control of a continous form? I can't use totals query for that form. Thanks, Michael.
2
by: amulyab | last post by:
Hi all, I want to display the line numbers for the text which resides inside the text field.How can i do this?Please help me.
10
vikas251074
by: vikas251074 | last post by:
Here is my code. I want to display content in center of screen. But it is displaying in left side of screen. What to do for center alignment? Thanks and regard, Vikas ...
1
mickey0
by: mickey0 | last post by:
Hello, I would like to center 'Savi' but align=center seems dont' work on it. Any hints? thanks <html> <body> <table border="1"> <tr> <th align="center">Savi</th> </tr> <tr> ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.