html - 如何在 bootstrap 中写一个包含表格的段落?

标签 html css twitter-bootstrap codepen

我无法写一段环绕右边表格的段落。表格随着段落的扩展而扩展。

Current layout

我正在复制 Apj Abdul Kalam 的维基百科页面格式。另外,我们可以减少表格中列的宽度吗?

这是我的代码笔链接:https://codepen.io/TariqueBaig/pen/zRrKpx

<body>
  <div class="container">
    <h1 class="display-4 text-center">A.P.J. Abdul Kalam</h1>
    <h3 class="text-center font-weight-light">Missile man of India</h3>
    <div class="row">
      <!--       <div class="col-lg-1"></div> -->
      <div class="col-lg-8">
        <p><span class="font-weight-bold">Avul Pakir Jainulabdeen Abdul Kalam</span> better known as <span class="font-weight-bold">A.P.J.Abdul Kalam</span> was born in 15th October 1931.He was the 11th President of India from 2002-2007.He was born and raise
          in Rameshwaram, TamilNadu, and studied physics and aerospace engineering.He spent the next four decades as a scientist and science administrator, mainly at the Defence Research and Development Organisation (DRDO) and Indian Space Research Organisation
          (ISRO) and was intimately involved in India's civilian space programme and military missile development efforts.He thus came to be known as the <span class="font-italic">Missile Man of India</span> for his work on the development of ballistic
          missile and launch vehicle technology.He also played a pivotal organisational, technical, and political role in India's Pokhran-II nuclear tests in 1998, the first since the original nuclear test by India in 1974.</p>
        <p>Kalam was elected as the 11th President of India in 2002 with the support of both the ruling Bharatiya Janata Party and the then-opposition Indian National Congress. Widely referred to as the "People's President," he returned to his civilian life
          of education, writing and public service after a single term. He was a recipient of several prestigious awards, including the Bharat Ratna, India's highest civilian honour.</p>
        <p>While delivering a lecture at the Indian Institute of Management Shillong, Kalam collapsed and died from an apparent cardiac arrest on 27 July 2015, aged 83. Thousands including national-level dignitaries attended the funeral ceremony held in
          his hometown of Rameshwaram, where he was buried with full state honours.</p>
      </div>
      <div class="col-lg-4 border border-secondary">
        <figure class="figure">
          <img class="figure-img img-fluid img-thumbnail" src="https://upload.wikimedia.org/wikipedia/commons/b/b0/A._P._J._Abdul_Kalam_in_2008.jpg" alt="Image of Abdul Kalam">
          <figcaption class="figure-caption text-center">Kalam in 2008</figcaption>
        </figure>
        <h6 class="text-center bg-primary text-white">11th President of India</h6>
        <p class="text-center font-weight-bold">In office<br><span class="font-weight-normal">25 July 2002 - 25 July</span></p>
        <table class="table">
          <thead>
          </thead>
          <tbody>
            <tr>
              <th scope="row">Prime Minister</th>
              <td>Atal bihari Vajpayee<br>Manmohan Singh</td>
            </tr>
            <tr>
              <th scope "row">Vice President</th>
              <td>Krishan Kant<br>Bhairon Singh Shekhawat</td>
            </tr>
            <tr>
              <th scope="row">Preceded By</th>
              <td>K.R.Narayanan</td>
            </tr>
            <tr>
              <th scope="row">Succeeded By</th>
              <td>Pratibha Patil</td>
            </tr>
          </tbody>
        </table>
      </div>
      <div class="row">
        <div>
          Avul Pakir Jainulabdeen Abdul Kalam was born on 15 October 1931 to a Tamil Muslim family in the pilgrimage centre of Rameswaram on Pamban Island, then in the Madras Presidency and now in the State of Tamil Nadu. His father Jainulabdeen was a boat owner
          and imam of a local mosque
        </div>
      </div>
    </div>
  </div>
</body>

最佳答案

Bootstrap .col-{...} 是不环绕或相互 float 的结构。顾名思义,它们是列。

另一方面,floating elements可以被文本和内联元素环绕。 float 元素是 float css 属性的值不是 none 的元素。 Bootstrap 4 也有一组速记类 Float .

下面的示例使用 .float-right 类将 table 推到右边。此外,将 表格 的标记移动到标题之后也很重要。要更改 table 部分的宽度,您仍然可以使用 .col-{} 类。 (它们只设置元素的 widthflex 属性,如果没有 flex 容器,flex 就不起作用。)要设置宽度,另一种选择是使用 Sizing 之一类,但不幸的是,那些不使用媒体断点。

