2015-04-27 125 views
0

我創建了一個頁面(http://www.nextsteptutoring.co.uk/WhatWeTeach.html),其中包含4個可選h3元素,用於顯示主題上的更多文本供用戶閱讀。無法使用javascript選擇html元素

1st元素完美地工作 - 整個元素是可選的。第二和第三部分可以部分選擇,可以點擊+和第一個字母。第四個不能點擊。

JS工作正常,我的CSS似乎沒有問題,因爲第一次工作正常,第二次和第三次部分正常。我看不出這是如何成爲z-inex的,因爲具有z-index值的頁面上的唯一元素是頁腳,並且加載也很好。

<!DOCTYPE html> 
<html> 
    <head> 
    <meta content="text/html; charset=windows-1252" http-equiv="content-type"> 
    <link href="http://fonts.googleapis.com/css?family=Pacifico" rel="stylesheet" type="text/css"> 
    <link href="http://fonts.googleapis.com/css?family=Cabin+Condensed" rel="stylesheet" type="text/css"> 
    <link rel="stylesheet" href="Main.CSS"> 
    <title>NST | What We Teach</title> 
    </head> 
    <body> 
    <div class="container"> 
    <header> </header> 
    <div class="leftcolumn"> 
     <h2>What We Teach</h2> 
     <p> Clear schemes of work, linked to the National Curriculum, which 
     are individually tailored to your child’s needs. We offer one to one   
     sessions, or small groups, with a maximum of 4 children. Groups are   
     based on specific needs/ability, rather than on chronological age.<br/> 
     <br/> 
     Programmes of study are adapted for high achievers in need of a 
     challenge, as well as those who lack confidence or require additional 
     support, outside of mainstream education.<br/> 
     </p> 
    </div> 
    <div class="rightcolumn"> 
     <div class="hide"> 
     <h3>+ Primary Maths</h3> 
     <ul> 
      <li>The four rules of number</li> 
      <li>Focus on Mental Arithmetic</li> 
      <li>Multiplication and associated division facts</li> 
      <li>Fractions, decimals and percentages</li> 
      <li>Data Handling, measures, and shapes</li> 
      <li>Algebra</li> 
      <li>Using and applying mathematical skills in everyday problem 
      solving</li> 
      <li>Confidence building and catch-up</li> 
     </ul> 
     </div> 
     <div class="hide"> 
     <h3>+ Primary English</h3> 
     <ul> 
      <li>Clear focus on comprehension. Building skills of inference and 
      reasoning</li> 
      <li>Individually tailored spelling programme (specialised dyslexia 
      spelling programme)</li> 
      <li>Grammar and punctuation</li> 
      <li>Writing for different purposes and audiences</li> 
      <li>Handwriting</li> 
      <li>Confidence building and catch-up</li> 
     </ul> 
     </div> 
     <div class="hide"> 
     <h3>+ Year 6 to Year 7 Transition</h3> 
     <p>Tailored English and Maths programme to support youngsters who 
      lack confidence during their transition from Primary to Secondary 
      education.</p> 
     </div> 
     <div class="hide"> 
     <h3>+ Written Reports</h3> 
     <p>Parents may wish to receive a termly or yearly written report on 
      their child’s progress, and targets for the next phase of their 
      learning. This service will incur a fee of £10.</p> 
     </div> 
    </div> 
    <footer> </footer> 
    </div> 
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"></script> 
    <script type="text/javascript" src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script> 
    <script type="text/javascript"> 
    $(document).ready(function(){ 
     $("header").load("Header.txt"); 
    }); 
    $(document).ready(function(){ 
     $("footer").load("Footer.txt"); 
    }); 
    $(".hide > h3").click(function(){ 
     $(this).parent().toggleClass("show"); 
    }); 
    $(".show > h3").click(function(){ 
     $(this).parent().toggleClass("hide"); 
    }); 
    </script> 
</body> 
</html> 


footer { 
    position: fixed; 
    width: 100%; 
    bottom: 0; 
    left: 0; 
    background: rgba(150,150,150,1); 
    color: white; 
    text-align: center; 
    z-index: 5; 
} 
footer .container div { 
    display: inline-block; 
    padding: 5px 30px 2px 30px; 
} 
#contact { 
    background: rgba(120,117,185,1); 
    float: right; 
    padding: 5px 100px 2px 100px; 
} 
.hide h3 { 
    width: 100%; 
    background: rgba(171,167,242,0.75); 
    border-radius: 5px; 
    cursor: pointer; 
    padding: 2px 0 2px 8px; 
} 
.hide p, .hide ul { 
    opacity: 0; 
    height: 0; 
} 
.show { 
    height: auto; 
} 
.show p, .show ul { 
    opacity: 1; 
    list-style-type: square; 
    height: auto; 
    font-size: 18px; 
} 

任何想法將不勝感激!

回答

0

問題是css

添加這樣的:

.hide p, .hide ul { 
    opacity: 0; 
    height: 0; 
    overflow: hidden; 
} 

li元素被重疊的按鈕。所以給overflow: hiddenul和他們得到hidden正確,而不影響其餘的。

+0

謝謝喬爾,那工作完美! –

0

CSS

.hide h3 { 
    padding: 2px 0 2px 10px; 
    width: 97%; 
    background: rgba(171,167,242,0.75); 
    border-radius: 5px; 
    cursor: pointer; 
    position: relative; 
} 

添加position:relative CSS屬性您.hide h3它將很好地工作。