javascript - 使用html css垂直排列4个div

标签 javascript jquery html css

自 4 小时以来,我一直在尝试垂直并排排列 4 个 div。这些 div 内部也有 2 个 div,用于图像和段落。我能够将 4 个图像 div 彼此相邻排列,但段落div 很难对齐。

我正在使用的代码:

.left4 {
  width: 215px;
  float: left;
}
.center4 {
  float: left;
  width: 215px;
  padding-right: 50px;
  padding-left: 50px;
}
.center4.1 {
  width: 215px;
  float: right;
  padding-left: 10px;
  float: left;
}
.right4 {
  width: 215px;
  float: left;
  padding-left: 40px;
}
.image4 {
  height: 100px;
  width: 215px;
  border: 4px;
  border-style: double;
  border-color: #BABABA;
  float: left;
  margin-top: 10px;
}
.para1 {
  height: 200px;
  color: #BABABA;
}
<div class="4">
  <div class="left4">
    <div class="image4">
      <img>
    </div>
    <div class="para1">
      <h3 style="color:#BABABA">INDONECTETUS FACILIS</h3>
      <p>Some wiki engines are open source, whereas others are proprietary. Some permit control over different functions (levels of access)</p>
      <p align="right"><a href="#" style="color:orange;text-decoration:none">Read More >></a>
      </p>
    </div>
  </div>
  <div class="center4">
    <div class="image4">
      <img>
    </div>
    <div class="para1">
      <h3 style="color:#BABABA">INDONECTETUS FACILIS</h3>
      <p>Some wiki engines are open source, whereas others are proprietary. Some permit control over different functions (levels of access)</p>
      <p align="right"><a href="#" style="color:orange;text-decoration:none">Read More >></a>
      </p>
    </div>
  </div>

  <div class="center4.1">
    <div class="image4">
      <img>
    </div>
    <div class="para1">
      <p>Some wiki engines are open source, whereas others are proprietary. Some permit control over different functions (levels of access)</p>
      <p align="right"><a href="#" style="color:orange;text-decoration:none">Read More >></a>
      </p>
    </div>
  </div>


  <div class="right4">
    <div class="image4">
      <img>
    </div>
    <div class="para1">
      <h3 style="color:#BABABA">INDONECTETUS FACILIS</h3>
      <p>Some wiki engines are open source, whereas others are proprietary. Some permit control over different functions (levels of access)</p>
    </div>
  </div>

最佳答案

您不能使用 .center4.1。在 CSS 中,这意味着您正在尝试访问多个类 center41。将其更改为 .center4-1

.left4 {
   width: 215px;
   float: left;
 }
 .center4 {
   float: left;
   width: 215px;
   padding-right: 50px;
   padding-left: 50px;
 }
 .center4-1 {
   width: 215px;
   float: right;
   padding-left: 10px;
   float: left;
 }
 .right4 {
   width: 215px;
   float: left;
   padding-left: 40px;
 }
 .image4 {
   height: 100px;
   width: 215px;
   border: 4px;
   border-style: double;
   border-color: #BABABA;
   float: left;
   margin-top: 10px;
 }
 .para1 {
   height: 200px;
   color: #BABABA;
 }
<div class="4">
  <div class="left4">
    <div class="image4">
      <img>
    </div>
    <div class="para1">
      <h3 style="color:#BABABA">INDONECTETUS FACILIS</h3>
      <p>Some wiki engines are open source, whereas others are proprietary. Some permit control over different functions (levels of access)</p>
      <p align="right"><a href="#" style="color:orange;text-decoration:none">Read More >></a>
      </p>
    </div>
  </div>
  <div class="center4">
    <div class="image4">
      <img>
    </div>
    <div class="para1">
      <h3 style="color:#BABABA">INDONECTETUS FACILIS</h3>
      <p>Some wiki engines are open source, whereas others are proprietary. Some permit control over different functions (levels of access)</p>
      <p align="right"><a href="#" style="color:orange;text-decoration:none">Read More >></a>
      </p>
    </div>
  </div>

  <div class="center4-1">
    <div class="image4">
      <img>
    </div>
    <div class="para1">
      <p>Some wiki engines are open source, whereas others are proprietary. Some permit control over different functions (levels of access)</p>
      <p align="right"><a href="#" style="color:orange;text-decoration:none">Read More >></a>
      </p>
    </div>
  </div>


  <div class="right4">
    <div class="image4">
      <img>
    </div>
    <div class="para1">
      <h3 style="color:#BABABA">INDONECTETUS FACILIS</h3>
      <p>Some wiki engines are open source, whereas others are proprietary. Some permit control over different functions (levels of access)</p>
    </div>
  </div>

关于javascript - 使用html css垂直排列4个div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32501162/

相关文章:

javascript - 获取 Facebook AR 中 3d 对象的位置并通过脚本更改它们

javascript - 如何访问其他对象兄弟的值?

javascript - 变量设置不正确

javascript - 访问 anchor 属性和 event.preventDefault()

html - 向右滚动时不显示背景颜色

javascript - 使用下拉列表按字母顺序 a-z 和 z-a 排序

javascript - 无法识别带有(一个空格)的数据目标标签

html - 如何在所有PC浏览器中播放HTTP Live Streaming(HLS)?

html - 显示图例文本时防止容器增长

javascript - 使用相同的键动态合并对象数组