0

I am new to this and would really appreciate some guidance. I am trying to position my images in a div using css. I have used the inline element and it still appears underneath the image. Here is my code for my ui buttons:

   #UIButtons {
position:fixed;
top: 50%;
left: 40%;
width:45em;  /* this is correct and displays how I want it to*/
height:18em;
margin-top: -9em; 
margin-left: -15em;
background: url(backtabss.png);

}
#UIButtons ul{ /* this has set the height ok*/
position:relative;
top: 9%;
right: 50%;
width:45em;
}
#UIButtons li  {/*not sure what this is doing to be honest*/
position:relative;
top: 70%;
left: 45%;
display: inline; /* this is not working my images are appearing vertical*/
padding: 40px;
}

I have commented the code to let you know whats happening. The HTML is:

<div id="UIButtons"> 
  <ul>
     <li><a href="tutorials.html"><img src="beginBUT.png" alt="Click to start  Tutorials" title=" Click this button to start Tutorials" width="300" height="250"/></a></li>
     <li><a href="sChords.html"><img src="beginCHO.png" alt= "Click to view Chord Sheet" title=" Click this button to view Chord Sheet" width="300" height="250"/></a></li>
 </ul>  
</div>

Thank you for time. I have looked at other suggests on here but none are helping me, in fact its confusing me more!

4
  • You need to fill in details .. At least frame question well before posting .. it you can not create a jfiddle Commented Mar 25, 2014 at 18:00
  • Really confusing question not sure what you want? Commented Mar 25, 2014 at 18:04
  • Consider leaning on a CSS framework with good documentation like Twitter Bootstrap, and keep it very simple. The benefit of a framework like this is that you don't need to know or write CSS. Just follow the examples they provide in their documentation. Here are some Bootstrap examples to get you started. Commented Mar 25, 2014 at 18:08
  • Thank you for your help I will use your advice to get my head around the css framework :) Commented Mar 26, 2014 at 12:19

3 Answers 3

1

This css code should do the trick

#UIButtons ul {
    list-style-type:none;
    margin:0;
    padding:0;
}

#UIButtons li  {
    display:inline;
}

If the parent container is not big enough to keep both of the elements on one line then it will put it on the next line. Do you always want them on the same line regardless of the parent element's size?

http://jsfiddle.net/XS57H/

Sign up to request clarification or add additional context in comments.

Comments

0

You have a couple of widths that collide, and some that seem to work fine, but actually they block each other.

Look how weird the sizes and positions of those elements are when you give them a border:

http://jsfiddle.net/qaZsh/

Now, I've removed a lot of CSS and the result is this:

  #UIButtons {
       border: 1px solid blue;
position:fixed;
width:55em;  /* this is correct and displays how I want it to*/
background: url(backtabss.png);

}
#UIButtons ul{ /* this has set the height ok*/
       border: 1px solid red;
position:relative;
top: 9%;
}
#UIButtons li  {/*not sure what this is doing to be honest*/
       border: 1px solid green;
display: inline-block; /* this is not working my images are appearing vertical*/
padding: 40px;
}

http://jsfiddle.net/qaZsh/1/

I'm not sure if that is exactly what you want (hard to guess) , but I think it's a lot closer. I've changed one thing: changed inline to inline-block for the li.

You could probably strip it down even further. Anyway, sometimes it's good to take a step back (or even start over). In this case, I think you just were lost in a big number of absolute and relative positionings, combined with positive and negative margins and paddings. At a certain point it's impossible to keep overview.

1 Comment

Thank you so much the key was the borders. I could now see which of the css controlled which element. Thank you so much for your help. Now in future if I get in a muddle I will add borders to see what is going on. I really recommend to new users to do the same, once you see the positioning you can easily tweak the positioning to suit your requirements!
0

you should be using inline-block:

#UIButtons li {
position: relative;
top: 70%;
left: 45%;
display: inline-block;
padding: 40px;
}

and you need to up the width here:

#UIButtons ul {
position: relative;
top: 9%;
right: 50%;
width: 52em;
} 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.