1

在我开始之前,您应该知道这里有很多信息。这个是因为我还不能发布 pix,还有两个是为了不浪费彼此的时间。非常感谢我在这篇文章中获得的所有帮助!

所以我正在使用一个无序列表,其中列表元素在大文本中显示为内联。列表本身占据了大约 80% 的页面。

当您单击列表元素时,应该会弹出一个 div 来替换列表元素,解释列表元素的含义,如果您单击 div,则 div 会消失,而列表元素会重新出现。

我遇到的问题是我希望 div 元素完全替换列表元素在无序列表中的放置方式(边距和所有内容)。相反,发生的事情是 div 每次都出现在左侧,而无序列表元素在右侧重新排列。

这是html:

    <div id="bottom">
    <h1 class="issue_line">So what's the issue in Niagara Falls?</h1>
    <ul class="issue_headings">
    <li class="issue1">Education</li>
 <div class="quarter-box1">
  <p>The members of NOAH recognize that <strong>quality education</strong> is      
      necessary for any community to thrive...<br/>
  <a href="issues_taskforces.html">Read more.</a></p>
 </div>

    <li class="issue2">Local Hiring</li>
 <div class="quarter-box2">
  <p>The need for jobs in Niagara County is overwhelming, and NOAH is working to 
      create more local jobs through the policy level...<br/>
  <a href="issues_taskforces.html">Read more.</a></p>
 </div>

    <li class="issue3">Economic Development</li>
 <div class="quarter-box3">
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse et   
      facilisis risus. Quisque a gravida urna. Ut leo ligula...<br/>
 <a href="issues_taskforces.html">Read more.</a></p>
 </div>

    <li class="issue4">Trasnportation</li>
 <div class="quarter-box4">
 <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse et 
     facilisis risus. Quisque a gravida urna. Ut leo ligula...<br/>
 <a href="issues_taskforces.html">Read more.</a></p>
</div>

    </ul>
    </div>

这是CSS

     #bottom {
      position: relative;
      width: 100%;
      margin: 0 auto; 
      clear: both;
      padding-top: 5px;
      padding-bottom: 5px;
     }

     ul.issue_headings {
      width: 1498px;
      float: left;
      margin-top: 50px;
      margin-bottom: 50px;
      padding: 0;
      list-style-type: none;
      display: none;
      text-align: center;
     }

     ul.issue_headings li {
      display: inline;
      margin-left: 2%;
      padding: 0;
      font-size: 3em;
      color: #9ac0e2;
     }

     ul.issue_headings li:hover {
      color: #FF9933;
     }

     .quarter-box1 { 
      float: left;
      margin-left: 50px;
      background-color: rgba(255, 255, 255, .9);
      border: 3px solid #0c69bf;
      box-shadow: 5px 5px 20px black;
      width: 280px;
      height: 150px;
      overflow: hidden;
      display: none;
     }

     .quarter-box2 { 
      float: left;
      margin-left: 100px;
      background-color: rgba(255, 255, 255, .9);
      border: 3px solid #0c69bf;
      box-shadow: 5px 5px 20px black;
      width: 280px;
      height: 150px;
      overflow: hidden;
      display: none;
     }

     .quarter-box3 {
      float: left;
      margin-left: 150px;
      background-color: rgba(255, 255, 255, .9);
      border: 3px solid #0c69bf;
      box-shadow: 5px 5px 20px black;
      width: 280px;
      height: 150px;
      overflow: hidden;
      display: none;
     } 

     .quarter-box4 {
      float: left;
      margin-left: 200px;
      background-color: rgba(255, 255, 255, .9);
      border: 3px solid #0c69bf;
      box-shadow: 5px 5px 20px black;
      width: 280px;
      height: 150px;
      overflow: hidden;
      display: none;
     }

     .quarter-box1:hover, .quarter-box2:hover,.quarter-box3:hover, .quarter-box4:hover { 
      border: 3px solid #FF9933;
     }

