【问题标题】:My submenu will only apear if i refresh my page?我的子菜单只有在我刷新页面时才会出现?
【发布时间】:2014-05-17 05:29:35
【问题描述】:

我正在为学校做一个项目,老师告诉我,如果我将鼠标悬停在某个图像上,则需要出现一个子菜单。我有一些代码,它可以工作,但前提是我刷新我的浏览器。我不知道为什么。

我也认为我应该在我的 HTML 中创建一个元素并将其内容放入我的 css 中,但我尝试过,它也不起作用。下面是我的 HTML 代码:

<header>
    <div class="wrapper">
        <h1 class="structural">De Fonduepot</h1>
        <section class="clearfix">
            <h2 class="structural">Kop</h2>
            <img src="images/kop.png" alt="afbeelding waar twee fonduepotten
                                      opstaan en de naam van het resaurant" />
            <img src="images/menu.jpg" alt="menu icoon voor mobiel surfen" />
            <ul id="mobilemenu">
                <li><a href="home.html">Home</a></li>
                <li><a href="menu.html">Menu</a></li>
                <li><a href="reserveren.html">Reserveren</a></li>
                <li><a href="contact.html">Contact</a></li>
            </ul>
        </section>
        <nav>
            <h2 class="structural">Menu</h2>
            <ul id="mainmenu">
                              <li><a href="home.html" id="selected">Home</a></li>
                              <li><a href="menu.html">Menu</a></li>
                              <li><a href="reserveren.html">Reserveren</a></li>
                              <li><a href="contact.html">Contact</a>
            </ul>
        </nav>
    </div>
</header>

这是我的 CSS:

#mobilemenu {
  list-style-type: none;
  position: absolute;
  z-index: 1;
  right: 1%;
  top: 76%;
  width: 40%;
  border-radius: 5rem;
  display: none;
}

#mobilemenu li a {
  line-height: 3rem;
  text-decoration: none;
  text-align: center;
  display: block;
  border: 0.1rem solid #381402;
  color: #ac0909;
  background-color: #dabd8b;
  -webkit-transition: all 1s;
  -moz-transition: all 1s;
  -ms-transition: all 1s;
  -o-transition: all 1s;
  transition: all 1s;
}

#mobilemenu li a:hover {
  color: #dabd8b;
  background-color: #ac0909;
}

header section {
  background-image: url("../images/zand.jpg");
  background-size: contain;
  border-radius: 5px;
  border: 0.25rem solid #f3deba;
  width: 90%;
  margin: 0 auto;
  margin-top: 2rem;
  margin-bottom: 1rem;
  position: relative;
}

header img:first-of-type {
  border-radius: 0.5rem;
  width: 80%;
  margin: 2%;
}

header img:last-of-type {
  float: right;
  margin-top: 1%;
  margin-right: 1%;
  width: 13%;
  border-radius: 5px;
  border: 0.25rem solid #f3deba;
}

header img:last-of-type:hover + #mobilemenu {
  display: block;
}

#mobilemenu:hover {
  display: block;
}

【问题讨论】:

  • 我觉得你的带有 display:none 的元素需要悬停在它上面才能出现,这有点奇怪。如果您希望在用户悬停在 clearfix 上时出现菜单,请尝试 .clearfix:hover > #mobilemenu{ display:block; }
  • 这是一个好技巧,但如果我将图像悬停,我只需要显示子菜单,而不是孔部分
  • .wrapper:hover > .clearfix > #mobilemenu{display:block}
  • 我真的觉得你不明白我的意思,我的子菜单只有在我将鼠标悬停在图像上方时才会出现:images/menu.jpg,如果我按照你说的那样做,它也会出现如果我将鼠标悬停在图像上方:images/kop.png
  • 这个怎么样:jsfiddle.net/pwWqL/1 我没发现问题。仅当第二张图片悬停在上方时才会出现

标签: html css hover submenu


【解决方案1】:

如果您在 IE 中进行测试,请务必正确关闭所有标签:

<li><a href="contact.html">Contact</a>

必须

<li><a href="contact.html">Contact</a></li>

【讨论】:

  • 那个在我粘贴这段代码时消失了,很抱歉
  • 您正在测试哪个浏览器.. 我只是用了一个小提琴,似乎可以按您的预期工作:jsfiddle.net/gomflo/BVSZt
  • 是的,但是如果您调整页面大小然后重试,则在刷新页面之前它不起作用
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-23
  • 1970-01-01
  • 1970-01-01
  • 2010-10-14
  • 2022-11-17
  • 1970-01-01
相关资源
最近更新 更多