变换css使菜单消失

时间:2017-06-10 02:29:55

标签: html css css3 transform

在我的下拉菜单中,我想添加变换css,这样当子菜单出现在悬停时会出现一种下翻效果。我已将以下css添加到.ht-main-navigation ul ul但是它只是让整个菜单消失了?任何人都可以提供任何解决方案吗?提前谢谢!

没有变换css的jsfiddle - https://jsfiddle.net/w1emxfm5/

jsfiddle with transform css - https://jsfiddle.net/n84u2xbL/

转换css

                        -webkit-transform: scale(1,0);
    -moz-transform: scale(1,0);
    transform: scale(1,0);
    -webkit-transform-origin: top;
    -moz-transform-origin: top;
    transform-origin: top;
    -webkit-transition: all .3s ease-in-out;
    -moz-transition: all .3s ease-in-out;

我的header.php

<?php
/**
 * The header for our theme.
 *
 * @package Total
 */

?>
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="profile" href="http://gmpg.org/xfn/11">
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>">

<?php wp_head(); ?>
</head>

<body <?php body_class(); ?>>
<div id="ht-page">
	<header id="ht-masthead" class="ht-site-header">
		<div class="ht-container ht-clearfix">
			<div id="ht-site-branding">
				<?php 
				if ( function_exists( 'has_custom_logo' ) && has_custom_logo() ) :
					the_custom_logo();
				else : 
					if ( is_front_page() ) : ?>
						<h1 class="ht-site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
					<?php else : ?>
						<p class="ht-site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></p>
					<?php endif; ?>
					<p class="ht-site-description"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'description' ); ?></a></p>
				<?php endif; ?>
			</div><!-- .site-branding -->

			<nav id="ht-site-navigation" class="ht-main-navigation">
				<div class="toggle-bar"><span></span></div>
				<?php 
				wp_nav_menu( array( 
					'theme_location' => 'primary', 
					'container_class' => 'ht-menu ht-clearfix' ,
					'menu_class' => 'ht-clearfix',
					'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
				) ); 
				?>
			</nav><!-- #ht-site-navigation -->
		</div>
	</header><!-- #ht-masthead -->

	<div id="ht-content" class="ht-site-content ht-clearfix">

我的css

/*--------------------------------------------------------------
## Header
--------------------------------------------------------------*/

#ht-masthead {
  background: #FFF;
  height: 70px;
  border-bottom: 1px solid #eee;
  z-index: 99;
  transition: height 0.3s ease;
  -moz-transition: height 0.3s ease;
  -webkit-transition: height 0.3s ease;
  position: fixed;
  text-align: center;
  width: 0 auto;
  margin-right: 38px;
  width: 100%;
}

.ht-sticky-header #ht-masthead {
  position: fixed;
  left: 0;
  right: 0;
}

.ht-sticky#ht-masthead {
  height: 74px;
}

.ht-sticky-header #ht-content {
  position: relative;
  z-index: 9;
  padding-top: 94px;
}

#ht-site-branding {
  float: left;
  width: 30%;
  transition: padding 0.3s ease;
  -moz-transition: padding 0.3s ease;
  -webkit-transition: padding 0.3s ease;
}

.ht-sticky #ht-site-branding {
  padding: 5px 0;
}

#ht-site-branding img {
  max-height: 60px;
  width: auto;
}

.ht-main-header {
  background: #f9f9f9;
  padding: 45px 0;
  margin-bottom: 25px;
}

.ht-main-title {
  margin: 0 0 15px;
  letter-spacing: 1px;
  font-weight: 400;
  text-transform: uppercase;
}

.ht-main-title:last-child {
  margin-bottom: 0;
}

.ht-site-title {
  font-family: 'futura_tbold';
  font-size: 24px;
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 6px;
  margin-left: 20px;
}

.ht-site-title a {
  text-decoration: none;
  color: #000;
}

.ht-site-title a:hover {
  text-decoration: none;
  color: #000;
}

.ht-site-description {
  color: #EEE;
  margin: 0;
  font-size: 15px;
  font-style: italic;
  line-height: 1;
}

