如何更改megamenu中的子菜单对齐方式

时间:2015-06-17 18:51:22

标签: html css menu

我正在制作一个大型菜单。我试图在菜单选项卡下创建一个子菜单。第一个图像文件是子菜单的css部分。 enter image description here

此文件显示子菜单的html代码。 enter image description here

第三个图像文件是输出。我尝试在并排排列的产品部分下生成子菜单视图,但结果很少。 enter image description here 带图像的子菜单很好但我只面对产品下的子菜单问题。

  Here is the link of jsfiddle file - 
       `https://jsfiddle.net/chintu/eqx60spx/`

2 个答案:

答案 0 :(得分:1)

****************************新邮件***************** ***********

请忽略旧的帖子更改,我想我找到了解决方案:

.dropdown_5columns .col_1 {
  width:550px;
}

#menu li .dropdown_5columns #submenu li {
float: left;
}

****************************旧帖子***************** ***********

我做了那2次更改。

/*.col_1 {width:130px;}*/ I REMOVED THIS WIDTH.
/*#menu li ul li {float:left;}*/ I HAVE SET THIS ONE TO FLOAT LEFT.

我的回答有用吗?



<!--[if IE 6]>
<style>
body {behavior: url("csshover3.htc");}
#menu li .drop {background:url("img/drop.gif") no-repeat right 8px; 
</style>
<![endif]-->
	<style type="text/css">
	body, ul, li {
    font-size:14px; 
    font-family:Arial, Helvetica, sans-serif;
    line-height:21px;
    text-align:left;
}
 
/* Navigation Bar */
 
#menu {
    list-style:none;
    margin:0px;
    height:50px;
    padding:0px;
    width: 100%;
 }
 
#menu li {
    float:left;
    text-align:center;
    position:relative;
    padding: 4px 10px 4px 10px;
    margin-right:30px;
    margin-top:7px;
    border:none;
}

#submenu li {
    float:left;
    text-align:center;
    position:inline-block;
    display: block;
    padding: 4px 10px 4px 10px;
    margin-right: 30px;
    margin-top: 10px;
    border-right: 1px solid #000000;
}

#menu li:hover {
    /*border: 1px solid #777777; */
    padding: 4px 9px 4px 9px;
     
    /* Background color and gradients 
     
    background: #F4F4F4;
    background: -moz-linear-gradient(top, #F4F4F4, #EEEEEE);
    background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#F4F4F4), to(#EEEEEE));
     
    /* Rounded corners */
     
    -moz-border-radius: 5px 5px 0px 0px;
    -webkit-border-radius: 5px 5px 0px 0px;
    border-radius: 5px 5px 0px 0px;
}
 
#menu li a {
    font-family:Arial, Helvetica, sans-serif;
    font-size:16px; 
    color: #000000;
    display:block;
    outline:0;
    text-decoration:none;
    font-weight: bold;
}
 
#menu li:hover a {
    color:#161616;
    text-shadow: 1px 1px 1px #FFFFFF;
}
#menu li .drop {
    padding-right:21px;
    background:url("img/drop.png") no-repeat right 8px;
}
#menu li:hover .drop {
    background:url("img/drop.png") no-repeat right 7px;
}
 
/* Drop Down */
 
.dropdown_1column, 
.dropdown_2columns, 
.dropdown_3columns, 
.dropdown_4columns,
.dropdown_5columns {
    margin:4px auto;
    float:left;
    position:absolute;
    left:-999em; /* Hides the drop down */
    text-align:left;
    padding:10px 5px 10px 5px;
    border:1px solid #777777;
    border-top:none;
     
    /* Gradient background  */
    background:#ffffff;
    background: -moz-linear-gradient(top, #ffffff, #ffffff);
    background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#ffffff), to(#ffffff));

    /* Rounded Corners 
    -moz-border-radius: 0px 5px 5px 5px;
    -webkit-border-radius: 0px 5px 5px 5px;
    border-radius: 0px 5px 5px 5px;*/
}
 
.dropdown_1column {width: 200px;}
.dropdown_2columns {width: 280px;}
.dropdown_3columns {width: 360px;}
.dropdown_4columns {width: 560px;}
.dropdown_5columns {width: 560px;}
 
#menu li:hover .dropdown_1column, 
#menu li:hover .dropdown_2columns, 
#menu li:hover .dropdown_3columns,
#menu li:hover .dropdown_4columns,
#menu li:hover .dropdown_5columns {
    left:-1px;
    top:auto;
}
 
