CSS - Inline Menu Items With Block Dropdowns
hi, Im making a menu that looks like:
link1 link2 link3 link4 and then wen you hover over link a dropdown may appear i have the problem that when they appear, they lay on top of each other. ANy idea how to make they display under each other. (it doesnt even work in IE at the mo, but i gues ill laft2 sort that later) thanks this is the html: PHP Code: <ul> <li><a href="index.php?action=home">home</a></li> <li><a href="index.php?action=whatnew">what's new</a></li> <li><a href="index.php?action=offers">special offers</a></li> <li><a href="#">collections</a> <ul><a href="#">drop1</a></ul> <ul><a href="#">drop2</a></ul> <!--when looping thru categories, do a WHERE cat_status >= 2--> </li> <li><a href="index.php?action=sBask">shopping basket</a></li> <li><a href="index.php?action=contact">contact us</a></li> </ul> this is the relevant css: PHP Code: #nav ul li { position: relative; margin: 0; padding: 0 10px 0 10px; list-style: none; display: inline; } #nav ul li ul { position: absolute; display: none; } #nav ul li:hover ul { display: block; left: 0; top: 10px; } #nav ul li:hover ul li { height: 20px; } Similar TutorialsHi! Is it OK to mix inline and block elements? For example: <imp ... /> <p> .... </p> Thanks I'm reading the "containing blocks" section of http://www.brainjar.com/css/positioning/: "Block boxes are generated by elements such as P, DIV or TABLE." <div> This is the first sentence. <p>This is the second sentence.</p> </div> "It's interesting to note that while the text of the first sentence in the above example generates an inline box" -Didn't they say that block boxes are generated by div? So why isn't the text of the first sentence in a block box? I am a 3week knewb to css. I was wondering if anyone could explain to me when I would use: div or display:block div or span span or display:inline thank you Hi, I am still quite new to CSS so forgive me if this is a silly question but I have created a DIV layout that look something like Code: <div class=row><div class=square>A</div><div class=square>B</div><div class=square>C</div></div> In the CSS "row" is designated as display type BLOCK "square" is designated as "INLINE-BLOCK" in safari, firefox etc this comes up showing the A,B & C next to each other in their own styled boxes. This is how I want to be. However in Internet Explorer (currently testing it on v8), the A ,B and C show up , one underneath the other in a straight line down the page. This is not cool. To fix this issue, I tried changing the inline-block to just "inline" This works fine now in IE, the squares are next to each other like i wanted, but now when I test it on safari,firefox, the boxes go straight down the page! Am I missing something here? I would rather not make a special style sheet for IE if there is a solution that will help make it work on all three browsers. It just seems strange that the display types are working completely opposite to each other . Any help would be appreciated. below if the full CSS rules if that helps any Code: .row { width: 100%; height: 30px; display: block; font-size: 14px; text-align: center; font-family: "Lucida Grande", Verdana, Arial, sans-serif; } .square { display: inline-block; background-color: #eeeeee; line-height: 30px; height: 30px; width: 30px; border-width: 1px; border-color: #000000; border-style: solid; } Thanks for taking the time to read my question. I have a <div></div> that I am using to make a bar across my page. In this bar I am placing the links to the other pages on the site. If I don't use float, the height is messed up. If I do use Float, the width shrinks to the minimum. So I added width: 100%; but that made it wider than the rest of the other bars I already have... at leasts in FF, but not in IE. What should I be using? Float? Block? Inline? I've read the descriptions on http://www.w3schools.com/css/pr_class_display.asp but am still unclear on how to use them. I would like to have an area as wide as the page, with links in it so that the height fits the text + the padding. Does DocType help this? Not to clear on how to use that either. Thanks again, Brad my code below. HTML: Code: <html> <!-- Generated by AceHTML Freeware http://freeware.acehtml.com --> <!-- Creation date: 20-Jan-2006 --> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Contribution Help</title> <meta name="description" content=""> <meta name="keywords" content=""> <meta name="author" content="piercedjunkmail@hotmail.com"> <meta name="generator" content="AceHTML 5 Freeware"> <link href="ChurchHelp.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="Bar1"></div> <div id="TitleBar">Help for You</div> <div id="MenuBar"> <div id="MenuItem"><a href="index.html">Home</a></div> <div id="MenuItem"><a href="General.html">General Help</a></div> <div id="MenuItem"><a href="Settings.html">Settings Help</a></div> <div id="MenuItem"><a href="Contribution.html">Contribution Help</a></div> <div id="MenuItem"><a href="Member.html">Member Help</a></div> <div id="MenuItem"><a href="SiteMap.html">Site Map</a></div> </div> <div id="imgCont"> <img src="Images/ContributionForm.jpg" border="0" width="427" height="287" alt=""> </div> </body> </html> CSS: Code: body { margin: auto; background-color: #bcb277; font-family: Veranda, Arial, sans-serif; } #Bar1 { background-color: #CC9900; height: 10px; } #TitleBar { background-color: #330033; height: 30px; color: green; font-weight: 25px; padding-top: 5px; padding-left: 10px; } #MenuBar { display: compact; /*float: left;*/ /*width: 100%;*/ background-color: #006600; padding: 2px; } #MenuItem { float: left; margin-left: 30px; color: white; } #imgCont { float: left; padding: 12px; background-color: #a99a66; } a:link { color: white; text-decoration: none; } a:visited { color: #DCDCDC; text-decoration: none; } a:hover { color: #A9A9A9; text-decoration: overline underline; } a:active { color: #8B0000; } I'm trying to display 5 images across, and underneath each image will be a caption. So, i'm using an inline list, but how do I go about getting something to the second line for each list item, seems that inline-block works fine in IE, but since its not available for Firefox, what's the method people use here? I usually lurk in the Javascript forum, but a frustrating CSS issue has presented itself. I've googled this extensively and haven't found any working solutions. I'll write in pseudo-code what I want to happen, and hopefully someone can fill in the blanks... here goes: Code: <style type="text/css"> .container { display: inline-block; } .title { align: left; } .subtext { align: right; } </style> <div class="container"> <div class="header"> <div class="title">Title Goes Here</div> <div class="subtext">Align Me Right</div> </div> <div class="content"> Variable content which container needs to size dynamically to fit. Could be 300px wide, could be 500px wide... </div> </div> What I've tried so far: Tried setting the container width to 1% so IE would autosize to content (while setting white-space: nowrap for the title/subtext), but IE wrapped between the title and subtext elements) Played around with setting absolute widths for the container, but I would really prefer being able to have variably sized content And unfortunately (in many ways) it only has to work in IE. Any help would be greatly appreciated. Thanks! I'm new to CSS (Other then very basic CSS) Anyway I have a menu which uses a tags, that also have a background image. I am adding in the background image with CSS, I have the display set to inline-block as block would put everything to the next line and inline would not allow for the image to show though in full (only enough for the text inside the link. Anyway using display: inline-block it seems to put padding on the links, is there a way to remove this? i want the background images from the links to be next to each other with no spacing or padding. My code: #buttonBackground { display: inline-block; background-image:url(/media/images/button_background.jpg); background-repeat:no-repeat; width: 113px; padding-top: 4px; height: 23px; text-align:center; vertical-align: bottom; (This isn't working either?) } and a sample link: <a href="default.asp" id="buttonBackground">HOME</a> Anyone able to help me remove the padding surronding the a tag? Ok, so maybe I don't understand the display attribute quite right. What I'm doing makes sense to me, but it's not working right when displayed. I have a div that is set to display inline (so that I don't have to use floating). Since inline elements can't have height/width attributes, i have another div inside of it, with display set to block. This inner div has height and width attributes. Now, if I place another similar structure (block div inside inline div) in the code, the two outer divs /should/ (in my mind) render side-by-side with the heights and widths of their child div's. When I try it though, it displays everything as block-type. Any ideas? PHP Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Title</title> <style type="text/css"> img{ border: 0px black solid; height: 200px; } div.outerholder{ display: inline; } div.innerholder{ text-align: center; height: 200px; width: 267px; margin: 0px; padding: 0px; display: block; } div.centerme{ text-align: center; margin-left: auto; margin-right: auto; } </style> </head> <body> <div class="centerme"> <div> <div class="outerholder"> <div class="innerholder" style="margin-right: 5px;"><a href="dir1/PICTURE.JPG"><img src="dir1/PICTURE.JPG" /></a></div> </div> <div class="outerholder"> <div class="innerholder" style="margin-left: 5px;"><a href="dir1/PICTURE.JPG"><img src="dir1/PICTURE.JPG" /></a></div> </div> </div> <div> <div class="outerholder"> <div class="innerholder" style="margin-right: 5px;"><a href="dir1/PICTURE.JPG"><img src="dir1/PICTURE.JPG" /></a></div> </div> <div class="outerholder"> <div class="innerholder" style="margin-left: 5px;"><a href="dir1/PICTURE.JPG"><img src="dir1/PICTURE.JPG" /></a></div> </div> </div> <div> <div class="outerholder"> <div class="innerholder" style="margin-right: 5px;"><a href="dir1/PICTURE.JPG"><img src="dir1/PICTURE.JPG" /></a></div> </div> </div> </body> </html> P.S. It also doesn't center properly in FF, but that's secondary... I hate IE so much. Ok, I have a list, with a display:inline-block; property. Wanting a row of images, with text under each mage. I thought I solved this with this property, but with IE, it doesnt put the images in a row, but places them one under the other. FORM: Code: <ul> <li> <img src="images/news/dummy.png" name="News" width="100" height="100" /><br /> Category<br /> 00/00/00</li> </ul> CSS: Code: #images ul { list-style:none; text-align:center; } #images li { margin-right:15px; display:inline-block; } Either a fix for IE, or a alternative to this would be great. Thanks in advance, Joe. Hey everyone, I seem to be having problems on IE7 for a clients website (http://beitelligent.com/clients/sportsdome/ ).. If you view it on IE8 or Firefox 2.X+ it seems to display correctly, all on the same line.. on IE7 it still displays it as a list.. Does anyone know why this is? Thanks, Peter Barbosa Hello, I a horizontal navigation within <ul><li> tags. Here is the css for the navigation <ul><li> and the first button. Code: #nav li{ display:inline; } a#aboutrollover { background-image:url(images/nav/about_off.gif); background-repeat:no-repeat; width:77px; height:18px; display:block; } a#aboutrollover span { display:none; } a#aboutrollover:hover { background-image:url(images/nav/about_on.gif); background-repeat:no-repeat; width:77px; height:18px; } You'll notice that for the button, I have display set to "block." Well, if I set it as "inline" or don't put a display, the span text shows. But the block makes the <li>'s stack upon each other. Here's the navigation code :: Code: <ul id="nav" name="nav"> <li> <a onclick="updateWithAbout()" href="#" id="aboutrollover"><span>About Cats Meow</span></a> </li> <li> <a onclick="updateWithGuest()" href="#" id="guestrollover"><span>Guest Pics</span></a> </li> <li> <a onclick="updateWithStaff()" href="#" id="staffrollover"><span>Cats Staff</span></a> </li> <li> <a href="#" id="webcamsrollover"><span>Cat's webcams</span></a> </li> <li> <a onclick="updateWithParties()" href="#" id="partiesrollover"><span>Cat's Meow Parties</span></a> </li> <li> <a onclick="updateWithContact()" href="#" id="contactrollover"><span>Contact Cats Meow</span></a> </li> </ul> I also tried display: run-in; and display:compact; instead of display:block;. But the first 2 options would make my navigation dissapear. Here is the site:: http://www.catskaraoke.com/index2.php Is there a simple solution to displaying the navigation horizontally? I know I can make it work, but it's a bit of excessive code for something that should be easy. thanks Hi all, I've got a problem on my hands. I've been restructuring the site I work on from their FrontPage code to complete XHTML + CSS. I always thought that by using span's that I could make a block level element display inline, but keep all of it's block level uniqueness, such as height and width and other items, but would display right next to other elements. Works great with headers and such but not with boxes. I created a 4 <span> system inside a centered div, figuring they'd all work. But span's don't keep their block level uniqueness, so nothing displayed at all! I fixed 3 of these 4 by putting their background images inside the spans, which I wanted to avoid, but it works so I won't complain on that. Now I have this. Code: <div id="bigdiv"> <span id="maptop"><img src="images/2004/new_main_front/wel_left_top.jpg" alt="Welcome!" /></span><span id="feattop"><img src="images/2004/new_main_front/feat_right_top.png" alt="" /></span><br /> <span id="mapbot"><img src="images/2004/new_main_front/wel_left_bot.jpg" alt="" /></span><span id="featbot">This is where things will go.</span><br /> </div> Span id featbot has no images, it has a repeat-x background so that I can place and change text in there at will. Because of this, and it being a span, it wraps only to the size of the text, which isn't good. I found a display: inline-table (displays as a table, but inline, pretty obvious), which works great in Safari for OS X, but not in IE 6 or Firefox on Windows. How would I structure this correctly so that it actually does work? Here is an image showing the design and how it's set up (ignore the gradients, they're not being used). As you can see where featbot is, that's where text will go, the others are images, so they display right. Suggestions? I'm really confused here... Thanks. Hello, First, I am new to webcoding so I apologise if what I am asking is too stupid. I am doing a little navigation bar for my blog with the hover effect. My problem is that the hover effect only work when I use {display: block;} but I need it to be inline, because when doing {display:block} it displays vertically. However when I do {display: inline-block;} the list items do show up inline horizontally but they show up only as images, neither does the hover effect or the links work. Second, in IE and in chrome it displays differently. Thank you very much for all the help! Also, here is the code! CSS #header-wrapper2{ height:80px; width:580px; margin:0; float: right; background-color: #000000; } #header-wrapper2-navbar{ height: 40px; width: 243; margin-top:40px; margin-left: 3px; padding:0; } #header-wrapper2-navbar li{ margin:0; padding:0; } #header-wrapper2-navbar li,#header-wrapper2-navbar a{ height: 40px; display: block; } #news{ left:0px; width:78px; background: url('') 0 0; } #news a:hover{ background: url('') 0 -44px; } #products{ left:78px; width:88px; background: url('') -78px 0; } #products a:hover{ background: url('') -78px -44px; } #about{ left:166px; width:77px; background: url('') -166px 0; } #about a:hover{ background: url('') -166px -44px; } HTML <div id='header-wrapper2'> <ul id='header-wrapper2-navbar'> <li id='news'><a href='()></li> <li id='products'><a href='></li> <li id='about'><a href='></li> </ul> </div> Hello, I'm customising a theme in wordpress and having a problem centering the three widgets that appear in the footer at the bottom. Nothing seems to work that I have tried. I know very little about css but understand the basic principle but can't seem to find the problem. I want the footer to be 100% the width of the page and for the three wigets to be in a single row of 3 but in the center and not off to the left. I've tried adjust the float but it just stacks them on top of each other set to none and over to the right set to right... I've inlcuded the CSS below and also the code in my footer.php page. Thanks in advance. test site is http://mtbireland.com/hkr Code: </div> </div> </div> <div style="width:100%; text-align: center; margin: 0 auto;"> <div id="footer"><div id="footer-left"> <ul> <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('footer 1') ) : ?> <li> <?php endif; ?> </ul> </div> <div id="footer-middle"> <ul> <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('footer 2') ) : ?> <li> <?php endif; ?> </ul> </div> <ul> <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('footer 3') ) : ?> <li> <?php endif; ?> </ul> </div> Code: #footer { height:200px; padding:20 0 0 0; color:#FFFFFF; font-size:12px; font-weight:normal; line-height:20px; font-family: Tahoma,georgia,Century gothic, Arial, sans-serif; width:100%; float:left; background:#392E2C; text-align:left; } /* Footer Widgets */ #footerwidgets { display: block; width:100%; background:#392E2C; } #footer-left { width: 210px; float: left; margin: 15px 10px 10px 30px; padding: 10px; text-align:left; } #footer-middle { width: 210px; float: left; margin: 15px 10px 10px 15px; padding: 10px; text-align:left; } #footer-right { width: 210px; float: right; margin: 15px 10px 10px 15px; padding: 10px; text-align:left; } Is it possible mix inline and block-level elements directly together?? For example: Code: <div....> <input..... /> <-- inline element <ul>... <-- block element </div> Thank you Hello, I know that putting a block level element (such as <p> or <div>) inside an inline element (such as <a>) is against "xhtml 1.0 strict" rules, so I'm putting a <span> (inline) within an <a> (also inline). I've made my <span> "display: block;", and it works in all browsers and validates fine, but I feel like I'm cheating the system a bit? The thing is, I need to put a margin under a piece of text without using <br /> (as when a browser forces a line break, it will use that rule and make different pieces of text look odd), but all the text is within an anchor tag, so I can't use <p> or <div>. Would appreciate any thoughts on the matter, Cheers! I have been trying in vain to get div elements on a page to behave how i want them to. I have a list of items, in the middle of which i need to display some tablular information witha picture along side it. This i have managed to acieve fine, but i can't get the next <li> to start below these 2, it starts alongside and the wraps underneath. I have tried everything. Can anyone help? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <style type="text/css"> <!-- #wrapper{ font-family:Verdana, Arial, Helvetica, sans-serif; margin-left: 20px; width: 550px; font-size: 12px; line-height: 22px; letter-spacing: 0.5px; color: #666666; } #topimg { margin: 20px 0; padding-bottom: 20px; border-bottom: 1px dotted #CCCCCC; text-align:left; display:block; } #secondimg { margin: 0 0 0 20px; text-align:left; display:block; } #bodyimg{ padding: 20px 0px 20px 20px; float:left; display:block; } #listtable{ padding-top: 20px; padding-bottom: 20px; float:left; font-size: 10px; letter-spacing: 0.5px; color: #891C46; list-style-type: none; line-height:18px; } #listtable li{ margin: 1px; padding: 1px; } #listtable div { margin: 1px; padding: 1px; background-color: #F7F7F7; } --> </style> <title>Carlton</title> </head> <body> <div id="wrapper"> <div id="topimg"> <img src="/carlton-newsite/img/planandbuy/planandbuy.gif" width="173" height="33"> </div> <div id="secondimg"> <img src="/carlton-newsite/img/planandbuy/thebasics.gif" width="133" height="23"> </div> <ul> <li>Cinema Advertising is available in weekly blocks starting on Fridays.</li> <li>It is possible to buy <em> guaranteed admissions</em> by TV region, <em> follow specific films</em> or <em> nominate individual screens</em>. </li> <li>The minimum time unit available is 5 seconds. Prices differ based on commercial length with indeces using 30” as a base: </li> <div id="listtable"> <table width="200" border="0" cellspacing="0" cellpadding="0" class="nobullet"> <tr> <td width="105"> <li> <div>5”</div> </li> <li>10”</li> <li> <div>20”</div> </li> <li>30”</li> <li> <div>40”</div> </li> <li>45”</li> <li> <div>50”</div> </li> <li>60”</li> <li> <div>90”</div> </li> </td> <td width="95"> <li> <div>.3”</div> </li> <li>.5”</li> <li> <div>.8”</div> </li> <li>.1.00”</li> <li> <div>.1.33”</div> </li> <li>.1.50”</li> <li> <div>.1.67”</div> </li> <li>.2.00”</li> <li> <div>.3.00”</div> </li> </td> </tr> </table> </div> <div id="bodyimg"> <img src="/carlton-newsite/img/digital_adver/satelite.jpg" width="220" height="182"> </div> <li>Cinema commercials are shown on 35mm film, it is easy to get your TV ad transferred by our production department. </li> <li>Lead times from booking to getting on screen are 3 weeks, although CSA’s <em> Early Booking Incentive</em> guarantees extra value if you can book your campaign 6 weeks in advance of start date. </li> <li>Cinema Advertising Association <em> cinema buying guidelines</em> ensure your campaign meets industry agreed standards. </li> </ul> </div> </body> </html> As the title says... Design constraints unfortunately mean I need to do achieve the basic design shown in the example below (using a list) I have created an example to illustrate the problem I am experiencing. Problem example The list item text is wrapping too early in IE6 and IE7, though fine in my other target browsers such as Firefox and Opera. removing clear:left stops the wrapping, but then when 2 or more nav items have short content they sit on the same line which is no good obviously Any ideas / solutions etc. would be most welcome |