为什么<li>标签放错了地方?

时间:2016-02-22 15:04:42

标签: css alignment html-lists

有一个包含四列的表格。在第一列中有一个图像。我已将align attribute设置为top。其余列包含文本。但是,当文本插入第四列时,<li>代码会失去inline display顺序。

任何有关解决此问题的建议都将受到高度赞赏。

&#13;
&#13;
ul.film1 li,
ul.film2 li,
ul.film3 li {
  width: 150px;
  height: 290px;
  border: 3px solid blue;
  display: inline-block;
}
#tableheadheader1,
#tableheadbody1 {
  font-family: Lato;
  font-size: 16px;
  text-align: center;
}
#tableheadfooter1 {
  font-family: Lato;
  font-size: 10px;
  text-align: justify;
}
&#13;
<ul class="film1">
  <li id="tableheadimage1">
    <img src="http://placehold.it/75x75" align="top">
  </li>
  <li id="tableheadheader1">
    <p>Tomorrowland</p>
  </li>
  <li id="tableheadbody1">
    <p>2015</p>
  </li>
  <li id="tableheadfooter1">
    <p>Whenever Casey Newton (Britt Robertson) touches a lapel pin with the letter T on it, she finds herself transported to Tomorrowland, a city filled with huge robots and sleek buildings. The gifted young woman recruits the help of scientist Frank Walker
      (George Clooney), a previous visitor to Tomorrowland, who years ago made a startling discovery about the future. Together, the two adventurers travel to the metropolis to uncover its mysterious secrets.</p>
  </li>
</ul>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

如果您将vertical-align: top;放在<li>元素上,则应解决问题。

ul.film1 li,
ul.film2 li,
ul.film3 li {
  width: 150px;
  height: 290px;
  border: 3px solid blue;
  display: inline-block;
  vertical-align: top; /* <-- this has been added */
}
#tableheadheader1,
#tableheadbody1 {
  font-family: Lato;
  font-size: 16px;
  text-align: center;
}
#tableheadfooter1 {
  font-family: Lato;
  font-size: 10px;
  text-align: justify;
}
<ul class="film1">
  <li id="tableheadimage1">
    <img src="http://placehold.it/75x75" align="top">
  </li>
  <li id="tableheadheader1">
    <p>Tomorrowland</p>
  </li>
  <li id="tableheadbody1">
    <p>2015</p>
  </li>
  <li id="tableheadfooter1">
    <p>Whenever Casey Newton (Britt Robertson) touches a lapel pin with the letter T on it, she finds herself transported to Tomorrowland, a city filled with huge robots and sleek buildings. The gifted young woman recruits the help of scientist Frank Walker
      (George Clooney), a previous visitor to Tomorrowland, who years ago made a startling discovery about the future. Together, the two adventurers travel to the metropolis to uncover its mysterious secrets.</p>
  </li>
</ul>