对齐2个div彼此相邻

时间:2018-01-29 10:50:32

标签: html5 css3

我在主页上有2个部分,包括图片和一些文字。我想让图片和顶部的文字相邻(左边的图片和右边的文字)。然后在底部显示左侧的文本和文本右侧的图片。

<input id="file" onchange="file_changed(this)" onclick="this.value=null;" type="file" accept="*/*" />
.alignnone {
  width: 20%;
  display: inline-block;
  height: 20px;
  padding: 13px;
  box-sizing: border-box;
}

.first {}

.button {
  text-decoration: none;
  color: #000;
  border-radius: 5px;
  border: 1px solid;
  padding: 10px;
  background-color: #43dbdb;
  margin: 1%;
  float: left;
}

.drop {
  width: 30% !important;
  border: none;
  padding: 0%;
  float: right;
}

.top {
  display: inline-block;
  vertical-align: top;
  padding: 2%;
}

.bottom {
  display: inline-block;
  vertical-align: bottom;
  padding: 2%;
}

#content {
  background-color: #D7DBDD;
  background-size: 90%;
  padding: 6%;
  margin: -2%;
}

h2 {
  text-align: center;
}

1 个答案:

答案 0 :(得分:0)

您正在寻找this(创建了一个codepen)吗?

<div class="top">
<div class="clearfix">
<img class="img1" src="https://privatechefanna.co.za/wp-content/uploads/2018/01/IMG_3713.jpg" width="99" height="99">
<h3>ABOUT ME</h3>
  <p class="first ">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus imperdiet, nulla et dictum interdum...</p>
</div>
</div>

<div class="bottom">
<div class="clearfix">
<img class="img2" src="https://privatechefanna.co.za/wp-content/uploads/2018/01/IMG_3713.jpg" width="99" height="99">
<h3>WHAT I DO</h3>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus imperdiet, nulla et dictum interdum...</p></div>
</div>

CSS:

.drop {
  width: 30% !important;
  border: none;
  padding: 0%;
}

.top {
  vertical-align: top;
  padding: 2%;
}

.bottom {
  vertical-align: bottom;
  padding: 2%;
}
.clearfix {
    overflow: auto;
}

.img2 {
    float: right;
    margin-left: 15px;
}

.img1{
  float: left;
  margin-right: 15px;
}