这是 jQuery

        $('h1.issue_line').click(function(){
          $('h1.issue_line').hide("slow");
          $('ul.issue_headings').show("slow");
          $('div.quarter-box1,div.quarter-box2,div.quarter-box3,div.quarter-                 
     box4').hide("slow");
        });
        $('ul.issue_headings li.issue1').click(function(){
          $('ul.issue_headings li.issue1,div.quarter-box2,div.quarter-box3,div.quarter-

     box4').hide("slow");
          $('div.quarter-box1,ul.issue_headings li.issue2,ul.issue_headings 
     li.issue3,ul.issue_headings li.issue4').show("slow");
        });
        $('ul.issue_headings li.issue2').click(function(){
          $('ul.issue_headings li.issue2,div.quarter-box1,div.quarter-box3,div.quarter-
     box4').hide("slow");
          $('div.quarter-box2,ul.issue_headings li.issue1,ul.issue_headings 
     li.issue3,ul.issue_headings li.issue4').show("slow");
        });
        $('ul.issue_headings li.issue3').click(function(){
        $('ul.issue_headings li.issue3,div.quarter-box1,div.quarter-box2,div.quarter-          
     box4').hide("slow");
          $('div.quarter-box3,ul.issue_headings li.issue1,ul.issue_headings          
     li.issue2,ul.issue_headings li.issue4').show("slow");
        });
        $('ul.issue_headings li.issue4').click(function(){
          $('ul.issue_headings li.issue4,div.quarter-box1,div.quarter-box2,div.quarter-
     box3').hide("slow");
          $('div.quarter-box4,ul.issue_headings li.issue1,ul.issue_headings          
     li.issue2,ul.issue_headings li.issue3').show("slow");
        });
        $('div.quarter-box1').click(function(){
          $('div.quarter-box1').hide("slow");
          $('ul.issue_headings li.issue1').show("slow");
        });
      $('div.quarter-box2').click(function(){
          $('div.quarter-box2').hide("slow");
          $('ul.issue_headings li.issue2').show("slow");
        });
      $('div.quarter-box3').click(function(){
          $('div.quarter-box3').hide("slow");
          $('ul.issue_headings li.issue3').show("slow");
        });
      $('div.quarter-box4').click(function(){
          $('div.quarter-box4').hide("slow");
          $('ul.issue_headings li.issue4').show("slow");
        });

让我知道你在想什么!

4

1 回答 1

0

...所以基于@nnnnnn 和@aug 的一些建议,我能够弄清楚这一点。通过确保 HTML 代码有效,可以修复 ul + div 组合(简单的错误,我完全错过了!)。此外,我在 div 之外添加了一个单独的 h4,但仍在列表元素内。

<div id="bottom">
<h1 class="issue_line">So what's the issue in Niagara Falls?</h1>
<ul class="issue_headings">
<li class="issue1">
    <h4>Education</h4>
    <div class="quarter-box1">
     <p>The members of NOAH recognize that <strong>quality education</strong> is necessary for any community to thrive...<br/>
     <a href="issues_taskforces.html">Read more.</a></p>
    </div>
</li>   
<li class="issue2">
    <h4>Local Hiring</h4>
    <div class="quarter-box2">
     <p>The <strong>need for jobs</strong> in Niagara County is overwhelming, and NOAH is working to create more local jobs through the policy level...<br/>
     <a href="issues_taskforces.html">Read more.</a></p>
    </div>
</li>
<li class="issue3">
    <h4>Economic Development</h4>
    <div class="quarter-box3">
     <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse et facilisis risus. Quisque a gravida urna. Ut leo ligula...<br/>
     <a href="issues_taskforces.html">Read more.</a></p>
    </div>
</li>   
<li class="issue4">
    <h4 style="margin-left:20px;">Transportation</h4>
    <div class="quarter-box4">
     <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse et facilisis risus. Quisque a gravida urna. Ut leo ligula...<br/>
     <a href="issues_taskforces.html">Read more.</a></p>
    </div>
</li>   
</ul>
</div>

...然后要求在 JQ 中进行一些编辑:

$('h1.issue_line').click(function(){
     $('h1.issue_line').hide("slow");
     $('li.issue1 h4,li.issue2 h4,li.issue3 h4,li.issue4 h4').show("slow");
     $('div.quarter-box1,div.quarter-box2,div.quarter-box3,div.quarter-box4').hide("slow");
   });
   $('li.issue1 h4').click(function(){
     $('li.issue1 h4,div.quarter-box2,div.quarter-box3,div.quarter-box4').hide("slow");
     $('div.quarter-box1,li.issue2 h4,li.issue3 h4,li.issue4 h4').show("slow");
   });
   $('li.issue2 h4').click(function(){
     $('li.issue2 h4,div.quarter-box1,div.quarter-box3,div.quarter-box4').hide("slow");
     $('div.quarter-box2,li.issue1 h4,li.issue3 h4,li.issue4 h4').show("slow");
   });
   $('li.issue3 h4').click(function(){
     $('li.issue3 h4,div.quarter-box1,div.quarter-box2,div.quarter-box4').hide("slow");
     $('div.quarter-box3,li.issue1 h4,li.issue2 h4,li.issue4 h4').show("slow");
   });
   $('li.issue4 h4').click(function(){
     $('li.issue4 h4,div.quarter-box1,div.quarter-box2,div.quarter-box3').hide("slow");
     $('div.quarter-box4,li.issue1 h4,li.issue2 h4,li.issue3 h4').show("slow");
   });
   $('div.quarter-box1').click(function(){
     $('div.quarter-box1').hide("slow");
     $('li.issue1 h4').show("slow");
   });
 $('div.quarter-box2').click(function(){
     $('div.quarter-box2').hide("slow");
     $('li.issue2 h4').show("slow");
   });
 $('div.quarter-box3').click(function(){
     $('div.quarter-box3').hide("slow");
     $('li.issue3 h4').show("slow");
   });
 $('div.quarter-box4').click(function(){
     $('div.quarter-box4').hide("slow");
     $('li.issue4 h4').show("slow");
   });

...最后,在 CSS 中进行一些调整以对齐列表:

#bottom {
 position: relative;
 width: 100%;
 margin: 0 auto; 
 clear: both;
 padding-top: 5px;
 padding-bottom: 5px;
}

ul.issue_headings {
 width: 1498px;
 float: left;
 margin-top: 20px;
 margin-bottom: 20px;
 padding: 0;
 list-style-type: none;
 text-align: center;
}

ul.issue_headings li h4 {
 display: inline;
 margin-top: 20px;
 margin-left: 0;
 padding: 0;
 font-size: 3em;
 color: #9ac0e2;
 display:none;
 width: 350px;
 cursor: pointer;
}

ul.issue_headings li h4:hover {
 color: #FF9933;
}

.quarter-box1, .quarter-box2, .quarter-box3, .quarter-box4 { 
 float: left;
 margin: 0 auto;
 background-color: rgba(255, 255, 255, .9);
 border: 3px solid #0c69bf;
 box-shadow: 5px 5px 20px black;
 width: 280px;
 height: 200px;
 overflow: hidden;
 display: none;
}

In conclusion, I now have a 3 stringed JQ event that can be toggled at the last phase.

Thanks again everyone for helping to point me in the right direction!

于 2012-08-28T23:04:28.187 回答