473,765 Members | 2,059 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Understanding Floating Divs

1 New Member
Despite having taken a course on web design, I appear to have very little practical knowledge of how to use CSS to get what I want. I think my problem is one of understand exactly what the functionality of each of these tags is, but no matter how many tutorials or other posts I read I can't seem to find out what I'm doing wrong.

Very simply: If this were to be a table, I would have two rows and three columns. In the first row would be an image, a video, and a different image. In the second row there is text, nothing, and text. The text corresponds to each of the images, so they should be lined up with the images above them. I also wanted everything centered on the page (and that's where things went wrong)

My best attempt at getting three images next to each other and centered caused the text to not go below the images. I don't know if I'm using the float style wrong or if I'm just not centering things the right way or WHAT, but if anyone can give me a pointer I'd really appreciate it. I hope I described my problem adequately.

Relevant HTML:
Expand|Select|Wrap|Line Numbers
  1. <div id="body">
  2.         <div id = "student-wrapper" class="wrapper"> 
  3.             <div id = "student-image">
  4.                 <a href="#">
  5.                     <img alt="Students Login" src="site images/students.png" width="300" height="190" />
  6.                 </a>
  7.             </div>
  8.         </div>
  9.         <div id = "video-wrapper" class="wrapper">
  10.             <iframe width="560" height="349" src="http://www.youtube.com/embed/cjaeYkTyUHk" frameborder="0" allowfullscreen></iframe>
  11.         </div>
  12.         <div id = "professional-wrapper" class="wrapper">
  13.             <div id = "professional-image">
  14.                 <a href="#">
  15.                     <img alt="Professionals Login" src="site images/professionals.png" width="200" height="400" />
  16.                 </a>
  17.              </div> <!-- END image div-->
  18.         </div> <!-- END professional-wrapper div-->
  19.         <div id="buffer"> </div>
  20.     </div> <!-- END body div -->
  21.  
  22.  
  23.     <div id = "goto-texts">
  24.        <div id = "student-text">
  25.               <a href="#"> 
  26.                    <p class="goto"> Start Here! </p> 
  27.             </a>
  28.        </div>
  29.        <div id = "professional-text">
  30.               <a href="#">
  31.                   <p class="goto"> Start Here! </p>
  32.             </a>
  33.        </div>
  34.    </div>
  35. </body>
And the CSS:

Expand|Select|Wrap|Line Numbers
  1. div#body{margin: 25px auto 25px auto; width:1200px;}
  2. div#student-wrapper{margin-right:30px;}
  3. div#professional-wrapper{margin-left:30px;}
  4.  
  5. p.goto{font-size:x-large; font-weight:bold}
  6. div.wrapper{float:left}

-Nick
Jun 23 '11 #1
1 1747
Dormilich
8,658 Recognized Expert Moderator Expert
first of all, I wouldn’t use the table approach (you still have 2 rows and 3 columns). the text belongs to the according image, thus image and text should have a common container.

the only question remaining is, where should the text sit vertically. either directly beneath the image (that’s the easy option) or all on the same line.
for the latter you will have to take the image out of the normal flow, which can be done by float: or position: absolute.

Example.
Expand|Select|Wrap|Line Numbers
  1. <div>
  2.     <img src="…" alt="image 1" width="20" height="30">
  3.     <p>Lorem ipsum dolor sit amet.</p>
  4. </div>
  5. <div>
  6.     <iframe></iframe>
  7.     &nbsp;
  8. <!-- you need content inside the <div>, otherwise it would collapse -->
  9. </div>
  10. <div>
  11.     <img src="…" alt="image 2" width="40" height="20">
  12.     <p>Morituri te salutant.</p>
  13. </div>
Expand|Select|Wrap|Line Numbers
  1. /* somewhat generic selectors for testing */
  2. div {
  3.     float: left;
  4.     width: 7em;
  5. }
  6. img, iframe {
  7.     position: absolute;
  8. }
  9. p {
  10.     margin-top: 3em;
  11. }
Jun 23 '11 #2

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

Similar topics

2
15144
by: Helen | last post by:
As soon as I float anything in a div, it is no longer held within the div anymore. I'd like to be able to float things relative to the element that they are contained in. Is this even possible in CSS? I'm a table based designer from way back, so maybe this is just the wrong approach to CSS. If this isn't actually possible, would someone be able to tell me what I can do instead? I don't really want to use absolute positioning because I...
0
2230
by: Olly | last post by:
I am using the following pure css layout with a header and footer: http://www.fu2k.org/alex/css/layouts/3Col_NN4_FMFM.mhtml The left column floats to the left of the main content (middle column). In the middle column I have 3 divs on top of each other, each of which needs to have a border. To get the borders to display correctly in Netscape 6 and ie5 (windows) I have to put a <br style="clear:both">
6
10921
by: veerleverbr | last post by:
Hi, I have the following html: <div id="content"> <div id="leftpart">...</div> <div id="rightpart">...</div> </div> leftpart en rightpart are in the css set to float left. The content of leftpart and rightpart div is so that both divs have different height.
12
2821
by: meltedown | last post by:
I would like the floating divs to float and then the header to come after them , on the left. That's what I thought clearing the floats was for, but in this example, the header is to the right of the floating divs, nothing is cleared. What am I doing wrong ? Here is the url:http://www.reenie.org/test/test5.php Here is the code: <html> <head>
1
1972
by: StevePBurgess | last post by:
I have a website which, on the main page, has two floating divs. One contains a list of navigation menu items and the other is themain content of the page. Occasionally that div that contains the menu is longer than the div that contains the main content. This displays perfeclty well on Firefox but on internet explorer the bottom bit of the navigation div is chopped off so that it is the same height as the (smaller) main content div.
2
3979
by: Arnost Sobota | last post by:
Hello, Suppose I want to play with DIVs as if they were type characters. I have a series of fixed-height (width is of no importance) blocks which must follow one another from left to right, with a small margin between them. This is easily done with the CSS float:left property. But in this context, what is the proper way to do a Line Feed/Carriage Return? Take a look at the code below for example's sake. I have 8 DIVs and I want to...
11
5411
by: yawnmoth | last post by:
How do you get both of these div's to have a 100% width? (1): <div style="float: left; background: black; color: white">Hello, world! </div> <div style="clear: both; background: blue; color: white">Hello, world! </div> You could set the width inside the floated div to 100% but if you do that and if you have a floated fixed width div, the 100% width div will appear on a new line, as demonstrated (2):
2
4230
by: benwah1983 | last post by:
Greetings, Here is my problem: The following code shows a div with two small nested divs (images with a title), then the div is closed. Another one opens and a "random text" is displayed. <div style="width: 500px;"> <div style="float: left; padding: 20px;"> Image Title 1<br/> <img src="test.jpg"/> </div> <div style="float: left; padding: 20px;">
4
32612
dlite922
by: dlite922 | last post by:
This is just barely above my head when it comes to css. I have a div that needs to contain rows of floating divs, but I need each row not to wrap on to the next one and continue to go right. The user will use a overflow: auto scroll to scroll to see the rest of the divs. illustration: # = === = = === === # = == = = # == ================== # =========
0
1708
by: nlindsay | last post by:
I am trying to center align 2 left floated divs within a % width background. I know that setting the wrapper div to a fixed width works, but can it be done with a fluid background? (basically I want 2 fixed width divs to center on a background image that stretches across the whole screen). thanks
0
9568
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10163
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9835
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8832
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.