如何显示一个块而不是 table 的整个宽度?

How do I display a block instead of the full width of a table?

我想仅使用 CSS 和 HTML 在我的应用程序的左侧部分显示 table。 这是我得到的:

我想得到这样的结果:

我找不到如何裁剪它并使其美观且响应迅速。

是否可以定义边框以使文本和大小写适合任何缩小?

.container {
  display: flex;
  flex-wrap: wrap;
  padding: 1em 1em 0 1em;
  background: #FAFAFA;
}

.column {
  width: 50%;
  margin-bottom: 1em;
}

.title {
  font-size: 0.875rem;
  font-family: "Helvetica";
  color: darkblue;
}

.rectangle-13 {
  display: inline-block;
  padding-left: 150px;
  background-color: white;
  width: 80%;
  height: 26px;
  padding: 8px 8px 8px 8px;
  border-color: #cccccc;
  border-width: 1px;
  border-style: solid;
  border-radius: 5px;
  box-shadow: black;
  font-family: "Helvetica";
  letter-spacing: 1;
  font-size: 16px;
}
<header>
  <img href="google.com" class="logo" src="images/.png" alt="logo"><br><br>
  <a href="profile.html"><img class="profil" src="images/account.png" alt="logo"><br><br></a>
  <!-- 
         <nav>
         
           <ul class="nav_links">
              <li><a href='#'>Comment ça marche?</a></li>
              <li><a href='#'>Contact</a></li>
              <li><a href='#'>Blog</a></li>
         
             </ul>
         
          </nav>  
         -->
</header>
<div class="entete"></div>
<div class="textentete">Mon Compte</div>
<br>
</div>
<div class="container">
  <div class="column">
    <div class="title">Identifiant</div>
    <div class="rectangle-13">X1VZXCS2</div>
  </div>
  <div class="column">
    <div class="title">Prénom</div>
    <div class="rectangle-13">Ludovic</div>
  </div>
  <div class="column">
    <div class="title">Nom</div>
    <div class="rectangle-13">Thiel</div>
  </div>
  <div class="column">
    <div class="title">Email</div>
    <div class="rectangle-13">ludovic@gmail.com</div>
  </div>
  <div class="column">
    <div class="title">Numéro de société</div>
    <div class="rectangle-13">2651611354</div>
  </div>
  <div class="column">
    <div class="title">Société</div>
    <div class="rectangle-13">DevNum</div>
  </div>
  <div class="column">
    <div class="title">Poste</div>
    <div class="rectangle-13">Développeur Front</div>
  </div>
</div>
<div class="centrage">
  <form method="get" action="/inscription.html">
    <input type="submit" value="Retour vers l'accueil">
  </form>
</div>

有人知道怎么做吗?

使用 Flexbox,这样您就可以使用下面的代码轻松解决您的问题。

.main-title h1 {
    background-color: #e8eaf6;
    color: #311b92;
    padding: 10px;
    border-radius: 20px;
    text-align: center;
    font-family: "Helvetica";
}

.rectangle-13 {
    background-color: white;
    width: 100%;
    min-width: 230px;
    height: 40px;
    padding: 8px 8px 8px 8px;
    border: 1px solid #000;
    border-radius: 5px;
    font-family: "Helvetica";
    font-size: 16px;
    box-sizing: border-box;
}

.rectangle-12,
.rectangle-14 {
    width: 100%;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    max-width: 524px;
    min-height: 323px;
    padding: 30px;
    background: #e8eaf6;
    color: #311b92;
    border: 1px solid;
    z-index: -1;
}

.main {
    display: flex;
    justify-content: space-evenly;
}
 <div class="main-title">
        <h1>Mon Compte</h1>
    </div>
    <div class="main">
        <div class="rectangle-12">
            <div>
                <div class="lable">Lable</div>
                <div class="rectangle-13">X1VZXCS2</div>
            </div>
            <div>
                <div class="lable">Lable</div>
                <div class="rectangle-13">Ludovic</div>
            </div>
            <div>
                <div class="lable">Lable</div>
                <div class="rectangle-13">Thiel</div>
            </div>
            <div>
                <div class="lable">Lable</div>
                <div class="rectangle-13">ludovic@gmail.com</div>
            </div>
            <div>
                <div class="lable">Lable</div>
                <div class="rectangle-13">2651611354</div>
            </div>
            <div>
                <div class="lable">Lable</div>
                <div class="rectangle-13">DevNum</div>
            </div>
            <div>
                <div class="lable">Lable</div>
                <div class="rectangle-13">Développeur Front</div>
            </div>
        </div>
        <div class="rectangle-14">
            <div>
                <h1>Add Content Here</h1>
            </div>
        </div>
    </div>