<div class="container">
    <h1 class="display-4 text-center">A.P.J. Abdul Kalam</h1>
    <h3 class="text-center font-weight-light">Missile man of India</h3>

    <!-- New position of the "table" -->
    <div class="col-lg-3 float-right border border-secondary">
        <figure class="figure">
            <img class="figure-img img-fluid img-thumbnail" src="https://upload.wikimedia.org/wikipedia/commons/b/b0/A._P._J._Abdul_Kalam_in_2008.jpg" alt="Image of Abdul Kalam">
            <figcaption class="figure-caption text-center">Kalam in 2008</figcaption>
        </figure>
        <h6 class="text-center bg-primary text-white">11th President of India</h6>
        <p class="text-center font-weight-bold">In office<br><span class="font-weight-normal">25 July 2002 - 25 July</span></p>
        <table class="table">
            <thead>
            </thead>
            <tbody>
                <tr>
                    <th scope="row">Prime Minister</th>
                    <td>Atal bihari Vajpayee<br>Manmohan Singh</td>
                </tr>
                <tr>
                    <th scope "row">Vice President</th>
                    <td>Krishan Kant<br>Bhairon Singh Shekhawat</td>
                </tr>
                <tr>
                    <th scope="row">Preceded By</th>
                    <td>K.R.Narayanan</td>
                </tr>
                <tr>
                    <th scope="row">Succeeded By</th>
                    <td>Pratibha Patil</td>
                </tr>
            </tbody>
        </table>
    </div>

    <!--
    Long-text description comes here.
    This wrapping <div> can also be omitted.
    -->
    <div class="this-div-could-also-be-deleted">
        <p><span class="font-weight-bold">Avul Pakir Jainulabdeen Abdul Kalam</span> better known as <span class="font-weight-bold">A.P.J.Abdul Kalam</span> was born in 15th October 1931.He was the 11th President of India from 2002-2007.He was born and raise in Rameshwaram, TamilNadu, and studied physics and aerospace engineering.He spent the next four decades as a scientist and science administrator, mainly at the Defence Research and Development Organisation (DRDO) and Indian Space Research Organisation (ISRO) and was intimately involved in India's civilian space programme and military missile development efforts.He thus came to be known as the <span class="font-italic">Missile Man of India</span> for his work on the development of ballistic missile and launch vehicle technology.He also played a pivotal organisational, technical, and political role in India's Pokhran-II nuclear tests in 1998, the first since the original nuclear test by India in 1974.</p>
        <p>Kalam was elected as the 11th President of India in 2002 with the support of both the ruling Bharatiya Janata Party and the then-opposition Indian National Congress. Widely referred to as the "People's President," he returned to his civilian life of education, writing and public service after a single term. He was a recipient of several prestigious awards, including the Bharat Ratna, India's highest civilian honour.</p>
        <p>While delivering a lecture at the Indian Institute of Management Shillong, Kalam collapsed and died from an apparent cardiac arrest on 27 July 2015, aged 83. Thousands including national-level dignitaries attended the funeral ceremony held in his hometown of Rameshwaram, where he was buried with full state honours.</p>
        
        <div>
            Avul Pakir Jainulabdeen Abdul Kalam was born on 15 October 1931 to a Tamil Muslim family in the pilgrimage centre of Rameswaram on Pamban Island, then in the Madras Presidency and now in the State of Tamil Nadu. His father Jainulabdeen was a boat owner and imam of a local mosque
        </div>
    </div>
</div>


<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>

关于html - 如何在 bootstrap 中写一个包含表格的段落?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48595323/

相关文章:

html - 使用 css .first 创建列表项分隔符

javascript - 如何在模态中传递数据属性

css - 检查硬件加速可用性? (可测试)

html - 如何制作 CSS 翻转图像? ( Sprite )

html - 推特 Bootstrap 3 : including img-responsive class seems to be resizing my container-fluid divs?

javascript - 防止action属性使用javascript运行php脚本

html - 当我将鼠标悬停在图像上时,它们是否有点晃来晃去?

html - 打印页面与 Chrome 和 IE 不同

css - 如何在导航选项卡 Bootstrap 用户界面(angularjs)中将文本对齐到顶部?

html - Bootstrap 3 页脚出现严重问题, Logo 对齐导致出现水平滚动条