/* Columns */
 
.col_1,
.col_2,
.col_3,
.col_4,
.col_5 {
    display:inline;
    float: left;
    position: relative;
    margin-left: 10px;
    margin-right: 10px;
}
.col_1 {width:130px;}
.col_2 {width:270px;}
.col_3 {width:410px;}
.col_4 {width:550px;}
.col_5 {width:550px;}
 
/* Right alignment */
 
#menu .menu_right {
    float:right;
    margin-right:0px;
}
#menu li .align_right {
    /* Rounded Corners */
    -moz-border-radius: 5px 0px 5px 5px;
    -webkit-border-radius: 5px 0px 5px 5px;
    border-radius: 5px 0px 5px 5px;
}
#menu li:hover .align_right {
    left:auto;
    right:-1px;
    top:auto;
}
 
/* Drop Down Content Stylings */
 
#menu p, #menu h2, #menu h3, #menu ul li {
    font-family:Arial, Helvetica, sans-serif;
    line-height:21px;
    font-size:12px;
    text-align:left;
    text-shadow: 1px 1px 1px #FFFFFF;
}
#menu h2 {
    font-size:21px;
    font-weight:400;
    letter-spacing:-1px;
    margin:7px 0 14px 0;
    padding-bottom:14px;
    border-bottom:1px solid #666666;
}
#menu h3 {
    font-size:14px;
    margin:7px 0 14px 0;
    padding-bottom:7px;
    border-bottom:1px solid #888888;
}
#menu p {
    line-height:18px;
    margin:0 0 10px 0;
}
 
#menu li:hover div a {
    font-size:12px;
    color:#015b86;
}
#menu li:hover div a:hover {
    color:#029feb;
}
.strong {
    font-weight:bold;
}
.italic {
    font-style:italic;
}
.imgshadow {
    background:#FFFFFF;
    padding:4px;
    border:1px solid #777777;
    margin-top:5px;
    -moz-box-shadow:0px 0px 5px #666666;
    -webkit-box-shadow:0px 0px 5px #666666;
    box-shadow:0px 0px 5px #666666;
}
.img_left { /* Image sticks to the left */
    width:auto;
    float:left;
    margin:5px 15px 5px 5px;
}
/*#menu li .black_box {
    background-color:#333333;
    color: #eeeeee;
    text-shadow: 1px 1px 1px #000;
    padding:4px 6px 4px 6px;
 
     Rounded Corners
    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
    border-radius: 5px;
 
    /* Shadow 
    -webkit-box-shadow:inset 0 0 3px #000000;
    -moz-box-shadow:inset 0 0 3px #000000;
    box-shadow:inset 0 0 3px #000000;
} */
#menu li ul {
    list-style:none;
    padding:0;
    margin:0 0 12px 0;
}
#menu li ul li {
    font-size:12px;
    line-height:24px;
    position:relative;
    text-shadow: 1px 1px 1px #ffffff;
    padding:0;
    margin:0;
    float:none;
    text-align:left;
    width:130px;
}
#menu li ul li:hover {
    background:none;
    border:none;
    padding:0;
    margin:0;
}
#menu li .greybox li {
    background:#F4F4F4;
    border:1px solid #bbbbbb;
    margin:0px 0px 4px 0px;
    padding:4px 6px 4px 6px;
    width:116px;
 
    /* Rounded Corners */
    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
    border-radius: 5px;
}
#menu li .greybox li:hover {
    background:#ffffff;
    border:1px solid #aaaaaa;
    padding:4px 6px 4px 6px;
    margin:0px 0px 4px 0px;
}

.dropdown_5columns .col_1 {
  width:550px;
}

