无序列表没有正确布局

时间:2012-08-09 12:10:15

标签: html css html-lists

我有一个无序列表,我想要显示两列中的文本块。该列表列出了两列中的项目,但我发现间距不一致。因此,右侧栏中的项目位于另一列之下,并设置了我设置的边距,而在左侧列中,两个项目之间出现了较大的间隙。

我该如何解决这个问题?我的HTML在下面。提前谢谢。

<html>
<head>test page
 <STYLE type="text/css">
 .textColumnBox {
padding-top:10px;
float: left;
width: 640px;
padding-bottom: 20px;
}
.moreNews {
padding: 2px 0 5px 0;
width:630px;
display:block;
clear:both;
background-image: url(/images/footer.jpg);
background-repeat: repeat-x;
text-align: right;
-moz-border-radius: 4px;
border-radius: 4px;
}
   .newscolumns
{
width: 100%; 
  overflow: hidden;
vertical-align:top;
}

.newscolumns ul
{
height: 300px;  
font-size: 12pt;    
 vertical-align:top;
 margin:2px;

}

 .newscolumns ul li
{
 padding: inherit;
 width: 310px;
 display: block;
 float: left;
 margin-bottom: -4px;
 background: red;
 vertical-align: top;
 }
.newsBox 
{
margin-left: 3px;
margin-bottom: 2px;/*changed from 15*/
padding-right: 20px;
border-right-width: 1px;
border-right-style: solid;
border-right-color: #4E4629;
}
.newsBox p {
display:block;
font-size: 0.7em;
line-height: 1.2em;
padding-bottom:5px;
}
.newsBox h3 {
line-height: 1.2em;
}

.newsBoxFoot {
display:block;
font-size: 0.7em;
line-height: 1.4em;
color:#999;

}
.newsBox a {
text-decoration:none;

}
.newsBox a:hover {
text-decoration:none;
color:#FFF;
}
 </STYLE></head>
<body>
 <div class="textColumnBox">
    <h1>
        Latest News</h1>
    <div class="newscolumns">
        <ul>
            <li>
    <div class="newsBox">
        <h3>
            <a href="#">sample text here qwertyuiowertyuiwertyu</a></h3>
        <p>kfdokashfsdhfjhf kjashf kjash fkjsahf saf kjsh fjsakhf kjashf kjsahf kjsahfjksafiksafkashf hsf haskjhf askjhf asjlkh flsakh flskahf lkashf lkashf lksahf lkashf lkashjh as</p>
        <div class="newsBoxFoot">20/12/2011 read more</div>
        <!-- end .newsBox -->
    </div>
</li> 
  <li>
    <div class="newsBox">
        <h3>
            <a href="#">yasdefghasdfgh sdfgsdfgasdfga dfgsdfgsdf sdfghsdefgh</a></h3>
        <p>Pkjhfsdfh skljfhsakjfh asjklhfasljkfh aslkf salkhf laskhf lskahf 
        lkasflkashfl ksahflk aslfk aslf hsalkf aslkhf laskhf lskahf glksahf 
        lskahf laskhf lksahf asljkf hsalkhflskahflkh&nbsp; sa</p>
        <p>ewreewrewr</p>
        <p>&nbsp;</p>

        <div class="newsBoxFoot">14/06/2012 read more</div>
        <!-- end .newsBox -->
    </div>
</li>
 <li>
    <div class="newsBox">
        <h3>
            <a href="#">gdfgfdg dfgfdgfgfdgdfg fdgfdgfdgfd gfdgfdgdfdfr</a></h3>
        <p>;sdljfs;dlj sd;lfj ds;pl;lsdjg;kdlgkdsflblkjg dlskh gkhkljh kjl.h k.j hgjklsdh g kjdsh g,m hcnxogv;isdhgoiunndkn  o;jyhds</p>
        <div class="newsBoxFoot">04/04/2012 read more</div>
        <!-- end .newsBox -->
    </div>
</li>
 <li>
        <div class="newsBox">
        <h3>
            <a href="#">dfgfdg dfgdfgdfg fddfg</a></h3>
        <p>sd;l;ljd;l sdkjfdskjlsdkjfldksjflsdkjflsdkjf sldkhfdslkhfjkldhf 
        sdkjhkjh skdjhfkjhkjdhk skdjhkjhkjhoswlhf lkhkljhs kjhkjhkjh 
        sdklhkjh kh</p>
        <div class="newsBoxFoot">14/06/2012 read more</div>
        <!-- end .newsBox -->
    </div>
</li>



       </ul>
    </div>
    <div class="moreNews">more news</div>
    <!-- end .textColumnBox -->
    </div>
</body>
</html>   

4 个答案:

答案 0 :(得分:1)

你的宽度是这里的问题。

See demo

.textColumnBox {
  padding-top:10px;
  float: left;
  width: 640px;
  padding-bottom: 20px;
}
.moreNews {
  padding: 2px 0 5px 0;
  width:630px;
  display:block;
  clear:both;
  background-image: url(/images/footer.jpg);
  background-repeat: repeat-x;
  text-align: right;
  -moz-border-radius: 4px;
  border-radius: 4px;
}
.newscolumns
{
  width: 100%;

  overflow: hidden;
  vertical-align:top;
}

.newscolumns ul
{
  height: 300px;

  font-size: 12pt;

  vertical-align:top;
  margin:2px;

}

.newscolumns ul li
{
  padding: inherit;
  width: 250px;
  display: block;
  float: left;
  margin-bottom: -4px;
  background: red;
  vertical-align: top;
}
.newsBox 
{
  margin-left: 3px;
  margin-bottom: 2px;
  /*changed from 15*/
  padding-right: 20px;
  border-right-width: 1px;
  border-right-style: solid;
  border-right-color: #4E4629;

}
.newsBox p {
  display:block;
  font-size: 0.7em;
  line-height: 1.2em;
  padding-bottom:5px;
}
.newsBox h3 {
  line-height: 1.2em;
}

.newsBoxFoot {
  display:block;
  font-size: 0.7em;
  line-height: 1.4em;
  color:#999;

}
.newsBox a {
  text-decoration:none;

}
.newsBox a:hover {
  text-decoration:none;
  color:#FFF;
}

<div class="textColumnBox">
  <h1>
    Latest News
  </h1>
  <div class="newscolumns">
    <ul>
      <li>
        <div class="newsBox">
          <h3>
            <a href="#">
              sample text here qwertyuiowertyuiwertyu
          </a>
      </h3>
      <p>
        kfdokashfsdhfjhf kjashf kjash fkjsahf saf kjsh fjsakhf kjashf kjsahf kjsahfjksafiksafkashf hsf haskjhf askjhf asjlkh flsakh flskahf lkashf lkashf lksahf lkashf lkashjh as
      </p>
      <div class="newsBoxFoot">
        20/12/2011 read more
      </div>
      <!-- end .newsBox -->
              </div>
          </li>

          <li>
            <div class="newsBox">
              <h3>
                <a href="#">
                  yasdefghasdfgh sdfgsdfgasdfga dfgsdfgsdf sdfghsdefgh
                </a>
              </h3>
              <p>
                Pkjhfsdfh skljfhsakjfh asjklhfasljkfh aslkf salkhf laskhf lskahf 
                lkasflkashfl ksahflk aslfk aslf hsalkf aslkhf laskhf lskahf glksahf 
                lskahf laskhf lksahf asljkf hsalkhflskahflkh&nbsp; sa
              </p>
              <p>
                ewreewrewr
              </p>
              <p>
                &nbsp;
              </p>

              <div class="newsBoxFoot">
                14/06/2012 read more
              </div>
              <!-- end .newsBox -->
            </div>
          </li>
          <li>
            <div class="newsBox">
              <h3>
                <a href="#">
                  gdfgfdg dfgfdgfgfdgdfg fdgfdgfdgfd gfdgfdgdfdfr
                </a>
              </h3>
              <p>
                ;sdljfs;dlj sd;lfj ds;pl;lsdjg;kdlgkdsflblkjg dlskh gkhkljh kjl.h k.j hgjklsdh g kjdsh g,m hcnxogv;isdhgoiunndkn  o;jyhds
              </p>
              <div class="newsBoxFoot">
                04/04/2012 read more
              </div>
              <!-- end .newsBox -->
            </div>
          </li>
          <li>
            <div class="newsBox">
              <h3>
                <a href="#">
                  dfgfdg dfgdfgdfg fddfg
                </a>
              </h3>
              <p>
                sd;l;ljd;l sdkjfdskjlsdkjfldksjflsdkjflsdkjf sldkhfdslkhfjkldhf 
                sdkjhkjh skdjhfkjhkjdhk skdjhkjhkjhoswlhf lkhkljhs kjhkjhkjh 
                sdklhkjh kh
              </p>
              <div class="newsBoxFoot">
                14/06/2012 read more
              </div>
              <!-- end .newsBox -->
            </div>
          </li>



      </ul>
  </div>
  <div class="moreNews">
    more news
  </div>
  <!-- end .textColumnBox -->
