Forum Moderators: not2easy

Message Too Old, No Replies

How do I mix inline and block items in <li>'s?

CSS novice stuck

         

steve

11:26 am on Jun 29, 2007 (gmt 0)

10+ Year Member



I'm building my first pure CSS site and I've hit my first stumbling block.

I'm using a background image to produce a rollover effect:


.main-content #buttons a:link, #buttons a:visited {
display: block;
border: none;
width: 117px;
height: 27px;
margin: 10px 10px 10px 10px;
font-size: 12px;
line-height: 22px;
color: #fff;
text-decoration: none;
background: #ff6600 url(./img/button-background.gif) no-repeat left top;
text-align: center;
}
.main-content #buttons a:hover {
background-color: #ff9933;
background-position: right top;
}

Which works great. Now I want to put the buttons in a list, and display one on each line with surrounding text:


.main-content ul {list-style:none; margin:0.5em 0 1.0em 0; float: left;}
.main-content ul li {margin:0 0 0.2em 2px; padding:0 0 0 12px; line-height:1.4em; font-size:120%;}
<ul>
<li>some text <a href="#">My button</a> some more text</li>
<li>some text <a href="#">My button</a> some more text</li>
</ul>

Because the buttons are block level they want to go on their own line. How do I stop them?

/Steve

<edit>Doctype</edit>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

Fotiman

3:20 pm on Jun 29, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Just a guess... but could you maybe float those things? For example, change your code to this:

<li><span>some text</span> <a href="#">My button</a> <span>some more text</span></li>

Then, do something like:


li span,
li a {
float: left;
}
li { clear: left; }

I haven't really looked thoroughly at your issue, but that's the first thing that came to mind.

Xapti

7:49 pm on Jun 29, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yeah, you'll have to float the anchor for it to not make a new line, and you'll have to float the first text to make sure it comes before the anchor. The second text doesn't need to be floated. If they were all floated, the LI would collapse without a fix. I'm not sure why Fotiman put clear:left on the li because it's not floating.

[edited by: Xapti at 8:01 pm (utc) on June 29, 2007]