#menu li .dropdown_5columns #submenu li {
float: left;
}
&#13;
<ul id="menu">
     
    <li><a href="#" class="drop">Home</a><!-- Begin Home Item -->
    	<div class="dropdown_2columns"><!-- Begin 2 columns container -->
     		<div class="col_2">
            <h2>Welcome !</h2>
            	</div>
                <div class="col_2">
                <p>WELCOME to <i>Simfa</i> Scientific Solutions</p>             
                <p>We are glad to meet you here in virtually</p>             
     		       </div>
                   	<div class="col_2">
       		         <h2>Our Scientific Supplies behold</h2>
            	   	</div>
       	            <div class="col_1">
    	            <img src="img/browsers.png" width="125" height="48" alt="" />
    	            <img src="img/browsers.png" width="125" height="48" alt="" />
    	            <img src="img/browsers.png" width="125" height="48" alt="" />
    	            <img src="img/browsers.png" width="125" height="48" alt="" />
       		 	    </div>
                   	<div class="col_1">
                	<p>FumeHoods (<a href="#">Mott</a> & <a href="#">Laborabue</a>)</p>
                	<p>Furniture (<a href="#">Mott</a> & <a href="#">Laborabue</a>)</p>
            		</div>  
        </div><!-- End 2 columns container -->
    </li><!-- End Home Item -->
 
    <li><a href="#" class="drop">Products</a><!-- Begin 5 columns Item -->
        <div class="dropdown_5columns"><!-- Begin 5 columns container -->
            <div class="col_1">
                <ul id="submenu">
                <li>FumeHoods
                	<a href="#">Mott</a>
                	<a href="#">Laborabue</a>
                </li>
                <li>Furniture
                	<a href="#">Mott</a>
                	<a href="#">Laborabue</a></li>
                <li>Mott
                	<a href="#">Mott</a>
                	<a href="#">Laborabue</a>
                </li>
                <li>Laborabue
                	<a href="#">Mott</a>
                	<a href="#">Laborabue</a>
                </li></ul>
            <div class="col_5">
                <h2></h2>
            </div>
            <div class="col_3">
            	<a href="#">Project Gallery</a>
                <img src="img/01.jpg" width="70" height="70" class="img_left imgshadow" alt="" />
         		<a href="#">Product Gallery</a>
                <img src="img/02.jpg" width="70" height="70" class="img_left imgshadow" alt="" />
                <a href="#">Reference Projects</a>
                <img src="img/01.jpg" width="70" height="70" class="img_left imgshadow" alt="" />
                <a href="#">Partners & Assosciates</a> 
                <img src="img/02.jpg" width="100" height="70" class="img_left imgshadow" alt="" />
                
            </div>
        </div><!-- End 5 columns container -->
    </li><!-- End 5 columns Item -->
    </li><!-- End 3 columns Item --> 
</ul>
</body>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

如果您删除&#34; col_1&#34;来自父div的类将水平对齐列表项。那是你想要完成的吗?或者您可以将其更改为&#34; col_5&#34;或者比单列宽的东西。

enter image description here

&#13;
&#13;
<div class="dropdown_5columns">
  <div <!-- REMOVE THIS class="col_1" or change to wider column like "col_5" --> >
    <ul id="submenu"></ul>
    <div class="col_5">...</div>
    <div class="col_3">...</div>
  </div>
</div>
&#13;
&#13;
&#13;

我还建议将链接和图像对包装在像DIV这样的容器元素中,或者可能包含在列表项中。然后,您可以将css应用于这些容器以获得更好的对齐结果。

enter image description here

&#13;
&#13;
.menu-gallery > div {
    display:inline-block;
    margin:5px;
    padding:5px;
}
&#13;
<div class="menu-gallery">
  <div>
    <a href="#">Project Gallery</a>
    <img src="img/01.jpg" width="70" height="70" class="img_left imgshadow" alt="" />
  </div>
  <div>
    <a href="#">Product Gallery</a>
    <img src="img/02.jpg" width="70" height="70" class="img_left imgshadow" alt="" />
  </div>
  <div>
    <a href="#">Reference Projects</a>
    <img src="img/01.jpg" width="70" height="70" class="img_left imgshadow" alt="" />
  </div>
  <div>
    <a href="#">Partners & Assosciates</a> 
    <img src="img/02.jpg" width="100" height="70" class="img_left imgshadow" alt="" />
  </div>
</div>
&#13;
&#13;
&#13;