</div>

答案 1 :(得分:0)

我看不到两列。只是“最新消息”,在它下面有一个带有一些文字的大红色框,但它的每一行都有不同的行。

答案 2 :(得分:0)

我希望你看起来像这样: - http://tinkerbin.com/WekcnbhE

<强> HTML

<div class="textColumnBox">
    <h1>
        Latest News</h1>
    <div class="newscolumns">
        <ul>
            <li>
    <div class="newsBox">
        <h3>
            <a href="#">sample text here qwertyuiowertyuiwertyu</a></h3>
        <p>kfdokashfsdhfjhf kjashf kjash fkjsahf saf kjsh fjsakhf kjashf kjsahf kjsahfjksafiksafkashf hsf haskjhf askjhf asjlkh flsakh flskahf lkashf lkashf lksahf lkashf lkashjh as</p>
        <div class="newsBoxFoot">20/12/2011 read more</div>
        <!-- end .newsBox -->
    </div>
</li> 
  <li>
    <div class="newsBox">
        <h3>
            <a href="#">yasdefghasdfgh sdfgsdfgasdfga dfgsdfgsdf sdfghsdefgh</a></h3>
        <p>Pkjhfsdfh skljfhsakjfh asjklhfasljkfh aslkf salkhf laskhf lskahf 
        lkasflkashfl ksahflk aslfk aslf hsalkf aslkhf laskhf lskahf glksahf 
        lskahf laskhf lksahf asljkf hsalkhflskahflkh&nbsp; sa</p>
        <p>ewreewrewr</p>
        <p>&nbsp;</p>

        <div class="newsBoxFoot">14/06/2012 read more</div>
        <!-- end .newsBox -->
    </div>
</li>
 <li>
    <div class="newsBox">
        <h3>
            <a href="#">gdfgfdg dfgfdgfgfdgdfg fdgfdgfdgfd gfdgfdgdfdfr</a></h3>
        <p>;sdljfs;dlj sd;lfj ds;pl;lsdjg;kdlgkdsflblkjg dlskh gkhkljh kjl.h k.j hgjklsdh g kjdsh g,m hcnxogv;isdhgoiunndkn  o;jyhds</p>
        <div class="newsBoxFoot">04/04/2012 read more</div>
        <!-- end .newsBox -->
    </div>
</li>
 <li>
        <div class="newsBox">
        <h3>
            <a href="#">dfgfdg dfgdfgdfg fddfg</a></h3>
        <p>sd;l;ljd;l sdkjfdskjlsdkjfldksjflsdkjflsdkjf sldkhfdslkhfjkldhf 
        sdkjhkjh skdjhfkjhkjdhk skdjhkjhkjhoswlhf lkhkljhs kjhkjhkjh 
        sdklhkjh kh</p>
        <div class="newsBoxFoot">14/06/2012 read more</div>
        <!-- end .newsBox -->
    </div>
</li>



       </ul>
    </div>
    <div class="moreNews">more news</div>
    <!-- end .textColumnBox -->
    </div>

<强> CSS

.textColumnBox {

float: left;
width: 640px;

}
.moreNews {

width:630px;
display:block;
clear:both;
background-image: url(/images/footer.jpg);
background-repeat: repeat-x;
text-align: right;
-moz-border-radius: 4px;
border-radius: 4px;
}
   .newscolumns
{
width: 100%; 
  overflow: hidden;
background:red;
}

.newscolumns ul
{
font-size: 12pt; 
  margin:0;
    padding:0;
}

 .newscolumns ul li
{

 width: 270px;
 float: left;
list-style-type: none;
margin:0px 20px;
  padding:0;

 }
.newscolumns ul li:nth-child(odd)
{


  border-right:1px solid black;
 }

.newsBox p {
display:block;
font-size: 0.7em;
line-height: 1.2em;

}
.newsBox h3 {
line-height: 1.2em;
}

.newsBoxFoot {
display:block;
font-size: 0.7em;
line-height: 1.4em;
color:#999;

}
.newsBox a {
text-decoration:none;

}
.newsBox a:hover {
text-decoration:none;
color:#FFF;
}

