DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
  1. DZone
  2. Coding
  3. Languages
  4. Create a Shiny and Bright CSS3 Menu Bar

Create a Shiny and Bright CSS3 Menu Bar

Andrey Prikaznov user avatar by
Andrey Prikaznov
·
Feb. 14, 12 · Interview
Like (0)
Save
Tweet
Share
11.70K Views

Join the DZone community and get the full member experience.

Join For Free

in our new tutorial we’ll create a new nice multicolor and crossbrowser css3 menu with sliding (i use css3 transitions) and pure css3 color switcher. this is a ul-li-based menu.


here are samples and downloadable package:

live demo | download in package


ok, download the example files and let's start coding!

step 1. html

as usual, we start with the html. here is the full html code of our menu. as you can see – this is a multilevel menu built on ul-li elements. but, it is a little unusual. i don’t wrap submenus into their  own ul element: i am going to hide them, and display if necessary.

index.html

<!doctype html>
<html lang="en" >
    <head>
        <meta charset="utf-8" />
        <title>css3 multicolor menu | script tutorials</title>
        <link href="css/styles.css" rel="stylesheet" type="text/css" />
        <link href="css/menu.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        <header>
            <h2>css3 multicolor menu</h2>
            <a href="http://www.script-tutorials.com/css3-multicolor-menu/" class="stuts">back to original tutorial on <span>script tutorials</span></a>
        </header>
        <div class="container">

            <span id="red"></span>
            <span id="orange"></span>
            <span id="pink"></span>
            <span id="green"></span>
            <span id="blue"></span>
            <span id="indigo"></span>
            <span id="violet"></span>
            <span id="grey"></span>

            <div class="colorscheme">
                <a href="#red" class="red"></a>
                <a href="#orange" class="orange"></a>
                <a href="#pink" class="pink"></a>
                <a href="#green" class="green"></a>
                <a href="#blue" class="blue"></a>
                <a href="#indigo" class="indigo"></a>
                <a href="#violet" class="violet"></a>
                <a href="#grey" class="grey"></a>
            </div>

            <ul id="nav">
                <li><a href="http://www.script-tutorials.com/">home</a></li>
                <li><a class="hsubs" href="#">menu 1</a>
                    <ul class="subs">
                        <li><a href="#">submenu 1</a></li>
                        <li><a href="#">submenu 2</a></li>
                        <li><a href="#">submenu 3</a></li>
                        <li><a href="#">submenu 4</a></li>
                        <li><a href="#">submenu 5</a></li>
                    </ul>
                </li>
                <li><a class="hsubs" href="#">menu 2</a>
                    <ul class="subs">
                        <li><a href="#">submenu 2-1</a></li>
                        <li><a href="#">submenu 2-2</a></li>
                        <li><a href="#">submenu 2-3</a></li>
                        <li><a href="#">submenu 2-4</a></li>
                        <li><a href="#">submenu 2-5</a></li>
                        <li><a href="#">submenu 2-6</a></li>
                        <li><a href="#">submenu 2-7</a></li>
                        <li><a href="#">submenu 2-8</a></li>
                    </ul>
                </li>
                <li><a class="hsubs" href="#">menu 3</a>
                    <ul class="subs">
                        <li><a href="#">submenu 3-1</a></li>
                        <li><a href="#">submenu 3-2</a></li>
                        <li><a href="#">submenu 3-3</a></li>
                        <li><a href="#">submenu 3-4</a></li>
                        <li><a href="#">submenu 3-5</a></li>
                    </ul>
                </li>
                <li><a href="#">menu 4</a></li>
                <li><a href="#">menu 5</a></li>
                <li><a href="#">menu 6</a></li>
                <li><a href="http://www.script-tutorials.com/css3-multicolor-menu/">back</a></li>
            </ul>

        </div>
    </body>
</html>

step 2. css

here are the css styles of our menu. maybe you’ve noticed – that in our html – i have two css files: layout.css and menu.css. the first file (layout.css) contain the styles of our demo page. we will not publish these styles in this article, but if you wish – you can find these styles in our package.

css/menu.css