.ht-site-description a {
  color: #333;
}

#total-breadcrumbs,
.woocommerce .woocommerce-breadcrumb {
  font-size: 15px;
  margin: 0;
  color: inherit;
}

.woocommerce .woocommerce-breadcrumb a,
#total-breadcrumbs a {
  color: #000;
}

.woocommerce .woocommerce-breadcrumb a:hover,
#total-breadcrumbs a:hover {
  color: #000;
}

.taxonomy-description,
.term-description {
  margin-bottom: 15px;
}

.taxonomy-description p:last-child,
.term-description p:last-child {
  margin-bottom: 0;
}


/*--------------------------------------------------------------
## General
--------------------------------------------------------------*/

.ht-section {
  padding: 60px 0;
  background: #FFF;
}

.ht-section-title-tagline {
  margin-bottom: 60px;
  text-align: center;
}

.ht-section-title {
  font-weight: 400;
  letter-spacing: 1px;
  text-transform: uppercase;
  font-size: 36px;
  width: 60%;
  margin: 0 auto 15px;
}

.ht-section-title:last-child {
  margin-bottom: 0;
}

.ht-section-tagline {
  font-size: 20px;
  width: 70%;
  margin: 0 auto;
}

#ht-page {
  width: 100% !important;
  margin: 0 auto;
  max-width: 100% !important;
  overflow: hidden !important;
}


/*--------------------------------------------------------------
## Menus
--------------------------------------------------------------*/

#ht-site-navigation {
  position: absolute;
  width: 100%;
  padding: 15px 0;
  transition: padding 0.3s ease;
  -moz-transition: padding 0.3s ease;
  -webkit-transition: padding 0.3s ease;
  float: right;
}

.ht-sticky #ht-site-navigation {
  padding: 17px 0;
}

.ht-main-navigation .ht-menu {}

.ht-main-navigation ul {
  list-style: none;
  margin: 0;
  padding-left: 0;
  display: inline-block;
  position: relative;
}

.ht-main-navigation li {
  float: left;
  margin-left: 30px;
}

.ht-main-navigation a {
  display: block;
  text-decoration: none;
  color: #000;
  text-transform: uppercase;
  font-size: 15px;
  font-family: 'Raleway', sans-serif;
  line-height: 36px;
  padding: 0 15px;
  font-weight: 600;
  letter-spacing: 2px;
  padding-bottom: 40px;
}

.ht-main-navigation ul ul {
  display: none;
  position: absolute;
  left: 0;
  top: 100%;
  background: #FFF;
  min-width: 200px;
 right:0;
  z-index: 999;
  padding: 8px;
  margin-top: 0px;
  box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.05);
    height:300px;
                            -webkit-transform: scale(1,0);
    -moz-transform: scale(1,0);
    transform: scale(1,0);
    -webkit-transform-origin: top;
    -moz-transform-origin: top;
    transform-origin: top;
    -webkit-transition: all .3s ease-in-out;
    -moz-transition: all .3s ease-in-out;
}

.ht-sticky .ht-main-navigation ul ul {
  margin-top: 17px;
}

.ht-main-navigation ul ul ul {
  left: 100%;
  top: 0;
  margin: 0 0 0 8px;
  border-top: 0;
}

.ht-sticky .ht-main-navigation ul ul ul {
  margin-top: 0;
}

.ht-main-navigation ul ul a {
  text-transform: none;
  font-weight: 400;
  color: #444;
  line-height: 1.5;
  padding: 10px 15px;
  font-size: 14px;
 text-align: left;
}

.ht-main-navigation ul ul li {
  float: none;
  margin: 0 0 5px;
}

.ht-main-navigation ul ul li:last-child {
  margin-bottom: 0;
}

.ht-main-navigation ul li:hover > ul {
  display: block;
}

.page-template-home-template .ht-main-navigation .current_page_item > a,
.page-template-home-template .ht-main-navigation .current-menu-item > a,
.page-template-home-template .ht-main-navigation .current_page_ancestor > a,
.home.blog .ht-main-navigation .current_page_item > a,
.home.blog .ht-main-navigation .current-menu-item > a,
.home.blog .ht-main-navigation .current_page_ancestor > a {
  background: none;
  color: inherit;
}

.ht-main-navigation li:hover > a,
.page-template-home-template .ht-main-navigation li:hover > a,
.home.blog .ht-main-navigation li:hover > a,
.ht-main-navigation .current_page_item > a,
.ht-main-navigation .current-menu-item > a,
.ht-main-navigation .current_page_ancestor > a,
.page-template-home-template .ht-main-navigation .current > a,
.home.blog .ht-main-navigation .current > a {
  color: #000;
  text-decoration: none;
}

.site-main .comment-navigation,
.site-main .posts-navigation,
.site-main .post-navigation {
  margin: 0 0 15px;
  overflow: hidden;
}

.comment-navigation .nav-previous,
.posts-navigation .nav-previous,
.post-navigation .nav-previous {
  float: left;
  width: 50%;
}

.comment-navigation .nav-next,
.posts-navigation .nav-next,
.post-navigation .nav-next {
  float: right;
  text-align: right;
  width: 50%;
}

2 个答案:

答案 0 :(得分:1)

由于您需要“向下翻转”效果,因此您只想转换scaleY()。您需要将scaleY(0)的初始值设置为默认状态,然后在悬停时转换为scaleY(1)。您还需要切换opacity而不是display: block/none来隐藏/显示菜单,因为您无法transition display属性,菜单只会隐藏/显示你正在切换display

/*--------------------------------------------------------------
## Header
--------------------------------------------------------------*/

#ht-masthead {
  background: #FFF;
  height: 70px;
  border-bottom: 1px solid #eee;
  z-index: 99;
  transition: height 0.3s ease;
  -moz-transition: height 0.3s ease;
  -webkit-transition: height 0.3s ease;
  position: fixed;
  text-align: center;
  width: 0 auto;
  margin-right: 38px;
  width: 100%;
}

.ht-sticky-header #ht-masthead {
  position: fixed;
  left: 0;
  right: 0;
}

.ht-sticky#ht-masthead {
  height: 74px;
}

.ht-sticky-header #ht-content {
  position: relative;
  z-index: 9;
  padding-top: 94px;
}

#ht-site-branding {
  float: left;
  width: 30%;
  transition: padding 0.3s ease;
  -moz-transition: padding 0.3s ease;
  -webkit-transition: padding 0.3s ease;
}

.ht-sticky #ht-site-branding {
  padding: 5px 0;
}

#ht-site-branding img {
  max-height: 60px;
  width: auto;
}

.ht-main-header {
  background: #f9f9f9;
  padding: 45px 0;
  margin-bottom: 25px;
}

.ht-main-title {
  margin: 0 0 15px;
  letter-spacing: 1px;
  font-weight: 400;
  text-transform: uppercase;
}

.ht-main-title:last-child {
  margin-bottom: 0;
}

.ht-site-title {
  font-family: 'futura_tbold';
  font-size: 24px;
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 6px;
  margin-left: 20px;
}

.ht-site-title a {
  text-decoration: none;
  color: #000;
}

.ht-site-title a:hover {
  text-decoration: none;
  color: #000;
}

.ht-site-description {
  color: #EEE;
  margin: 0;
  font-size: 15px;
  font-style: italic;
  line-height: 1;
}

.ht-site-description a {
  color: #333;
}

#total-breadcrumbs,
.woocommerce .woocommerce-breadcrumb {
  font-size: 15px;
  margin: 0;
  color: inherit;
}

.woocommerce .woocommerce-breadcrumb a,
#total-breadcrumbs a {
  color: #000;
}

.woocommerce .woocommerce-breadcrumb a:hover,
#total-breadcrumbs a:hover {
  color: #000;
}

.taxonomy-description,
.term-description {
  margin-bottom: 15px;
}

.taxonomy-description p:last-child,
.term-description p:last-child {
  margin-bottom: 0;
}


/*--------------------------------------------------------------
## General
--------------------------------------------------------------*/

.ht-section {
  padding: 60px 0;
  background: #FFF;
}

.ht-section-title-tagline {
  margin-bottom: 60px;
  text-align: center;
}

.ht-section-title {
  font-weight: 400;
  letter-spacing: 1px;
  text-transform: uppercase;
  font-size: 36px;
  width: 60%;
  margin: 0 auto 15px;
}

.ht-section-title:last-child {
  margin-bottom: 0;
}

.ht-section-tagline {
  font-size: 20px;
  width: 70%;
  margin: 0 auto;
}

#ht-page {
  width: 100% !important;
  margin: 0 auto;
  max-width: 100% !important;
  overflow: hidden !important;
}


/*--------------------------------------------------------------
## Menus
--------------------------------------------------------------*/

#ht-site-navigation {
  position: absolute;
  width: 100%;
  padding: 15px 0;
  transition: padding 0.3s ease;
  -moz-transition: padding 0.3s ease;
  -webkit-transition: padding 0.3s ease;
  float: right;
}

.ht-sticky #ht-site-navigation {
  padding: 17px 0;
}

.ht-main-navigation .ht-menu {}

.ht-main-navigation ul {
  list-style: none;
  margin: 0;
  padding-left: 0;
  display: inline-block;
  position: relative;
}

.ht-main-navigation li {
  float: left;
  margin-left: 30px;
}

.ht-main-navigation a {
  display: block;
  text-decoration: none;
  color: #000;
  text-transform: uppercase;
  font-size: 15px;
  font-family: 'Raleway', sans-serif;
  line-height: 36px;
  padding: 0 15px;
  font-weight: 600;
  letter-spacing: 2px;
  padding-bottom: 40px;
}

.ht-main-navigation ul ul {
  position: absolute;
  left: 0;
  top: 100%;
  background: #FFF;
  min-width: 200px;
  right: 0;
  z-index: 999;
  padding: 8px;
  margin-top: 0px;
  box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.05);
  height: 300px;
  transform: scaleY(0);
  -webkit-transform-origin: top;
  -moz-transform-origin: top;
  transform-origin: top;
  -webkit-transition: all .3s ease-in-out;
  -moz-transition: all .3s ease-in-out;
  opacity: 0;
}

.ht-sticky .ht-main-navigation ul ul {
  margin-top: 17px;
}

.ht-main-navigation ul ul ul {
  left: 100%;
  top: 0;
  margin: 0 0 0 8px;
  border-top: 0;
}

.ht-sticky .ht-main-navigation ul ul ul {
  margin-top: 0;
}

.ht-main-navigation ul ul a {
  text-transform: none;
  font-weight: 400;
  color: #444;
  line-height: 1.5;
  padding: 10px 15px;
  font-size: 14px;
  text-align: left;
}

.ht-main-navigation ul ul li {
  float: none;
  margin: 0 0 5px;
}

.ht-main-navigation ul ul li:last-child {
  margin-bottom: 0;
}

.ht-main-navigation ul li:hover > ul {
  opacity: 1;
  transform: scaleY(1);
}

.page-template-home-template .ht-main-navigation .current_page_item > a,
.page-template-home-template .ht-main-navigation .current-menu-item > a,
.page-template-home-template .ht-main-navigation .current_page_ancestor > a,
.home.blog .ht-main-navigation .current_page_item > a,
.home.blog .ht-main-navigation .current-menu-item > a,
.home.blog .ht-main-navigation .current_page_ancestor > a {
  background: none;
  color: inherit;
}

.ht-main-navigation li:hover > a,
.page-template-home-template .ht-main-navigation li:hover > a,
.home.blog .ht-main-navigation li:hover > a,
.ht-main-navigation .current_page_item > a,
.ht-main-navigation .current-menu-item > a,
.ht-main-navigation .current_page_ancestor > a,
.page-template-home-template .ht-main-navigation .current > a,
.home.blog .ht-main-navigation .current > a {
  color: #000;
  text-decoration: none;
}

