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 - 触发 javascript 函数的其他选项

javascript - 将下划线与 jshint 一起使用

jquery - 使用 <p> 将特定元素后的文本换行

html - 替换文件中特定行号处的字符

javascript - while 循环增量值在函数内不起作用

javascript - 数组中对象的迭代并更改对象中的值

json - jQuery AJAX 请求在 IE 中失败

javascript - JS图片源属性触发 Action

jquery - 需要帮助构建 jQuery 查询

javascript - 单击行在新窗口中打开 div