473,388 Members | 1,342 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,388 software developers and data experts.

Understanding Floating Divs

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 1729
Dormilich
8,658 Expert Mod 8TB
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
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...
0
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...
6
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...
12
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...
1
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...
2
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...
11
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:...
2
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...
4
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...
0
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
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...

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.