html - 自上而下对齐 DIV/类

标签 html css

我刚开始接触 HTML,为了计算机科学导论中的一个元素,我需要制作一个网页。我有一个概念,我知道我想做什么,但我不知道如何正确地做到这一点。到目前为止,我有这个:

<!DOCTYPE hmtl>
<hmtl>
  <title>
    Audiophile Poll - M100s or Mad Dogs v3.2?
  </title>
  <head>
    <style>
      body{
        background-color: #292E37;
      }
      h1{
        width: 100%;
        color: #800000;
        text-align: center;
        font-family: "Lucida Console", "Courier New";
        font-size: 40px;
      }
      .heading{
        color: #808080;
        text-align: left;
        margin: 5px;
        font-family: "Lucida Sans Unicode";
        font-size: 24px;
        font-weight: bold;
      }
      .body{
        width: 100%;
        font-weight: normal;
      }
      .image{
        float: left;
      }
      .paragraph{
        color: #808080;
        font-size: 14px;
        width: 60%;
        float: left;
        margin: 10px;
      }
    </style>
  </head>
  <body>
    <h1>
    <b>
      V-MODA M-100 vs. MrSpeakers Mad Dog
    </b>
    </h1>
    <div id="box1">
      <div class="heading">
        V-MODA M-100
      </div>
      <div class="body">
        <div class="image">
          <img src="http://www.acgears.com/images/m_100_shadow_laying_case_square_web.jpg" height="300px" width="300px"/>
        </div>
        <div class="paragraph">
          <b>Cost:</b> $310<br />
          <b>Audio Profile:</b> "Modiophile" (near balance with light emphasis on bass)<br />

        </div>
      </div>
    </div>  
    <div id="box2">
      <div class="heading">
        MrSpeakers Mad Dogs v3.2
      </div>
      <div class="body">
        <div class="image">
          <img src="http://cdn.head-fi.org/0/05/300x300px-LS-0512aba0_1125220115_maddog.jpeg" height="300px" width="300px"/>
        </div>
        <div class="paragraph">
          <b>Cost:</b> <br />
          <b>Audio Profile:</b> <br />

        </div>
      </div>
    </div>
  </body>
</html>

现在,我要展开里面的文字,仅此而已。我有第一组对象(第一个标题、图像和段落)右对齐,但每当我尝试加载第二组时,我得到一个奇怪的对齐方式。我需要做什么才能得到这样的东西:

标题1

图片文字

-中断-

标题 2

图片文字

最佳答案

试试这个

在两个 div 之间添加这一行

<div style="clear:both"></div>

DEMO

关于html - 自上而下对齐 DIV/类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20559132/

相关文章:

javascript - 绝对中心(垂直和水平) "Responsive"它不起作用

javascript - 从 Whatsapp 测验代码更改分享数量

javascript - 仅带有日期选择器的自定义 jQuery UI 下载不包含所有 css

css - 如何在一个部分添加视频背景?

html - 无法移动文本按钮

html - 是否有必要将网站图标和苹果图标保留在网站根目录下?

javascript - 在 vendor/lib 目录中包含 Rails 中的 js/css 模块

javascript - 制作一个幽灵填充的动画按钮并且边界半径有问题

html - 如何在不影响主导航的情况下设置 CSS 子导航的样式

html - 在宽度为 100% 的水平条中将具有相同宽度的菜单项居中