#nav,#nav ul {
    list-style: none outside none;
    margin: 0;
    padding: 0;
}
#nav {
    background-color: #000000;
    border-radius: 5px 5px 5px 5px;
    box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.5);
    display: table;
    padding: 10px;
    position: relative;
}
#nav ul {
    background-color: red;
    border:1px solid red;
    border-radius: 0 5px 5px 5px;
    border-width: 0 1px 1px;
    box-shadow: 0 5px 5px rgba(0, 0, 0, 0.5);
    left: -9999px;
    overflow: hidden;
    padding: 20px 0 10px;
    position: absolute;
    top: -9999px;

    -moz-transform: scaley(0);
    -ms-transform: scaley(0);
    -o-transform: scaley(0);
    -webkit-transform: scaley(0);
    transform: scaley(0);

    -moz-transform-origin: 0 0;
    -ms-transform-origin: 0 0;
    -o-transform-origin: 0 0;
    -webkit-transform-origin: 0 0;
    transform-origin: 0 0;

    -moz-transition: -moz-transform 0.1s linear;
    -ms-transition: -ms-transform 0.1s linear;
    -o-transition: -o-transform 0.1s linear;
    -webkit-transition: -webkit-transform 0.1s linear;
    transition: transform 0.1s linear;
}
#nav li {
    float: left;
    position: relative;
}
#nav li a {
    color: #ffffff;
    display: block;
    font-size: 16px;
    padding: 7px 20px;
    text-decoration: none;
}
#nav li:hover > a {
    background-color: red;
    border-radius: 5px 5px 5px 5px;
    color: #ffffff;
}
#nav li:hover > a.hsubs {
    border-radius: 5px 5px 0 0;
}
#nav li:hover ul.subs {
    left: 0;
    top: 34px;
    width: 180px;

    -moz-transform: scaley(1);
    -ms-transform: scaley(1);
    -o-transform: scaley(1);
    -webkit-transform: scaley(1);
}
#nav ul li {
    width: 100%;
}
#nav ul li:hover > a {
    background-color: #222222 !important;
    border-radius: 5px 5px 5px 5px;
}

/* colors */
.colorscheme {
    height: 32px;
    list-style: none outside none;
    margin: 0 auto 25px;
    width: 320px;
}
.colorscheme a {
    cursor: pointer;
    float: left;
    height: 30px;
    margin: 0 5px;
    width: 30px;
}
.colorscheme .red {
    background-color: red;
}
.colorscheme .orange {
    background-color: orange;
}
.colorscheme .pink {
    background-color: pink;
}
.colorscheme .green {
    background-color: green;
}
.colorscheme .blue {
    background-color: blue;
}
.colorscheme .indigo {
    background-color: indigo;
}
.colorscheme .violet {
    background-color: violet;
}
.colorscheme .grey {
    background-color: grey;
}

#red:target ~ #nav ul {
    background-color: red;
    border: 1px solid red;
}
#orange:target ~ #nav ul {
    background-color: orange;
    border: 1px solid orange;
}
#pink:target ~ #nav ul {
    background-color: pink;
    border: 1px solid pink;
}
#green:target ~ #nav ul {
    background-color: green;
    border: 1px solid green;
}
#blue:target ~ #nav ul {
    background-color: blue;
    border: 1px solid blue;
}
#indigo:target ~ #nav ul {
    background-color: indigo;
    border: 1px solid indigo;
}
#violet:target ~ #nav ul {
    background-color: violet;
    border: 1px solid violet;
}
#grey:target ~ #nav ul {
    background-color: grey;
    border: 1px solid grey;
}

#red:target ~ #nav li:hover > a {
    background-color: red;
}
#orange:target ~ #nav li:hover > a {
    background-color: orange;
}
#pink:target ~ #nav li:hover > a {
    background-color: pink;
}
#green:target ~ #nav li:hover > a {
    background-color: green;
}
#blue:target ~ #nav li:hover > a {
    background-color: blue;
}
#indigo:target ~ #nav li:hover > a {
    background-color: indigo;
}
#violet:target ~ #nav li:hover > a {
    background-color: violet;
}
#grey:target ~ #nav li:hover > a {
    background-color: grey;
}

live demo

download in package


conclusion

hope you enjoyed new menu, don’t forget to tell us thanks and leave a comment :) good luck!

source: http://www.script-tutorials.com/css3-multicolor-menu/

CSS

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Introduction to Automation Testing Strategies for Microservices
  • Use Golang for Data Processing With Amazon Kinesis and AWS Lambda
  • GitLab vs Jenkins: Which Is the Best CI/CD Tool?
  • Spring Cloud

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: