html - 帮助垂直 CSS 菜单

标签 html menu css

我正在努力设计一个像这样的垂直 CSS 菜单。 on the right of this site
alt text

.我有两个问题。

  1. 如何在菜单项中添加图像。

  2. 如何制作顶部和底部所有元素的边界半径 不是每个元素

这是我的代码

<!DOCTYPE html>

<html lang="en">
<head>
    <meta charset="utf-8">
    <title>CSS3 Buttons</title>
    <style>


    .button {
     width: 400px;
     height: 100px;
     line-height: 100px;
     color: #C0C0C0; 
     text-decoration: none;
     font-size: 50px;
     font-family: helvetica, arial;
     font-weight: bold;
     display: block;
     text-align: center;
     position: relative;
     padding-bottom:1px;

     /* BACKGROUND GRADIENTS */
     background: #F5F3F4;



     /* BORDER RADIUS */
     /* -moz-border-radius: 10px;
     -webkit-border-radius: 10px;
     border-radius: 10px; */


     /* TEXT SHADOW */

     text-shadow: 1px 1px 1px black;

     /* BOX SHADOW */
     -moz-box-shadow: 0 1px 3px black;
     -webkit-box-shadow: 0 1px 3px black;
     box-shadow: 0 1px 3px black;
    }

    /* WHILE HOVERED */
    .button:hover {
         color: #A8A8A8;
        -moz-box-shadow: 0 2px 6px black;
        -webkit-box-shadow: 0 2px 6px black;

    }

    /* WHILE BEING CLICKED */
    .button:active {
        -moz-box-shadow: 0 2px 6px black;
        -webkit-box-shadow: 0 2px 6px black;
    }


    </style>
</head>
<body>
     <a href="#" class="button"> Profile  </a>
     <a href="#" class="button">  Privacy </a>
     <a href="#" class="button"> Services </a>
     <a href="#" class="button"> Avatar </a>
     <a href="#" class="button"> Language </a>
</body>
</html> 

最佳答案

首先,您应该调整您的 html 以包含如下列表(注意我还添加了 id 属性):

<ul>
 <li><a href="#" class="button" id="profile-btn"> Profile  </a></li>
 <li><a href="#" class="button" id="privacy-btn">  Privacy </a></li>
 <li><a href="#" class="button" id="services-btn"> Services </a></li>
 <li><a href="#" class="button" id="avatar-btn"> Avatar </a></li>
 <li><a href="#" class="button" id="language-btn"> Language </a></li>
</ul>

然后,使用以下 css 添加图像:

 a#profile-btn {
   background-image:url(/image_path/profile.png);
 }
 a#privacy-btn {
   background-image:url(/image_path/privacy.png);
 }
 a#services-btn {
   background-image:url(/image_path/services.png);
 }
 a#avatar-btn {
   background-image:url(/image_path/avatar.png);
 }
 a#language-btn {
   background-image:url(/image_path/language.png);
 }

最后是圆形边框:

ul {list-style:none;}
ul li:first-child a {
  -moz-border-radius-topleft: 25px;
  -moz-border-radius-topright: 25px;
  -webkit-border-radius-topleft:25px;
  -webkit-border-radius-topright:25px;
  border-top-right-radius:25px;
  border-top-left-radius:25px;
 }
 ul li:last-child a {
   -moz-border-radius-bottomleft: 25px;
   -moz-border-radius-bottomright: 25px;
   -webkit-border-radius-bottomleft:25px;
   -webkit-border-radius-bottomright:25px;
   border-bottom-right-radius:25px;
   border-bottom-left-radius:25px;
 }

编辑:此代码旨在与您提供的所有其他 CSS 一起使用,只要您按所示替换 HTML。

关于html - 帮助垂直 CSS 菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4418763/

相关文章:

javascript - 为什么你会在 html 和 javaScript 的主体中调用一个函数,例如函数(c)?

html - 在兼容模式下尝试将鼠标悬停在 IE 8 上时 CSS 菜单消失

html - 如何使图像 slider 根据窗口调整大小

html - 如何创建具有尖边的 div?

javascript - 如何为右键单击的每个汉字字符显示汉字笔划顺序工具提示?

html - 不同的列表项

html - 创建带有描述的菜单项

css - 有没有办法创建一个带有渐变和圆 Angular 边框的按钮(或 div)?

javascript - 放置区框外的表单字段

html - 如何使表格中的文本向左溢出?