Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="menu">
    <!--   第一組清單   -->
    <div class="item">
        <div class="main">今日總覽</div>
        <div class="sub">
            <ul>
                <li>今日最新</li>
                <li>熱門排行</li>
                <li>特別企劃</li>
            </ul>
        </div>
    </div>
    <!--   第二組清單   -->
    <div class="item">
        <div class="main">成功者故事</div>
        <div class="sub"></div>
    </div>
    <!--   第三組清單   -->
    <div class="item">
        <div class="main">財經</div>
        <div class="sub">
            <ul>
                <li>產業動態</li>
                <li>趨勢報導</li>
                <li>地產風雲</li>
                <li>投資焦點</li>
                <li>個人理財</li>
            </ul>
        </div>
    </div>
    <!--   第四組清單   -->
    <div class="item">
        <div class="main">時事</div>
        <div class="sub">
            <ul>
                <li>國際</li>
                <li>兩岸</li>
                <li>新聞</li>
            </ul>
        </div>
    </div>
    <!--   第五組清單   -->
    <div class="item">
        <div class="main">職場力</div>
        <div class="sub">
            <ul>
                <li>經營創業</li>
                <li>管理新法</li>
                <li>職場修練</li>
                <li>心靈成長</li>
            </ul>
        </div>
    </div>
</div>
              
            
!

CSS

              
                *{
    margin: 0;
    padding: 0;
}
#menu{
/*     width: 300px; */
    margin: 0 auto;
}
.item{
    float: left;
}
.main{
    background-color: #e33535;
    color: #FFF;
    font-family: "微軟正黑體";
    font-weight: bold;
    font-size: 20px;
    cursor: pointer;
    text-align: center;
    height: 35px;
    line-height: 35px;
    width: 100px;
}
.main:hover{
    background-color: #aaa;
}
.sub{
    background-color: #4d4949;
    color: #FFF;
    font-family: "微軟正黑體";
    text-align: center;
    font-weight: bold;
    width: 100px;
}
.sub li{
    height: 30px;
    line-height: 30px;
    border-bottom: 1px solid #777;
}

              
            
!

JS

              
                $(document).ready(function() {
    var oldtext = ['今日總覽', '成功者故事', '財經', '時事', '職場力'];
    var newtext = ['Today', 'Success', 'Business', 'News', 'Career']

    //  讓 #menu 的寬度自動根據 main 的數量而變
    $("#menu").css("width", $(".main").length * 100)
        //  一進入畫面時收合選單
    $(".sub").slideUp(0);

    for (i = 0; i < $(".main").length; i++) {
        //  點選按扭時收合或展開選單
        $(".main:eq(" + i + ")").on("mouseover", {
            id: i
        }, function(e) {
            n = e.data.id
            $(".sub:eq(" + n + ")").slideToggle()
            $(".sub:not(:eq(" + n + "))").slideUp()
            $(".main:eq(" + n + ")").text(newtext[n])
        })
        $(".main:eq(" + i + ")").on("mouseleave", {
            id: i
        }, function(e) {
            n = e.data.id
            $(".main:eq(" + n + ")").text(oldtext[n])
            $(".sub").stop();
        })
    }
})
              
            
!
999px

Console