1. ホーム
  2. css

[解決済み] How can I center <ul> <li> into a div?

2022-03-03 19:07:17

Question

How can I center an unordered list of <li> into a fixed-width div ?

<table width="100%">
  <tbody>
  <tr>
    <td width="41%"><img src="/web/20100104192317im_/http://www.studioteknik.com/html2/html/images/hors-service.jpg" width="400" height="424"></td>
    <td width="59%"><p align="left">&nbsp;</p>
      <h1 align="left">StudioTeknik.com</h1>
      <p><br align="left">
        <strong>Marc-André Ménard</strong></p>
      <ul>
        <li>Photographie digitale</li>
        <li>Infographie </li>
        <li>Débug et IT (MAC et PC)</li>
        <li> Retouche </li>
        <li>Site internet</li>
        <li>Graphisme</li>
      </ul>
      <p align="left"><span class="style1"><strong>Cellulaire en suisse : </strong></span><a href="#">+41 079 573 48 99</a></p>
      <p align="left"><strong class="style1">Skype : </strong> <a href="#">menardmam</a></p>
    <p align="left"><strong class="style1">Courriel :</strong><a href="https://web.archive.org/web/20100104192317/mailto:[email protected]">    [email protected]</a></p></td>
  </tr>
  </tbody>
</table>

How to solved?

Since ul and li elements are display: block by default — give them auto margins and a width that is smaller than their container .

ul {
    width: 70%;
    margin: auto;
}

ディスプレイのプロパティを変更したり、通常の整列ルールを上書きするようなことをした場合(フローティングなど)、これはうまくいきません。