Home Web Front-end HTML Tutorial div css js creates HTML tab control_html/css_WEB-ITnose

div css js creates HTML tab control_html/css_WEB-ITnose

Jun 24, 2016 pm 12:29 PM

The code is as follows:

< html >
     < head >
         < title > tab控件

         < style  type ="text/css" >
            body{}{
                text-align:center;
            }

            div.normal{}{
                font-size:12px;
                font-family:宋体;
            }

            div#tab_control{}{
                position:relative;
                margin:0 auto;
                border:1px solid lightblue;
                width:300px;
            }

            /**//** Define the style of the tab tab*/
            div#tab_control ul{}{
                list-style:none;
                margin:0px 1px 0px 1px;
                padding:0px 0px 20px 0px;
                line-height:0px;
                border-bottom:1px solid gray;
            }
            
            div#tab_control ul li{}{
                float:left;
                overflow:hidden;
                display:inline-block;
                color:black;
                background:#d0d0d0;
                cursor:pointer;
                width:90px;
                text-align:center;
                line-height:19px;
                margin:0px 1px 0px 1px;
                border:1px solid gray;
                padding:0px;
                font-family:宋体;
                font-size:12px;
            }
            
            div#tab_control div.tab_content{}{
                display:block ;
                overflow:hidden;
                border:1px solid gray;
                border-top:0px;
                padding:0px 0px 0px 0px;
                margin:0px 1px 1px 1px;
                clear:both;
                background:white;
            }
        
        
         < script  language ="javascript" >
            window.onload = function(){
                if(window.document.all){
                    window.attachEvent("onload", windowOnload);
                } else {
                    window.addEventListener("load", windowOnload(), false);
                }
            }
            //页面加载时需要执行的方法
            function windowOnload(){
                var li_1 = document.getElementById("li_1");
                showTab(li_1, li_1.className);
            }
            
            //显示标签页
            function showTab(liobj, liname){
                liobj.style.cssText = "background:white; border-bottom:1px solid white";
                
                var tab_content = document.getElementById("tab_content");
                var li_1 = document.getElementById("li_1");
                var li_2 = document.getElementById("li_2");
                if(liname == "li_1"){
                    li_2.style.cssText = "background:#E0E0E0; border-bottom:1px solid gray";

                    tab_content.innerHTML = 
                        "

";    
                    tab_content.innerHTML += "
姓名:
密码:
";
                }else if(liname == "li_2"){
                    li_1.style.cssText = "background:#E0E0E0; border-bottom:1px solid gray";

                    tab_content.innerHTML = 
                        "";    
                    tab_content.innerHTML += "
企业名:
密码:
";
                }
            }
        
    
     < body >
         < div  id ="tab_control" >
             < ul  id ="tab_tag" >
                 < li  id ="li_1"  class ="li_1"  onmousedown ="javascript:showTab(this, this.className);"   > 个人用户登录
                 < li  id ="li_2"  class ="li_2"  onmousedown ="javascript:showTab(this, this.className);"   > 企业用户登录
            
             < div  class ="tab_content"  id ="tab_content" >
                
            
        

  注意点:

  1:ul的line-height设置为0,但padding-bottom设置为文字显示的高度;同时,list-style属性必须设置为none;

  2:li的float属性设置为left;line-height必须设置为ul的padding-bottom高度减去li的border-bottom的宽度;padding设置为0;margin-top与margin-bottom俱都设置为0;

  3:tab_content(即

)的border-top设置为0,该边框由ul的border-bottom代替;其margin-top也需设置为0;

  4:ul和tab_content的宽度或者margin-left和margin-right保持一致;

  5:当鼠标点击li时,只需设置该li的背景色、该li的border-bottom和tab_content的背景色保持相同即可。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the purpose of the <progress> element? What is the purpose of the <progress> element? Mar 21, 2025 pm 12:34 PM

The article discusses the HTML &lt;progress&gt; element, its purpose, styling, and differences from the &lt;meter&gt; element. The main focus is on using &lt;progress&gt; for task completion and &lt;meter&gt; for stati

What is the purpose of the <datalist> element? What is the purpose of the <datalist> element? Mar 21, 2025 pm 12:33 PM

The article discusses the HTML &lt;datalist&gt; element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

Is HTML easy to learn for beginners? Is HTML easy to learn for beginners? Apr 07, 2025 am 12:11 AM

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

What is the purpose of the <meter> element? What is the purpose of the <meter> element? Mar 21, 2025 pm 12:35 PM

The article discusses the HTML &lt;meter&gt; element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates &lt;meter&gt; from &lt;progress&gt; and ex

What is the viewport meta tag? Why is it important for responsive design? What is the viewport meta tag? Why is it important for responsive design? Mar 20, 2025 pm 05:56 PM

The article discusses the viewport meta tag, essential for responsive web design on mobile devices. It explains how proper use ensures optimal content scaling and user interaction, while misuse can lead to design and accessibility issues.

What is the purpose of the <iframe> tag? What are the security considerations when using it? What is the purpose of the <iframe> tag? What are the security considerations when using it? Mar 20, 2025 pm 06:05 PM

The article discusses the &lt;iframe&gt; tag's purpose in embedding external content into webpages, its common uses, security risks, and alternatives like object tags and APIs.

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

What is an example of a starting tag in HTML? What is an example of a starting tag in HTML? Apr 06, 2025 am 12:04 AM

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

See all articles