答案 3 :(得分:0)

I think now i change some codings, now u try it


<html>
<head>test page
 <STYLE type="text/css">
 .textColumnBox {
padding-top:10px;

margin:0px auto;
width: 640px;
padding-bottom: 20px;
}
.moreNews {
padding: 2px 0 5px 0;
width:630px;
display:block;
clear:both;
background-image: url(/images/footer.jpg);
background-repeat: repeat-x;
text-align: right;
-moz-border-radius: 4px;
border-radius: 4px;
}
   .newscolumns
{
width: 100%; 
  overflow: hidden;
vertical-align:top;
}

.newscolumns ul
{
height: 300px;  
font-size: 12pt;    
 vertical-align:top;
 margin:2px;
 padding:0px;

}

 .newscolumns ul li
{
 padding: inherit;
 width: 310px;
 display: block;
 float: left;
 margin-bottom: 5px;
 background: red;
 vertical-align: top;
 }
.newsBox 
{
margin-left: 3px;
margin-bottom: 2px;/*changed from 15*/
padding-right: 20px;
border-right-width: 1px;
border-right-style: solid;
border-right-color: #4E4629;
}
.newsBox p {
display:block;
font-size: 0.7em;
line-height: 1.2em;
padding-bottom:5px;
}
.newsBox h3 {
line-height: 1.2em;
}

.newsBoxFoot {
display:block;
font-size: 0.7em;
line-height: 1.4em;
color:#999;

}
.newsBox a {
text-decoration:none;

}
.newsBox a:hover {
text-decoration:none;
color:#FFF;
}
p
{
    margin:0px;
}
 </STYLE></head>
<body>
 <div class="textColumnBox">
    <h1>
        Latest News</h1>
    <div class="newscolumns">
        <ul>
            <li>
    <div class="newsBox">
        <h3>
            <a href="#">sample text here qwertyuiowertyuiwertyu</a></h3>
        <p>kfdokashfsdhfjhf kjashf kjash fkjsahf saf kjsh fjsakhf kjashf kjsahf kjsahfjksafiksafkashf hsf haskjhf askjhf asjlkh flsakh flskahf lkashf lkashf lksahf lkashf lkashjh as</p>
        <div class="newsBoxFoot">20/12/2011 read more</div>
        <!-- end .newsBox -->
    </div>
</li> 
  <li style="float:right;" >
    <div class="newsBox">
        <h3>
            <a href="#">yasdefghasdfgh sdfgsdfgasdfga dfgsdfgsdf sdfghsdefgh</a></h3>
        <p>Pkjhfsdfh skljfhsakjfh asjklhfasljkfh aslkf salkhf laskhf lskahf 
        lkasflkashfl ksahflk aslfk aslf hsalkf aslkhf laskhf lskahf glksahf 
        lskahf laskhf lksahf asljkf hsalkhflskahflkh&nbsp; sa</p>



        <div class="newsBoxFoot">14/06/2012 read more</div>
        <!-- end .newsBox -->
    </div>
</li>
 <li>
    <div class="newsBox">
        <h3>
            <a href="#">gdfgfdg dfgfdgfgfdgdfg fdgfdgfdgfd gfdgfdgdfdfr</a></h3>
        <p>;sdljfs;dlj sd;lfj ds;pl;lsdjg;kdlgkdsflblkjg dlskh gkhkljh kjl.h k.j hgjklsdh g kjdsh g,m hcnxogv;isdhgoiunndkn  o;jyhds</p>
        <div class="newsBoxFoot">04/04/2012 read more</div>
        <!-- end .newsBox -->
    </div>
</li>
 <li style="float:right;">
        <div class="newsBox">
        <h3>
            <a href="#">dfgfdg dfgdfgdfg fddfg</a></h3>
        <p>sd;l;ljd;l sdkjfdskjlsdkjfldksjflsdkjflsdkjf sldkhfdslkhfjkldhf 
        sdkjhkjh skdjhfkjhkjdhk skdjhkjhkjhoswlhf lkhkljhs kjhkjhkjh 
        sdklhkjh kh</p>
        <div class="newsBoxFoot">14/06/2012 read more</div>
        <!-- end .newsBox -->
    </div>
</li>



       </ul>
    </div>
    <div class="moreNews">more news</div>
    <!-- end .textColumnBox -->
    </div>
</body>
</html>