Search code examples
htmltextalignmentcelldocument-body

How to align text in the box in HTML so that it does not affect the spacing on each side


I am a newbie in HTML and currently working on my University project work and I really need some help. I am using a background box for the "blog-like" website which needs to align title and short text on the left and contents with hyperlinks on the right.

So far I have used a cell to align them but to say the least, it looks very ugly and moreover affects spacing. No matter what I tried I can't change the contents on both sides without a response from another. Is it possible to arrange content somehow another way instead of using a single cell for an entire box and dividing percentage for each side? I have uploaded a picture of the website below

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

  <head>
    <title>
      Your Personal Guide To Best Hardcore Events
    </title>
    <style type="text/css">
      body {
        background: url(http://webprojects.eecs.qmul.ac.uk/at315/background.jpg);
        background-repeat: no-repeat;
        background-size: 100% 100%;
        background-attachment: fixed
      }

      .background {
        display: flex;
        justify-content: center;
      }

      div.transbox {
        margin: 0px;
        background-color: #ffffff;
        border: 1.5px solid black;
        opacity: 0.6;
        filter: alpha(opacity=60);
        width: 100%;
        max-width: 1300px;
      }

    </style>
  </head>

  <body>
    <p align="center">
      <img src="http://webprojects.eecs.qmul.ac.uk/at315/header.png" style="width:70%;" border="0" alt="" />
    </p>
    <div class="background">
      <div class="transbox">
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <th width="75%" align="left">
              <h2>
                    Articles:
                  </h2>
            </th>
            <th width="20%" align="center">
              <ul style="list-style: none;">
                <li>
                  <a href="http://webprojects.eecs.qmul.ac.uk/rr305/CourseWork/blog.xml" style="text-decoration:none">Homepage</a>
                  <br />
                  <br />
                </li>
                <li>
                  <small><a href="http://www.qmul.ac.uk" style=
                      "text-decoration:none">Architects</a></small>
                </li>
                <li>
                  <small><a href="https://www.facebook.com" style=
                      "text-decoration:none">Northlane</a></small>
                </li>
                <li>
                  <small><a href="http://www.bbc.co.uk" style=
                      "text-decoration:none">Attila</a></small>
                </li>
              </ul>
            </th>
          </tr>
          <tr>
            <td align="left">
              <h4>
                    <strong>Architects Rocking Brixton</strong>
                  </h4>Read our article about Architects headlining their biggest sold-out UK show!
              <hr />
            </td>
          </tr>
          <tr>
            <td></td>
          </tr>
          <tr>
            <td align="left">
              <h4>
                    <strong>Architects Rocking Brixton</strong>
                  </h4>Read our article about Architects headlining their biggest sold-out UK show!
              <hr />
            </td>
          </tr>
          <tr>
            <td></td>
          </tr>
          <tr>
            <td align="left">
              <h4>
                    <strong>Architects Rocking Brixton</strong>
                  </h4>Read our article about Architects headlining their biggest sold-out UK show!
              <br />
              <br />
            </td>
          </tr>
        </table>
      </div>
    </div>
  </body>

</html>

Main page of the website


Solution

  • In this situations it is best to use flex and max width. It is very good to responsive design so.

    .background {
    display: flex;
    justify-content: center;
    }
    
    div.transbox {
    margin: 30px;
    background-color: #ffffff;
    border: 1px solid black;
    opacity: 0.6;
    filter: alpha(opacity=60);
    width: 100%;
    max-width: 1000px;
    }
    

    Change your browser size, It work good for all sizes. And the best part is if the screen has width < 1000px the table fills all of the screen.