


我现在用ul做了一个横向菜单,想把它放在“home”连接的右边,但我发现它运行时ul菜单始终会换行,是不是css出了问题,请大家给我指教一下,谢谢。建议用firefox浏览器运行。
Home
|
回复讨论(解决方案)
在线等,请大家帮忙。
ul是块级元素,当然会换行,你可以强制它inline,其它自己调吧。
ul { display:inline}
把css的最后一行改成li:hover ul,.over ul { display:inline;}也不行,没办法只能用类似下面的坐标定位来调整了:
ul{
position:absolute;
top: 10px;
margin-left:100px;
}
<html xmlns="http://www.w3.org/1999/xhtml"><head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title></title> <style> ul { padding:0; margin:0; list-style:none;display: inline;} li { float:left; width:140px; } ul li a { text-decoration:none; color:#777;} li:hover { background-color:#ddd;} ul li ul li table{ background-color:#ddd;} li ul { display:none;} li:hover ul,.over ul { display:block;} </style></head><body><div style="float: left;"> <a style="color:red;" > Home </a> | </div><ul style="float: left;"> <li><a href="">menu1</a> <ul> <li><a href="">test1</a></li> <li><a href="">test2</a></li> <li><a href="">test3</a></li> <li><a href="">test4</a></li> </ul> </li> <li><a href="javascript:void(0);">menu2</a> <ul> <li><a href="">test5</a></li> <li><a href="">test6</a></li> </ul> </li></ul></body></html>
这是在你写的基础上改的。
oNA_na:你的代码可以把位置调整,但也带来了新的问题,在后面的代码在鼠标移到菜单上去就会向右浮动。代码如下:
test data 1 test data 1 test data 1 test data 1 test data 1 test data 1
test data 2
test data 3 test data 3 test data 3test data 3 test data 3 test data 3test data 3 test data 3 test data 3
这个定位问题很棘手也很急,我实在想不出来好的办法了,请大家帮忙。
我重新修改了一下css代码,定位正常了,但鼠标移到菜单上后面的元素就会往后移。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta content="text/html; charset=utf-8" http-equiv="content-type"> <title>prod menus</title> <style> ul.hMenu,ul.hMenu li ul { padding:0; margin:0; list-style:none;} ul.hMenu li { float:left; width:140px; } ul.hMenu li:hover a { color:red;} ul.hMenu li:hover { background-color:yellow;} ul.hMenu li ul li table{ background-color:yellow;} ul.hMenu li ul { display:none;} ul.hMenu li:hover ul,.over ul { display:block;} .eth{text-align:left;} </style> </head> <body> <div style="float: left;"> <a style="color:red;" > Home </a> | </div> <ul class="hMenu"> <li><a href="">menu1</a> <ul> <li><a href="">test1</a></li> <li><a href="">test2</a></li> <li><a href="">test3</a></li> <li><a href="">test4</a></li> </ul> </li> <li><a>menu2 </a> <ul> <li><a href="">test5</a></li> <li><a href="">test6</a></li> </ul> </li> </ul> <br/> test data 1 test data 1 test data 1 test data 1 test data 1 test data 1 <br/> test data 2 <br/> <a href="">test data 3 test data 3 test data 3test data 3 test data 3 test data 3test data 3 test data 3 test data 3</a> </body></html>
通过relative定位应该可以达到要求吧。
在上面代码的基础上,我改了一下。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta content="text/html; charset=utf-8" http-equiv="content-type"> <title>prod menus</title> <style> /*ul.hMenu,ul.hMenu li ul { padding:0; margin:0; list-style:none;}*/ /*ul.hMenu li { float:left; width:140px; }*/ /*ul.hMenu li:hover a { color:red;} */ /*ul.hMenu li:hover { background-color:yellow;}*/ /*ul.hMenu li ul li table{ background-color:yellow;} */ /*ul.hMenu li ul { display:none;}*/ /*ul.hMenu li:hover ul,.over ul { display:block;}*/ /**/ /*.eth{text-align:left;}*/ .hMenu { margin: 0; padding: 0; z-index: 30; width: 480px; height:23px;} .hMenu li { margin: 0; padding: 0; list-style: none; float: left; width:140px; } .hMenu li a { display: block; width: 140px; color:red; text-align: left; text-decoration: none} .hMenu li a:hover { background: yellow} .hMenu div { position: absolute; visibility: hidden; margin: 0; padding: 0; } .hMenu div a { position: relative; display: block; width: 140px; white-space: nowrap; text-align: left; text-decoration: none; background: yellow; color:red } </style> <script type="text/javascript"> var timeout = 100; var delaytime = 0; var ddmenuitem = 0; function mopen(id) { mcancelclosetime(); if(ddmenuitem) ddmenuitem.style.visibility = 'hidden'; ddmenuitem = document.getElementById(id); ddmenuitem.style.visibility = 'visible'; } function mclosedelay() { delaytime = window.setTimeout(mclose, timeout); } function mclose() { if(ddmenuitem) ddmenuitem.style.visibility = 'hidden'; } function mcancelclosetime() { if(delaytime) { window.clearTimeout(delaytime); delaytime = null; } } </script> </head> <body> <div style="float: left;"> <a style="color:red;" > Home </a> | </div> <ul class="hMenu"> <li><a href="" onmouseover="mopen('m1')" onmouseout="mclosedelay()">menu1</a> <div id="m1" onmouseover="mcancelclosetime()" onmouseout="mclosedelay()"> <a href="">test1</a> <a href="">test2</a> <a href="">test3</a> <a href="">test4</a> </div> </li> <li><a href="" onmouseover="mopen('m2')" onmouseout="mclosedelay()">menu2 </a> <div id="m2" onmouseover="mcancelclosetime()" onmouseout="mclosedelay()"> <a href="">test5</a> <a href="">test6</a> </div> </li> </ul> <br/> test data 1 test data 1 test data 1 test data 1 test data 1 test data 1 <br/> test data 2 <br/> <a href="">test data 3 test data 3 test data 3test data 3 test data 3 test data 3test data 3 test data 3 test data 3</a> </body></html>
lichuny257,你的代码可用,可以用纯css实现此效果吗?

HTMLattributesarecrucialinwebdevelopmentforcontrollingbehavior,appearance,andfunctionality.Theyenhanceinteractivity,accessibility,andSEO.Forexample,thesrcattributeintagsimpactsSEO,whileonclickintagsaddsinteractivity.Touseattributeseffectively:1)Usese

