javascript - 使用 css 以相同的方式对齐元素

标签 javascript html css angularjs

我是网络开发的新手。

我有以下代码:

.notation {
  width: 170%;
  margin-left: -238px;
}

.mytable {
  margin: 0.5em auto;
  font-size: 90%;
  position: relative;
  width: 59%;
}

table.mytable>*>tr>td {
  border: 1px solid #a2a9b1;
  padding: 0.2em 0.4em;
}

table.mytable {
  background-color: #f8f9fa;
  color: #222;
  margin: 1em 0;
  border: 1px solid #a2a9b1;
  border-collapse: collapse;
}
<div class="col-md-12 table-responsive notation" ng-if="(documentType !== 'jobDescription')">
  <table class="mytable" style="margin:0.5em auto; font-size:90%;position:relative;width:60%;margin-bottom:13px;">
    <tbody>
      <tr>
        <td style="width:2.5em; background-color:#fce8e8;text-align:center;"><b></b></td>
        <td>Full Name</td>
        <td style="width:2.5em; background-color:#e2d6f1;text-align:center;"></td>
        <td>Email</td>
        <td style="width:2.5em; background-color:aqua;text-align:center;"><b></b></td>
        <td>Telephone Number</td>
        <td style="width:2.5em; background-color:#ccfcdd;text-align:center;"><b></b></td>
        <td>Total Experience</td>
        <td style="width:2.5em; background-color:skyblue;text-align:center;"><b></b></td>
        <td>Skill Set</td>
      </tr>
    </tbody>
  </table>
  <table class="mytable" style="margin:0.5em auto; font-size:90%;position:relative;width:60%;margin-bottom:13px;">
    <tbody>
      <tr>
        <td style="width:2.5em; background-color:#d1cff7;text-align:center;"><b></b></td>
        <td>Company Experience</td>
        <td style="width:2.5em; background-color:#e8dca7;text-align:center;"></td>
        <td>Education</td>
        <td style="width:2.5em; background-color:#10eabe;text-align:center;"><b></b></td>
        <td>Project</td>
        <td style="width:2.5em; background-color:#aee8dc;text-align:center;"><b></b></td>
        <td>Project</td>
        <td style="width:2.5em; background-color:#f2d7da;text-align:center;"><b></b></td>
        <td>Address</td>
      </tr>
    </tbody>
  </table>
</div>

现在输出看起来像

enter image description here

但是在这里,发生了什么,这些东西没有对齐,我的意思是 FullName 占用的空间很小,但是 companyExperience 占用的空间很大,所以我想让每个元素对齐。

那么,我该怎么做呢?

已更新-

enter image description here

我得到了这种类型的输出。

最佳答案

这是您想要的那种输出吗?

.notation {
  width: 170%;
  margin-left: -238px;
}

.mytable {
  margin: 0.5em auto;
  font-size: 90%;
  position: relative;
  width: 59%;
}

table.mytable>*>tr>td {
  /*border: 1px solid #a2a9b1;*/
  padding: 0.2em 0.4em;
}

table.mytable {
  background-color: #f8f9fa;
  color: #222;
  margin: 1em 0;
  /*border: 1px solid #a2a9b1;*/
  border-collapse: collapse;
}
<div class="col-md-12 table-responsive notation" ng-if="(documentType !== 'jobDescription')">
  <table class="mytable" style="margin:0.5em auto; font-size:90%;position:relative;width:60%;margin-bottom:13px;">
    <tbody>
      <tr>
        <td style="width:2.5em; background-color:#fce8e8;text-align:center;"><b></b></td>
        <td>Full Name</td>
        <td style="width:2.5em; background-color:#e2d6f1;text-align:center;"></td>
        <td>Email</td>
        <td style="width:2.5em; background-color:aqua;text-align:center;"><b></b></td>
        <td>Telephone Number</td>
        <td style="width:2.5em; background-color:#ccfcdd;text-align:center;"><b></b></td>
        <td>Total Experience</td>
        <td style="width:2.5em; background-color:skyblue;text-align:center;"><b></b></td>
        <td>Skill Set</td>
      </tr>
    <!--/tbody>
  </table>
  <table class="mytable" style="margin:0.5em auto; font-size:90%;position:relative;width:60%;margin-bottom:13px;">
    <tbody-->
      <tr>
        <td style="width:2.5em; background-color:#d1cff7;text-align:center;"><b></b></td>
        <td>Company Experience</td>
        <td style="width:2.5em; background-color:#e8dca7;text-align:center;"></td>
        <td>Education</td>
        <td style="width:2.5em; background-color:#10eabe;text-align:center;"><b></b></td>
        <td>Project</td>
        <td style="width:2.5em; background-color:#aee8dc;text-align:center;"><b></b></td>
        <td>Project</td>
        <td style="width:2.5em; background-color:#f2d7da;text-align:center;"><b></b></td>
        <td>Address</td>
      </tr>
    </tbody>
  </table>
</div>

我只更改了您的一些代码作为注释。 (在上面检查)
您不需要使用两个 table,只需两个 tr

关于javascript - 使用 css 以相同的方式对齐元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49981961/

相关文章:

html - 更改 DIV 高度以适合图像

jquery - 我可以强制 iframe 使用 css 或 jQuery 显示页面的特定部分吗

javascript - 在 Fabric JS 中重置字体大小

javascript - 正则表达式,字符串是白名单字符的组合,不包含黑名单中的任何字符

javascript - 获取文本字段中的选择值以及更改时的值

html - 消失的 DIV 或 DIV 边框

javascript - 使用 javascript 将 Django timesince 的输出解析为浮点天数

javascript - 如何在 solid gauge (highcharts) 中正确设置 y 轴?

javascript - 更改显示模式后的中心按钮

css - Chrome 中的间歇性后台加载错误