简体   繁体   中英

My Html tab switch is not working, what am i doing wrong?

I am trying to group my CV into section, by using the tabs 'Profile', 'Education', 'Skills'. 'Work Experience', 'Featured Projects'.

However, with the code snippets I have found and put together (and the help of W3schools), It seems that my tab functions are not working, but just list the Education "page" below the Profile "page".

What am I not considering? This is my first attempt with HTML and CSS. If you see any clean-up potential, please point it out.

 @import url(https://weloveiconfonts.com/api/?family=entypo|fontawesome); /* entypo */ [class*="entypo-"]:before { font-family: 'entypo', sans-serif; } /* fontawesome */ [class*="fontawesome-"]:before { font-family: 'FontAwesome', sans-serif; } /* Utils */ .clear { clear: both; } .purple { color: #837c9a; } .block { margin: 25px 30px; } .block h1 { margin-left: -5px; font-weight: 200; } .last.block { margin-bottom: 110px; } .horizontal_list { margin: 0; padding: 0; list-style-type: none; } .horizontal_list li { float: left; } .horizontal_list li:before { content: none; } .horizontal_list li { padding-left: 0; text-indent: 0; } .horizontal_line { margin: 34px 0 0 30px; height: 26px; position: relative; } .line_left, .line_right { border-top: 1px solid #434247; width: 305px; margin-top: 13px; } .line_left { float: left; } .line_right { float: right; } .left_circle, .central_circle, .right_circle { background: rgb(69, 68, 73); background: rgba(255, 255, 255, 0.15); position: absolute; border-radius: 50px; } .left_circle, .right_circle { width: 13px; height: 13px; top: 7px; } .left_circle { left: 314px; } .central_circle { width: 26px; height: 26px; top: 0px; left: 322px; } .right_circle { left: 343px; } /* Main tags */ body { background: url(https://www.toptal.com/designers/subtlepatterns/patterns/dark_wall.png) repeat; margin: 0; } h1, h2, h3, h4 { font-family: 'Lato', Helvetica, sans-serif; font-weight: 300; color: #48DA9B; } h1 { font-size: 48px; font-weight: 300; margin: 20px 0; } h2 { font-size: 28px; margin: 32px 0 24px; } h3 { font-size: 24px; } h4 { font-size: 18px; font-weight: 400; } blockquote { font-style: italic; margin: 25px 0; padding-left: 20px; border-left: 2px solid #48DA9B; } blockquote, p, a, li { font-family: 'Lato', Helvetica, sans-serif; font-weight: 300; font-size: 15px; color: #3c3b3f; } a:focus { outline: none; } ul { list-style: none; padding: 0; margin: 0; } li { padding-left: 1em; text-indent: -.7em; } li:before { content: "• "; color: #837c9a; font-size: 20px; padding-right: 8px; } /* Containers size */ #main_container { width: 960px; margin: 0 auto; } #header { height: 130px; border-bottom: 1px solid #403F44; } .header_logotype_container { width: 260px; height: 130px; border-right: 1px solid #403F44; float: left; } .header_menu_container { height: 130px; width: 699px; float: left; } .header_menu_container a { font-family: 'Lato', Helvetica, sans-serif; } #left_col { width: 260px; float: left; } #content_container1 { width: 699px; border-left: 1px solid #403F44; float: left; } #content_container2 { width: 699px; border-left: 1px solid #403F44; float: left; } #content_container3 { width: 699px; border-left: 1px solid #403F44; float: left; } #content_container4 { width: 699px; border-left: 1px solid #403F44; float: left; } #content_container5 { width: 699px; border-left: 1px solid #403F44; float: left; } #footer { width: 960px; height: 60px; border-top: 1px solid #403F44; display: inline-block; } /* HEADER */ .logotype_name { text-transform: uppercase; font-size: 32px; margin: 43px 0 0; } .logotype_occupation { text-transform: uppercase; margin-top: 5px; color: #5ce2af; font-size: 14px; letter-spacing: 2px; padding-left: 7px; } .download_print_buttons { width: 225px; height: 45px; float: right; } .download_print_buttons a { text-decoration: none; font-size: 12px; font-family: 'Lato', Helvetica, sans-serif; font-style: italic; line-height: 45px; padding: 16px 17px; background: #ffffff; } .download_print_buttons a:hover { background: #666666; } .download_print_buttons .icon { color: #02070a; padding-right: 6px; font-style: normal; font-size: 18px; } .icon-angle-double-right { position: relative; top: 2px; } .download_print_buttons a:hover .icon { color: #e4e3e8; } .header_menu { width: 699px; margin-top: 40px; margin-left: 5px; } .header_menu a { text-decoration: none; padding: 0 20px; border-left: 1px solid #e4e3e8; font-size: 16px; font-weight: 400; } .header_menu a.no_border { border-left: none; } .header_menu a:hover { color: #837c9a; } /* LEFT NAV */ #left_nav h2 { margin: 0; font-size: 24px; } .profile_frame { width: 230px; height: 260px; background: black; border: 1px solid #403F44; margin-top: 30px; } .profile_picture { width: 210px; height: 240px; margin: 10px; background: url(//s3-us-west-2.amazonaws.com/s.cdpn.io/86033/profile/profile-512_3.jpg) 100% /210px no-repeat; } .hello_content, .contact_details_content { margin-top: 25px; } .hello_content { width: 230px; } .contact_details_content h2+p.purple { margin-top: 10px; } .contact_details_content p { margin: 0; } .contact_details_content p.purple { margin-top: 25px; } .send_message_button, .special_button { margin-top: 25px; display: block; background: #48DA9B; width: 230px; height: 50px; position: relative; z-index: 1; } .cut1:after { content: ""; position: absolute; bottom: -19px; left: -20px; width: 30px; height: 30px; z-index: 9; background: url(https://www.toptal.com/designers/subtlepatterns/patterns/dark_wall.png) repeat; transform: rotate(45deg); } .cut2:before { content: ""; position: absolute; top: -19px; right: -20px; width: 30px; height: 30px; z-index: 9; background: url(https://www.toptal.com/designers/subtlepatterns/patterns/dark_wall.png) repeat; transform: rotate(45deg); } .content { text-align: center; color: #04080b; width: 100%; height: 40px; position: absolute; z-index: 2; font: 18px 'Lato', Arial, sans-serif; margin: 0; padding: 16px 0 0; top: -4px; bottom: 10px; border-top: 1px solid #403F44; border-bottom: 1px solid #403F44; } .send_message_button:hover, .special_button:hover { background: #29C782; } .get_social_content { margin-top: 15px; } .get_social_content h2 { margin-bottom: 8px; } .social_icons { margin-left: -8px; } .social_icons a { font-size: 35px; text-decoration: none; color: #000507; padding: 0; padding: 0 5px; } .social_icons a span.invisible { display: none; } .social_icons .facebook:hover { background: #3b5998; color: #dfe3ee; border-top-right-radius: 50px; border-bottom-left-radius: 50px; } .social_icons .twitter:hover { background: #00B0ED; color: #fff; border-top-left-radius: 50px; border-bottom-right-radius: 50px; } .social_icons .linkedin:hover { background: #007bb6; color: #fff; border-top-right-radius: 50px; border-bottom-left-radius: 50px; } .footer_name { font-style: italic; margin-top: 20px; } /* Profile Content */ .profile_quote { position: relative; /* margin-left: 5px; */ } .profile_quote p { font-size: 17px; width: 455px; } .profile_quote .entypo-quote { color: #3d3a41; font-size: 80px; font-style: normal; position: absolute; top: -20px; right: 70px; cursor: default; } .philosophy_content { margin-top: 20px; } .philosophy_content p { margin: 0; width: 370px; float: left; } .philosophy_content ul { float: left; padding-left: 40px; } @import url("https://fonts.googleapis.com/css?family=Open+Sans:400,600,700"); @import url("https://netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.css"); section { display: none; padding: 20px 0 0; border-top: 1px solid #ddd; } input { display: none; } label { display: inline-block; margin: 0 0 -1px; padding: 12px 28.5px; font-weight: 600; text-align: center; color: #bbb; border: 1px solid transparent; } label:before { font-family: fontawesome; font-weight: normal; margin-right: 10px; } label:hover { color: #888; cursor: pointer; } input:checked+label { color: #555; border: 1px solid #ddd; border-top: 2px solid orange; border-bottom: 1px solid #fff; } #tab1:checked~#content_container1, #tab2:checked~#content_container2, #tab3:checked~#content_container3, #tab4:checked~#content_container4, #tab5:checked~#content_container5 { display: block; } @media screen and (max-width: 650px) { label { font-size: 0; } label:before { margin: 0; font-size: 18px; } } @media screen and (max-width: 400px) { label { padding: 15px; } }
 <link href='https://fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic' rel='stylesheet' type='text/css'> <!-- MAIN CONTAINER --> <div id="main_container"> <!-- HEADER --> <div id="header"> <!-- LOGOTYPE/NAME --> <div class="header_logotype_container"> <h1 class="logotype_name">Firstname <span class="purple">Lachname</span></h1> <h2 class="logotype_occupation">Occupation</h2> </div> <!-- MAIN MENU --> <main> <div class="header_menu_container"> <ul class="download_print_buttons horizontal_list"> <li><a href="#"><span class="icon entypo-download"></span>Download CV</a></li> <li><a href="#"><span class="icon entypo-print"></span>Print CV</a></li> </ul> <div class="clear tab"></div> <ul class="header_menu horizontal_list"> <li><input id="tab1" type="radio" name="tabs" checked> <label for="tab1">Profile</label></li> <li><input id="tab2" type="radio" name="tabs"> <label for="tab2">Education</label></li> <li><input id="tab3" type="radio" name="tabs"> <label for="tab3">Skills</label></li> <li><input id="tab4" type="radio" name="tabs"> <label for="tab4">Work Experience</label></li> <li><input id="tab5" type="radio" name="tabs"> <label for="tab5">Featured Projects</label></li> </ul> </div> </div> <!-- LEFT COL --> <div id="left_col"> <div class="profile_frame"> <div class="profile_picture"></div> <!-- <img src="images/javier_latorre.jpg" alt="profile picture"> --> </div> <div class="hello_content"> <h2>Hello!</h2> <p>I'm passionate about technology and human behavior, hardworker and a fast-learner with experience in around 5 different countries studying, working and volunteering. I believe that the right digital innovation is key to our society's wellbeing. This motivates me to not only consume the latest technology but to be an active driver of change and development.</p> </div> <div class="contact_details_content"> <h2>Contact details</h2> <p class="purple">Phone:</p> <p>any numbers</p> <p class="purple">Email:</p> <p>first.last@xyz.com</p> <p class="purple">Adress:</p> <p>Street Nr.</p> <p>Zip Location</p> <p>Country</p> </div> <a href="first.last@xyz.com" class="send_message_button"> <span class="cut1"></span> <span class="cut2"></span> <span class="content">Send me a message <span class="fontawesome-double-angle-right"></span></span> </a> <div class="get_social_content"> <h2>Get social</h2> <ul class="social_icons horizontal_list"> <li><a class="linkedin" href="https://www.linkedin.com/in/xyz/"><span class="entypo-linkedin-circled"></span><span class="invisible">LinkedIn</span></a></li> </ul> </div> </div> <!-- PROFILE CONTENT --> <div id="content_container1"> <div class="block"> <h1>Profile</h1> <blockquote class="profile_quote"> <p>"There is no end to education. It is not that you read a book, pass an examination, and finish with education. The whole of life, from the moment you are born to the moment you die, is a process of learning."</p> <p>Jiddu Krishnamurti.</p> <span class="entypo-quote"></span> </blockquote> </div> <div class="block"> <h2>A few words about me</h2> <p>Until now, in my life, I change from active moments with a lot of variety, challenges and improvisations, to moments of tranquility and stability, being difficult to stay in a place during a long time. I consider myself a tolerant and respectful person with open mind and quite honest. I really like to listen people stories and backgrounds and their different experiences around the world.</p> </div> <div class="horizontal_line"> <div class="line_left"></div> <div class="left_circle"></div> <div class="central_circle"></div> <div class="right_circle"></div> <div class="line_right"></div> </div> <div class="block"> <h2>Philosophy</h2> <p>I belive in ethic and moral not in imposed rules that you "have to" do or follow.</p> <div class="philosophy_content"> <p>I believe life is made from different shades of grey, not from black and white. Furthermore, as a human being with rationality, I think it is our duty to take care of the world and treat others as one would like others to treat oneself. This way of perceiving reality affects my beliefs and my way of behaving. Summarizing on several points:</p> <ul> <li>Pragmatic</li> <li>Honest</li> <li>Respectful</li> <li>Open-minded</li> <li>Coherent</li> </ul> <div class="clear"></div> </div> </div> <div class="horizontal_line"> <div class="line_left"></div> <div class="left_circle"></div> <div class="central_circle"></div> <div class="right_circle"></div> <div class="line_right"></div> </div> <div class="last block"> <h2>Work Motivation</h2> <p>I'm passionate about technology and human behavior, yet, these are only a few of my interests. others include:</p> <ul> <li>Visiting new places</li> <li>Meeting people</li> <li>Hiking and Biking</li> <li>Bouldering</li> <li>Cooking</li> <li>Reading</li> </ul> </div> </div> <div class="clear"></div> <!-- Education CONTENT --> <div id="content_container2"> <div class="block"> <h1>Education Timeline</h1> <blockquote class="profile_quote"> <p>"There is no end to education. It is not that you read a book, pass an examination, and finish with education. The whole of life, from the moment you are born to the moment you die, is a process of learning."</p> <p>Jiddu Krishnamurti.</p> <span class="entypo-quote"></span> </blockquote> </div> <div class="block"> <h2>A few words about me</h2> <p>Until now, in my life, I change from active moments with a lot of variety, challenges and improvisations, to moments of tranquility and stability, being difficult to stay in a place during a long time. I consider myself a tolerant and respectful person with open mind and quite honest. I really like to listen people stories and backgrounds and their different experiences around the world.</p> </div> <div class="horizontal_line"> <div class="line_left"></div> <div class="left_circle"></div> <div class="central_circle"></div> <div class="right_circle"></div> <div class="line_right"></div> </div> <div class="block"> <h2>Philosophy</h2> <p>I belive in ethic and moral not in imposed rules that you "have to" do or follow.</p> <div class="philosophy_content"> <p>I believe life is made from different shades of grey, not from black and white. Furthermore, as a human being with rationality, I think it is our duty to take care of the world and treat others as one would like others to treat oneself. This way of perceiving reality affects my beliefs and my way of behaving. Summarizing on several points:</p> <ul> <li>Pragmatic</li> <li>Honest</li> <li>Respectful</li> <li>Open-minded</li> <li>Coherent</li> </ul> <div class="clear"></div> </div> </div> <div class="horizontal_line"> <div class="line_left"></div> <div class="left_circle"></div> <div class="central_circle"></div> <div class="right_circle"></div> <div class="line_right"></div> </div> <div class="last block"> <h2>Work Motivation</h2> <p>I'm passionate about technology and human behavior, yet, these are only a few of my interests. others include:</p> <ul> <li>Visiting new places</li> <li>Meeting people</li> <li>Hiking and Biking</li> <li>Bouldering</li> <li>Cooking</li> <li>Reading</li> </ul> </div> </div> <div class="clear"></div> </main> <!-- FOOTER --> <div id="footer"> <p class="footer_name">Fist Last CV 2022</p> </div> </div>

Add this simple js function to switch the tabs. Also add one class (here tabcontainer ) in different tab containers. Add style display:none to next tabs initially, the style will be changed to display:block by js

 function openTab(tab) { var i; var x = document.getElementsByClassName("tabcontainer"); for (i = 0; i < x.length; i++) { x[i].style.display = "none"; } document.getElementById(tab).style.display = "block"; }
 <ul class="header_menu horizontal_list"> <li> <input id="tab1" type="radio" name="tabs" checked onclick="openTab('content_container1')"> <label for="tab1">Profile</label> </li> <li> <input id="tab2" type="radio" name="tabs" onclick="openTab('content_container2')"> <label for="tab2">Education</label></li> <li> <input id="tab3" type="radio" name="tabs" onclick="openTab('content_container3')"> <label for="tab3">Skills</label> </li> <li> <input id="tab4" type="radio" name="tabs" onclick="openTab('content_container4')"> <label for="tab4">Work Experience</label> </li> <li> <input id="tab5" type="radio" name="tabs" onclick="openTab('content_container5')"> <label for="tab5">Featured Projects</label> </li> </ul> <div id="content_container1" class="tabcontainer"> <div class="block"> <h1>Profile</h1> <blockquote class="profile_quote"> <p>"Tab 1: About Profile"</p> <p>Jiddu Krishnamurti.</p> <span class="entypo-quote"></span> </blockquote> </div> </div> <div class="clear"></div> <!-- Education CONTENT --> <div id="content_container2" class="tabcontainer" style="display:none"> <div class="block"> <h1>Education Timeline</h1> <blockquote class="profile_quote"> <p>"Tab 3: About Education Timeline."</p> <p>Test Author2</p> <span class="entypo-quote"></span> </blockquote> </div> </div> <div id="content_container3" class="tabcontainer" style="display:none"> <div class="block"> <h1>Skills</h1> <blockquote class="profile_quote"> <p>"Tab 3: About Skills."</p> <p>Test Author3</p> <span class="entypo-quote"></span> </blockquote> </div> </div> <div class="clear"></div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM