search
HomeWeb Front-endHTML TutorialCSS MENU的白色三角形?位..._html/css_WEB-ITnose

CSS MENU

大家好, 这个MENU是参考FREE MENU网站的MENU改的, 把它套到DIV MENU里面, 为的是在右边出现一个放三个产品照片的区块,但是有一个白色三角形箭头, 我已经试了好久都改不好,就是当滑鼠移到右边区块的产品照片时, 三角形会错位跑到上面去,请熟悉CSS的朋友们帮帮忙, 帮我看一下要在哪里控制不要让它跑掉... 谢谢

<style type="text/css">body {	background-color: #fff;	background-repeat: repeat-x;	font-family: "微?正黑?", "Microsoft JhengHei", Arial, Helvetica, sans-serif;	margin-left: 0px;	margin-top: 0px;	margin-right: 0px;	margin-bottom: 0px;}#mainContent-2 {	font-family: "微?正黑?", "Microsoft JhengHei", Arial, Helvetica, sans-serif;	font-size: 14px;	text-decoration: none;	background-repeat: repeat-x;	text-align: center;}#main-big-banner {	width: 1024px;	margin-right: auto;	margin-left: auto;}#left-inside-title-0 {	width: 214px;	margin: 0px;	float: left;}#left-inside-title-1 {	width: 214px;	text-align: right;	height: 46px;	border-bottom-width: 5px;	border-bottom-style: solid;	border-bottom-color: #808080;	text-decoration: none;	background-color: #d9d9d9;}#left-inside-title-text {	font-family: "微?正黑?", "Microsoft JhengHei", Arial, Helvetica, sans-serif;	font-size: 26px;	font-weight: bold;	color: #FFF;	text-decoration: none;	width: 188px;	margin-top: 7px;	margin-right: 21px;	float: right;}#left-inside-title-down {	width: 214px;	text-align: right;}#left-menu-1 {	width: 214px;	margin-top: 10px;	margin-right: 21px;	float: right;	text-align: right;}.left-button-link-1 {	font-family: "微?正黑?", "Microsoft JhengHei", Arial, Helvetica, sans-serif;	font-size: 16px;	color: #AACD06;	text-decoration: none;	font-weight: bold;}.left-button-link-1:hover {	font-family: "微?正黑?", "Microsoft JhengHei", Arial, Helvetica, sans-serif;	font-size: 16px;	color: #D9FA3D;	text-decoration: none;	font-weight: bold;}.left-button-link-2 {	font-family: "微?正黑?", "Microsoft JhengHei", Arial, Helvetica, sans-serif;	font-size: 16px;	color: #666;	text-decoration: none;	font-weight: bold;}.left-button-link-2:hover {	font-family: "微?正黑?", "Microsoft JhengHei", Arial, Helvetica, sans-serif;	font-size: 16px;	color: #999;	text-decoration: none;	font-weight: bold;}/* Starter CSS for Flyout Menu */.cssmenu{	background-color: #eee;	width: 214px;	border-top-width: 1px;	border-bottom-width: 1px;	border-top-style: dashed;	border-bottom-style: dashed;	border-top-color: #ccc;	border-bottom-color: #ccc;	margin-top: 10px;	float: right;	margin-right: 0px;	text-align: right;}.cssmenu ul,.cssmenu ul li,.cssmenu ul ul {  list-style: none;  margin: 0;  padding: 0;  border: 0;}.cssmenu ul {  position: relative;  z-index: 597;  float: left;}.cssmenu ul li {	width: 190px;	float: right;  min-height: 1px;  line-height: 1em;  vertical-align: middle;}.cssmenu ul li.hover,.cssmenu ul li:hover {  position: relative;  z-index: 599;  cursor: default;}.cssmenu ul ul {  margin-top: 1px;  visibility: hidden;  position: absolute;  top: 1px;  left: 99%;  z-index: 598;  width: 100%;}.cssmenu ul ul li {  float: none;}.cssmenu ul ul ul {  top: 1px;  left: 99%;}.cssmenu ul li:hover > ul {  visibility: visible;}.cssmenu ul li {  float: none;}.cssmenu ul ul li {  font-weight: normal;}/* Custom CSS Styles */.cssmenu ul a,.cssmenu ul a:link,.cssmenu ul a:visited {  display: block;  font-family: "微?正黑?", "Microsoft JhengHei", Arial, Helvetica, sans-serif;  color: #f60;  text-decoration: none;}.cssmenu > ul {  float: none;}.cssmenu ul {/*  background: #fff;*/}.cssmenu > ul > li {/*  border-left: 3px solid #d7d8da;*/  float: right;}.cssmenu > ul > li > a {  padding: 10px 21px; /* 子???隔 */}.cssmenu > ul > li:hover {/*  border-left: 3px solid #bd3e53;*/}.cssmenu ul li:hover > a {  color: #f90;}.cssmenu > ul > li:hover {/*  background: #f6f6f6;*/}/* Sub Menu */.cssmenu ul ul a:link,.cssmenu ul ul a:visited {  font-family: "微?正黑?", "Microsoft JhengHei", Arial, Helvetica, sans-serif;  font-size: 9px;  color:#000;}.cssmenu ul ul {  width: 360px;  background: none;  border-left: 20px solid transparent;}.cssmenu ul ul a {  padding: 8px 0;/*  border-bottom: 1px solid #eeeeee;*/}.cssmenu ul ul li {  width: 340px;  margin-top:-45px; /* 三?品??位置 */  padding: 0 10px;  background: #fff;}.cssmenu ul ul li:last-child {/*  border-bottom: 3px solid #d7d8da;*/  padding-bottom: 0px;}.cssmenu ul ul li:first-child {  padding-top: 0px;}.cssmenu ul ul li:last-child > a {  border-bottom: none;}.cssmenu ul ul li:first-child:after {  content: '';  display: block;  width: 0;  height: 0;  position: absolute;  left: -20px;  top: 5px; /* 白色三角 */  border-left: 10px solid transparent;  border-right: 10px solid #fff;  border-bottom: 10px solid transparent;  border-top: 10px solid transparent;}</style><script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.min.js"></script><script language="javascript">$(function() {    $("a.left-button-link-2").mouseover(function(){		$(".cssmenu").slideUp();	var _this=$(this).attr("href");	if($(_this).css("display")=="none"){			$(_this).slideDown();		}else{			$(_this).slideUp();			}		return false;	});	$("#A1").mouseover(function(){		$("#a1").slideDown();		return false;	});	$("#A2").mouseover(function(){		$("#a2").slideDown();		return false;	});});</script><div id="mainContent-2">  <div id="main-big-banner"><table width="1024" border="0" cellspacing="0" cellpadding="0">      <tr>      <td width="214" align="left" valign="top">  <div id="left-inside-title-0">  <div id="left-inside-title-1"><div id="left-inside-title-text">MENUS</div></div>  <div id="left-inside-title-down">    <div id="left-menu-1"><a href="#" id="A1" name="A1" class="left-button-link-2">MENU-A</a></div>    <div id="a1" name="a1" style="display:none;" class="cssmenu">      <ul><li class="has-sub"><a href="#" class="apple-menu-text">MENU-A1</a>      <ul><li class="first"><table border="0" cellpadding="5"><tr align="center">      <td width="90"><a href="#"><img  src="/static/imghwm/default1.png"  data-src="upload/product/20131016115341.png"  class="lazy"      style="max-width:90%" border="0" alt="CSS MENU的白色三角形?位..._html/css_WEB-ITnose" ><br>Button Guard</a></td>      <td width="90"><a href="#"><img  src="/static/imghwm/default1.png"  data-src="upload/product/20131016114147.png"  class="lazy"      style="max-width:90%" border="0" alt="CSS MENU的白色三角形?位..._html/css_WEB-ITnose" ><br>Glass Guard</a></td>      <td width="90"><a href="#"><img  src="/static/imghwm/default1.png"  data-src="upload/product/2013101694948.png"  class="lazy"      style="max-width:90%" border="0" alt="CSS MENU的白色三角形?位..._html/css_WEB-ITnose" ><br>Glass Guard</a></td>      <td width="90"><a href="#"><span class="left-button-link-1">More..</span></a></td>      </tr></table></li></ul>      </li></ul>    </div>    <div id="left-menu-1"><a href="#" id="A2" name="A2" class="left-button-link-2">MENU-B</a></div>    <div id="a2" name="a2" style="display:none;" class="cssmenu">      <ul><li class="has-sub"><a href="#" class="apple-menu-text">MENU-B1</a>      <ul><li class="first"><table border="0" cellpadding="5"><tr align="center">      <td width="90"><a href="#"><img  src="/static/imghwm/default1.png"  data-src="upload/product/20131019200659.png"  class="lazy"      style="max-width:90%" border="0" alt="CSS MENU的白色三角形?位..._html/css_WEB-ITnose" ><br>yacht x laptop Mac book</a></td>      <td width="90"><a href="#"><img  src="/static/imghwm/default1.png"  data-src="upload/product/20131019200445.png"  class="lazy"      style="max-width:90%" border="0" alt="CSS MENU的白色三角形?位..._html/css_WEB-ITnose" ><br>lettre x Air Mac book</a></td>      <td width="90"><a href="#"><img  src="/static/imghwm/default1.png"  data-src="upload/product/20131019200102.png"  class="lazy"      style="max-width:90%" border="0" alt="CSS MENU的白色三角形?位..._html/css_WEB-ITnose" ><br>verglas x New iPan</a></td>      <td width="90"><a href="#"><span class="left-button-link-1">More..</span></a></td>      </tr></table></li></ul>      </li></ul>    </div>    <p> </p>  </div></div>    </td>        <td width="810" align="left" valign="top" bgcolor="#A0A0A0"></td>      </tr>    </table></div></div>



回复讨论(解决方案)

.cssmenu ul li:hover {
  position: relative;
  z-index: 599;
  cursor: default;
}
应该是这个position: relative的问题,因为三角是绝对定位的,定位在第一个relative的父元素中。
把这个position删了试试。

with386819368 ...

发现问题了,虽然按你说的拿掉position: relative,三角形不会跑掉,
但是如果增加子选单,那三个产品区块只会固定出现在第一个子选单旁边,
不会出现在第二个选单旁边,如果不拿掉,区块出现位置正常,但三角形会跑掉,
该如何解决呢... 以下HTML我有增加一个子选单


<style type="text/css">body {    background-color: #fff;    background-repeat: repeat-x;    font-family: "微?正黑?", "Microsoft JhengHei", Arial, Helvetica, sans-serif;    margin-left: 0px;    margin-top: 0px;    margin-right: 0px;    margin-bottom: 0px;}#mainContent-2 {    font-family: "微?正黑?", "Microsoft JhengHei", Arial, Helvetica, sans-serif;    font-size: 14px;    text-decoration: none;    background-repeat: repeat-x;    text-align: center;}#main-big-banner {    width: 1024px;    margin-right: auto;    margin-left: auto;}#left-inside-title-0 {    width: 214px;    margin: 0px;    float: left;}#left-inside-title-1 {    width: 214px;    text-align: right;    height: 46px;    border-bottom-width: 5px;    border-bottom-style: solid;    border-bottom-color: #808080;    text-decoration: none;    background-color: #d9d9d9;}#left-inside-title-text {    font-family: "微?正黑?", "Microsoft JhengHei", Arial, Helvetica, sans-serif;    font-size: 26px;    font-weight: bold;    color: #FFF;    text-decoration: none;    width: 188px;    margin-top: 7px;    margin-right: 21px;    float: right;}#left-inside-title-down {    width: 214px;    text-align: right;}#left-menu-1 {    width: 214px;    margin-top: 10px;    margin-right: 21px;    float: right;    text-align: right;}.left-button-link-1 {    font-family: "微?正黑?", "Microsoft JhengHei", Arial, Helvetica, sans-serif;    font-size: 16px;    color: #AACD06;    text-decoration: none;    font-weight: bold;}.left-button-link-1:hover {    font-family: "微?正黑?", "Microsoft JhengHei", Arial, Helvetica, sans-serif;    font-size: 16px;    color: #D9FA3D;    text-decoration: none;    font-weight: bold;}.left-button-link-2 {    font-family: "微?正黑?", "Microsoft JhengHei", Arial, Helvetica, sans-serif;    font-size: 16px;    color: #666;    text-decoration: none;    font-weight: bold;}.left-button-link-2:hover {    font-family: "微?正黑?", "Microsoft JhengHei", Arial, Helvetica, sans-serif;    font-size: 16px;    color: #999;    text-decoration: none;    font-weight: bold;}/* Starter CSS for Flyout Menu */.cssmenu{    background-color: #eee;    width: 214px;    border-top-width: 1px;    border-bottom-width: 1px;    border-top-style: dashed;    border-bottom-style: dashed;    border-top-color: #ccc;    border-bottom-color: #ccc;    margin-top: 10px;    float: right;    margin-right: 0px;    text-align: right;}.cssmenu ul,.cssmenu ul li,.cssmenu ul ul {  list-style: none;  margin: 0;  padding: 0;  border: 0;}.cssmenu ul {  position: relative;  z-index: 597;  float: left;}.cssmenu ul li {    width: 190px;    float: right;  min-height: 1px;  line-height: 1em;  vertical-align: middle;}.cssmenu ul li.hover,.cssmenu ul li:hover {  position: relative;  z-index: 599;  cursor: default;}.cssmenu ul ul {  margin-top: 1px;  visibility: hidden;  position: absolute;  top: 1px;  left: 99%;  z-index: 598;  width: 100%;}.cssmenu ul ul li {  float: none;}.cssmenu ul ul ul {  top: 1px;  left: 99%;}.cssmenu ul li:hover > ul {  visibility: visible;}.cssmenu ul li {  float: none;}.cssmenu ul ul li {  font-weight: normal;}/* Custom CSS Styles */.cssmenu ul a,.cssmenu ul a:link,.cssmenu ul a:visited {  display: block;  font-family: "微?正黑?", "Microsoft JhengHei", Arial, Helvetica, sans-serif;  color: #f60;  text-decoration: none;}.cssmenu > ul {  float: none;}.cssmenu ul {/*  background: #fff;*/}.cssmenu > ul > li {/*  border-left: 3px solid #d7d8da;*/  float: right;}.cssmenu > ul > li > a {  padding: 10px 21px; /* 子???隔 */}.cssmenu > ul > li:hover {/*  border-left: 3px solid #bd3e53;*/}.cssmenu ul li:hover > a {  color: #f90;}.cssmenu > ul > li:hover {/*  background: #f6f6f6;*/}/* Sub Menu */.cssmenu ul ul a:link,.cssmenu ul ul a:visited {  font-family: "微?正黑?", "Microsoft JhengHei", Arial, Helvetica, sans-serif;  font-size: 9px;  color:#000;}.cssmenu ul ul {  width: 360px;  background: none;  border-left: 20px solid transparent;}.cssmenu ul ul a {  padding: 8px 0;/*  border-bottom: 1px solid #eeeeee;*/}.cssmenu ul ul li {  width: 340px;  margin-top:-45px; /* 三?品??位置 */  padding: 0 10px;  background: #fff;}.cssmenu ul ul li:last-child {/*  border-bottom: 3px solid #d7d8da;*/  padding-bottom: 0px;}.cssmenu ul ul li:first-child {  padding-top: 0px;}.cssmenu ul ul li:last-child > a {  border-bottom: none;}.cssmenu ul ul li:first-child:after {  content: '';  display: block;  width: 0;  height: 0;  position: absolute;  left: -20px;  top: 5px; /* 白色三角 */  border-left: 10px solid transparent;  border-right: 10px solid #fff;  border-bottom: 10px solid transparent;  border-top: 10px solid transparent;}</style><script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.min.js"></script><script language="javascript">$(function() {    $("a.left-button-link-2").mouseover(function(){        $(".cssmenu").slideUp();    var _this=$(this).attr("href");    if($(_this).css("display")=="none"){            $(_this).slideDown();        }else{            $(_this).slideUp();            }        return false;    });    $("#A1").mouseover(function(){        $("#a1").slideDown();        return false;    });    $("#A2").mouseover(function(){        $("#a2").slideDown();        return false;    });});</script> <div id="mainContent-2">  <div id="main-big-banner"><table width="1024" border="0" cellspacing="0" cellpadding="0">      <tr>      <td width="214" align="left" valign="top">  <div id="left-inside-title-0">  <div id="left-inside-title-1"><div id="left-inside-title-text">MENUS</div></div>  <div id="left-inside-title-down">    <div id="left-menu-1"><a href="#" id="A1" name="A1" class="left-button-link-2">MENU-A</a></div>    <div id="a1" name="a1" style="display:none;" class="cssmenu">      <ul><li class="has-sub"><a href="#" class="apple-menu-text">MENU-A1</a>      <ul><li class="first"><table border="0" cellpadding="5"><tr align="center">      <td width="90"><a href="#"><img  src="/static/imghwm/default1.png"  data-src="upload/product/20131016115341.png"  class="lazy"      style="max-width:90%" border="0" alt="CSS MENU的白色三角形?位..._html/css_WEB-ITnose" ><br>Button Guard</a></td>      <td width="90"><a href="#"><img  src="/static/imghwm/default1.png"  data-src="upload/product/20131016114147.png"  class="lazy"      style="max-width:90%" border="0" alt="CSS MENU的白色三角形?位..._html/css_WEB-ITnose" ><br>Glass Guard</a></td>      <td width="90"><a href="#"><img  src="/static/imghwm/default1.png"  data-src="upload/product/2013101694948.png"  class="lazy"      style="max-width:90%" border="0" alt="CSS MENU的白色三角形?位..._html/css_WEB-ITnose" ><br>Glass Guard</a></td>      <td width="90"><a href="#"><span class="left-button-link-1">More..</span></a></td>      </tr></table></li></ul>      </li></ul>      <ul><li class="has-sub"><a href="#" class="apple-menu-text">MENU-A2</a>      <ul><li class="first"><table border="0" cellpadding="5"><tr align="center">      <td width="90"><a href="#"><img  src="/static/imghwm/default1.png"  data-src="upload/product/20131016115341.png"  class="lazy"      style="max-width:90%" border="0" alt="CSS MENU的白色三角形?位..._html/css_WEB-ITnose" ><br>11111 Guard</a></td>      <td width="90"><a href="#"><img  src="/static/imghwm/default1.png"  data-src="upload/product/20131016114147.png"  class="lazy"      style="max-width:90%" border="0" alt="CSS MENU的白色三角形?位..._html/css_WEB-ITnose" ><br>22222 Guard</a></td>      <td width="90"><a href="#"><img  src="/static/imghwm/default1.png"  data-src="upload/product/2013101694948.png"  class="lazy"      style="max-width:90%" border="0" alt="CSS MENU的白色三角形?位..._html/css_WEB-ITnose" ><br>33333 Guard</a></td>      <td width="90"><a href="#"><span class="left-button-link-1">More..</span></a></td>      </tr></table></li></ul>      </li></ul>    </div>    <div id="left-menu-1"><a href="#" id="A2" name="A2" class="left-button-link-2">MENU-B</a></div>    <div id="a2" name="a2" style="display:none;" class="cssmenu">      <ul><li class="has-sub"><a href="#" class="apple-menu-text">MENU-B1</a>      <ul><li class="first"><table border="0" cellpadding="5"><tr align="center">      <td width="90"><a href="#"><img  src="/static/imghwm/default1.png"  data-src="upload/product/20131019200659.png"  class="lazy"      style="max-width:90%" border="0" alt="CSS MENU的白色三角形?位..._html/css_WEB-ITnose" ><br>yacht x laptop Mac book</a></td>      <td width="90"><a href="#"><img  src="/static/imghwm/default1.png"  data-src="upload/product/20131019200445.png"  class="lazy"      style="max-width:90%" border="0" alt="CSS MENU的白色三角形?位..._html/css_WEB-ITnose" ><br>lettre x Air Mac book</a></td>      <td width="90"><a href="#"><img  src="/static/imghwm/default1.png"  data-src="upload/product/20131019200102.png"  class="lazy"      style="max-width:90%" border="0" alt="CSS MENU的白色三角形?位..._html/css_WEB-ITnose" ><br>verglas x New iPan</a></td>      <td width="90"><a href="#"><span class="left-button-link-1">More..</span></a></td>      </tr></table></li></ul>      </li></ul>    </div>     <p> </p>  </div></div>     </td>        <td width="810" align="left" valign="top" bgcolor="#A0A0A0"></td>      </tr>    </table></div></div>

这么久了不知道你解决了没
.cssmenu ul li.hover,
.cssmenu ul li:hover {
  position: relative;
  z-index: 599;
  cursor: default;
}
问题呢还是这里,.cssmenu ul li.hover这个选择不知道是不是没用的,可以去掉吧,改成
.cssmenu ul .has-sub:hover {
  position: relative;
  z-index: 599;
  cursor: default;
}
不然选择到了最里层的li,所以产生错误。
另外你要引用一下我,我才知道你的回复呀

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
HTML's Purpose: Enabling Web Browsers to Display ContentHTML's Purpose: Enabling Web Browsers to Display ContentMay 03, 2025 am 12:03 AM

The core purpose of HTML is to enable the browser to understand and display web content. 1. HTML defines the web page structure and content through tags, such as, to, etc. 2. HTML5 enhances multimedia support and introduces and tags. 3.HTML provides form elements to support user interaction. 4. Optimizing HTML code can improve web page performance, such as reducing HTTP requests and compressing HTML.

Why are HTML tags important for web development?Why are HTML tags important for web development?May 02, 2025 am 12:03 AM

HTMLtagsareessentialforwebdevelopmentastheystructureandenhancewebpages.1)Theydefinelayout,semantics,andinteractivity.2)SemantictagsimproveaccessibilityandSEO.3)Properuseoftagscanoptimizeperformanceandensurecross-browsercompatibility.

Explain the importance of using consistent coding style for HTML tags and attributes.Explain the importance of using consistent coding style for HTML tags and attributes.May 01, 2025 am 12:01 AM

A consistent HTML encoding style is important because it improves the readability, maintainability and efficiency of the code. 1) Use lowercase tags and attributes, 2) Keep consistent indentation, 3) Select and stick to single or double quotes, 4) Avoid mixing different styles in projects, 5) Use automation tools such as Prettier or ESLint to ensure consistency in styles.

How to implement multi-project carousel in Bootstrap 4?How to implement multi-project carousel in Bootstrap 4?Apr 30, 2025 pm 03:24 PM

Solution to implement multi-project carousel in Bootstrap4 Implementing multi-project carousel in Bootstrap4 is not an easy task. Although Bootstrap...

How does deepseek official website achieve the effect of penetrating mouse scroll event?How does deepseek official website achieve the effect of penetrating mouse scroll event?Apr 30, 2025 pm 03:21 PM

How to achieve the effect of mouse scrolling event penetration? When we browse the web, we often encounter some special interaction designs. For example, on deepseek official website, �...

How to modify the playback control style of HTML videoHow to modify the playback control style of HTML videoApr 30, 2025 pm 03:18 PM

The default playback control style of HTML video cannot be modified directly through CSS. 1. Create custom controls using JavaScript. 2. Beautify these controls through CSS. 3. Consider compatibility, user experience and performance, using libraries such as Video.js or Plyr can simplify the process.

What problems will be caused by using native select on your phone?What problems will be caused by using native select on your phone?Apr 30, 2025 pm 03:15 PM

Potential problems with using native select on mobile phones When developing mobile applications, we often encounter the need for selecting boxes. Normally, developers...

What are the disadvantages of using native select on your phone?What are the disadvantages of using native select on your phone?Apr 30, 2025 pm 03:12 PM

What are the disadvantages of using native select on your phone? When developing applications on mobile devices, it is very important to choose the right UI components. Many developers...

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Atom editor mac version download

Atom editor mac version download

The most popular open source editor