.site-main .comment-navigation,
.site-main .posts-navigation,
.site-main .post-navigation {
  margin: 0 0 15px;
  overflow: hidden;
}

.comment-navigation .nav-previous,
.posts-navigation .nav-previous,
.post-navigation .nav-previous {
  float: left;
  width: 50%;
}

.comment-navigation .nav-next,
.posts-navigation .nav-next,
.post-navigation .nav-next {
  float: right;
  text-align: right;
  width: 50%;
}
<nav id="ht-site-navigation" class="ht-main-navigation">
  <div class="toggle-bar"><span></span></div>
  <div class="ht-menu ht-clearfix">
    <ul id="menu-primary-menu-links" class="ht-clearfix">
      <li id="menu-item-129" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-129"><a href="http://localhost:8888/wordpress/fashion/">item 1</a>
        <ul class="sub-menu">
          <li id="menu-item-139" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-139"><a href="http://localhost:8888/wordpress/fashion/fashion-news/">sub item 1</a></li>
          <li id="menu-item-140" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-140"><a href="http://localhost:8888/wordpress/fashion/my-looks/">sub item 2</a></li>
          <li id="menu-item-138" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-138"><a href="http://localhost:8888/wordpress/fashion/outfit-ideas/">sub item 3</a></li>
          <li id="menu-item-137" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-137"><a href="http://localhost:8888/wordpress/fashion/shopping/">sub item 4</a></li>
        </ul>
      </li>
      <li id="menu-item-128" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-128"><a href="http://localhost:8888/wordpress/beauty/">item 2</a>
        <ul class="sub-menu">
          <li id="menu-item-142" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-142"><a href="http://localhost:8888/wordpress/beauty/hair/">sub item 1</a></li>
          <li id="menu-item-143" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-143"><a href="http://localhost:8888/wordpress/beauty/makeup/">sub item 2</a></li>
          <li id="menu-item-141" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-141"><a href="http://localhost:8888/wordpress/beauty/skincare/">sub item 3</a></li>
        </ul>
      </li>
      <li id="menu-item-132" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-132"><a href="http://localhost:8888/wordpress/living/">item 3</a></li>
      <li id="menu-item-130" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-130"><a href="http://localhost:8888/wordpress/wellness/">item 4</a></li>
      <li id="menu-item-759" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-759"><a href="http://localhost:8888/wordpress/travel/">item 5</a></li>
      <li id="menu-item-135" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-135"><a href="http://localhost:8888/wordpress/video/">item6</a></li>
      <li id="menu-item-133" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-133"><a href="http://localhost:8888/wordpress/shop/">item 7</a>
        <ul class="sub-menu">
          <li id="menu-item-150" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-150"><a href="http://localhost:8888/wordpress/shop/my-closet/">sub item 1</a></li>
          <li id="menu-item-149" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-149"><a href="http://localhost:8888/wordpress/shop/my-picks/">sub item 2</a></li>
          <li id="menu-item-148" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-148"><a href="http://localhost:8888/wordpress/shop/instagram/">sub item 3</a></li>
          <li id="menu-item-147" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-147"><a href="http://localhost:8888/wordpress/shop/snapchat/">sub item 4</a></li>
        </ul>
      </li>
      <li id="menu-item-509" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-509"><a href="http://localhost:8888/wordpress/more/">item 8</a>
        <ul class="sub-menu">
          <li id="menu-item-512" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-512"><a href="http://localhost:8888/wordpress/contact/">sub item 1</a></li>
          <li id="menu-item-510" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-510"><a href="http://localhost:8888/wordpress/about/">sub item 2</a></li>
          <li id="menu-item-513" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-513"><a href="http://localhost:8888/wordpress/faq/">sub item 3</a></li>
          <li id="menu-item-511" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-511"><a href="http://localhost:8888/wordpress/archive/">sub item 4</a></li>
        </ul>
      </li>
    </ul>
  </div>
</nav>

答案 1 :(得分:0)

你必须设置.ht-main-navigation ul ul {display:block;变换:scale(0); }

悬停CSS .ht-main-navigation ul li:hover&gt; ul {display:block;变换:规模(1); }