I have a main content section which has the following CSS


  margin:0 auto;
  font-family:Arial, Helvetica, sans-serif;


I wanted extra yet separate Div block to be contained within the main element and float to the right. I could not get it to sit perfect. I am not to sure where i have went wrong . here is the code for my float element.

     float:right; width:500px; height:auto; position:inherit;
     background-color:#ffffff; margin-top:-31%; border-left-color:000; border-left-style:solid;
     border-left-width:thin; font-family:Arial, Helvetica, sans-serif; font-size:12px; text-align:justify;
     padding-left:1%; padding-right:1%; padding-top:1%;

I had to add a Margin-top of negative 31 for it to be aligned in the 1366 resolution of my widescreen monitor. On all other lower res screen it is pushed away to the bottom. I know i should not use negatives.

where am I going wrong?.

I need help.

  • Updated and fixed the CSS code blocks. In the future try and make sure your code is within code blocks (spaced over 4 spaces, or click the '10101' button in the menu) Ktash over 8 years ago

3 answers

Ktash 1851
This was chosen as the best answer

The HTML code here might be the bigger issue. My best guess without seeing your actual HTML code is that your div block is placed after your content block. Any content you want to float right or left needs to be placed before the content you want to float it with. So, your code should look like:


<div id="right_ad">
    ... <!-- Content you want on the right hand side. -->
<div id="content3">
   ... <!-- Main content -->


#right_ad {
    float: right;
    /* ... Styles go here ... */
#content3 {
    /* ... Styles go here ... */
Answered over 8 years ago by Ktash

Thank you very much. I never even noticed that my Div's were not in correct order. Fixed now. Thank you so much

Answered over 8 years ago by Matt Ewing
  • You're welcome. In the future, you can post this as a comment on my answer as opposed to as an answer on itself. This site has a different format then a traditional forum. Ktash over 8 years ago
  • Also, give vote as "Great Answer" when someone gives you the correct answer so they get props for their work. Xeoncross over 8 years ago

vpn firewall router

Answered over 8 years ago by Gene Sirkit