The alt attribute is an important part of the tag in HTML and is used to provide alternative text for images. 1. When the image cannot be loaded, the text in the alt attribute will be displayed to improve the user experience. 2. Screen readers use the alt attribute to help visually impaired users understand the content of the picture. 3. Search engines index text in the alt attribute to improve the SEO ranking of web pages.

The roles of HTML, CSS and JavaScript in web development are: 1. HTML is used to build web page structure; 2. CSS is used to beautify the appearance of web pages; 3. JavaScript is used to achieve dynamic interaction. Through tags, styles and scripts, these three together build the core functions of modern web pages.

Setting the lang attributes of a tag is a key step in optimizing web accessibility and SEO. 1) Set the lang attribute in the tag, such as. 2) In multilingual content, set lang attributes for different language parts, such as. 3) Use language codes that comply with ISO639-1 standards, such as "en", "fr", "zh", etc. Correctly setting the lang attribute can improve the accessibility of web pages and search engine rankings.

HTMLattributesareessentialforenhancingwebelements'functionalityandappearance.Theyaddinformationtodefinebehavior,appearance,andinteraction,makingwebsitesinteractive,responsive,andvisuallyappealing.Attributeslikesrc,href,class,type,anddisabledtransform

TocreatealistinHTML,useforunorderedlistsandfororderedlists:1)Forunorderedlists,wrapitemsinanduseforeachitem,renderingasabulletedlist.2)Fororderedlists,useandfornumberedlists,customizablewiththetypeattributefordifferentnumberingstyles.

HTML is used to build websites with clear structure. 1) Use tags such as, and define the website structure. 2) Examples show the structure of blogs and e-commerce websites. 3) Avoid common mistakes such as incorrect label nesting. 4) Optimize performance by reducing HTTP requests and using semantic tags.

ToinsertanimageintoanHTMLpage,usethetagwithsrcandaltattributes.1)UsealttextforaccessibilityandSEO.2)Implementsrcsetforresponsiveimages.3)Applylazyloadingwithloading="lazy"tooptimizeperformance.4)OptimizeimagesusingtoolslikeImageOptimtoreduc


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Linux new version
SublimeText3 Linux latest version