剧透:我在 CSS 中留下了很多评论来告诉你一切 确实。

好的。这有很多问题。我决定重写代码,因为原来的代码太乱了。看来你对HTML和CSS真的了解不多。我已经为你完成了一半,所以你可以想出另一半。

一些小技巧:

1. Make sure to organize, and name everything correctly. If it's an input field, name it "input-field" not "rectangle13" when your document gets bigger, it's gonna be harder to find out what's going on.

2. When dealing with settings like padding:__ or margin:__, say you wanted the same values for top, left, bottom, and right of the margin or padding, just set it to one singular value.

Before: margin: 5px, 5px, 5px, 5px;

After: margin: 5px;

3. Don't use <div> for everything. Yes, they're useful, but there are better ways of making input fields and text. Examples: <h1>(heading), <p>(paragraph), <input type=text>(text input)

哦,还有:

我知道我提供的 HTML 和 CSS 并不完美 (抱歉我没有太多时间.)

这是HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="index.css">
</head>
<body>
    <div class="content">
        <div class="title">
            <h1>Mon Compte</h1>
        </div>

        <div class="form">
            <div class="column">
                <div class="inputField">
                    <h1>Identifiant</h1>
                    <input type="text" value="X1VZXCS2">
                </div>

                <div class="inputField">
                    <h1>Nom</h1>
                    <input type="text" value="Thiel">
                </div>

                <div class="inputField">
                    <h1>Numéro de société</h1>
                    <input type="text" value="2651611354">
                </div>

                <div class="inputField">
                    <h1>Poste</h1>
                    <input type="text" value="Développeur Front">
                </div>

                <div class="inputField">
                    <h1>Prénom</h1>
                    <input type="text" value="Ludovic">
                </div>

                <div class="inputField">
                    <h1>Email</h1>
                    <input type="text" value="ludovic@gmail.com">
                </div>

                <div class="inputField">
                    <h1>Société</h1>
                    <input type="text" value="DevNum">
                </div>
            </div>

            <div class="column">
                <div class="submit">
                    <input type="submit" value="button">
                    <input type="submit" value="button">
                </div>
            </div>
        </div>
    </div>
</body>
</html>

这是CSS

body, html {
    /* Make the HTML fill the screen */
    font-family: Helvetica;
    width: 100%;
    height: 100%;
    margin: 0px;
    padding: 0px;
}

.content {
    /* Make DIV in the HTML fill the screen */
    width: 100%;
    height: 100%;
}

.title {
    /* Setting the width and height of the container containing the title */
    width: 100%;
    height: 100px;

    /* Display flex will align everything inside it HORIZONTALLY */
    display: flex;

    /* Justify content will align everything inside it to the center HORIZONTALLY */
    justify-content: center;

    /* Setting the background color */
    background-color: #FAFAFA;
}

.form {
    /* Setting the width and height of the container containing the form */
    height: 500px;
    width: 100%;

    /* Setting the background color */
    background-color: #FAFAFA;

    /* Display flex will align everything inside it HORIZONTALLY */
    display: flex;

    /* Justify content will align everything inside it to the center HORIZONTALLY */
    justify-content: center;

    /* Align items will align everything inside it to the center VERTICALLY */
    align-items: center;
}

.form .column {
    /* Setting the width and height of the columns */
    width: 50%;
    height: 100%;

    /* Setting the background color */
    background-color: #FAFAFA;

    /* Setting the invisible space around the column, if all 4 values are the same, subsitute with ONE value */
    margin: 30px;

    /* Display flex will align everything inside it HORIZONTALLY */
    display: flex;

    /* Wrap items */
    flex-wrap: wrap;
}

.column .inputField {
    /* Setting the background color */
    background-color: #FAFAFA;

    /* Setting the width and height of the input fields */
    height: 70px;
    width: calc(50% - 10px); /* Accounting for margin */

    /* Setting the whitespace */
    padding-top: 2px;
    padding-bottom: 10px;

    /* Setting the invisible space */
    margin-right: 10px;
}

.column .inputField h1 {
    /* Setting the font color of the name/title of the input field. */
    color: darkblue;

    /* Setting the font size*/
    font-size: 14px;
}

.column .inputField input {
    /* Setting the font size*/
    font-size: 18px;

    /* Setting the OVERALL padding */
    padding: 4px;

    /* Setting the LEFT padding */
    padding-left: 20px;

    /* Setting the border */
    border: 1px solid #959595;

    /* Setting the width and height of the input fields */
    height: 30px;
    width: calc(100% - 40px); /* Accounting for overflow */
}