每个图像旁边的每个段落

时间:2018-03-29 19:33:22

标签: html css image text

我有4个不同的段落和4个图像,每个图像对应于每个图像。我希望每个图像都在每个图像旁边。

欢迎任何帮助,

body{
    background-image:url(http://www.icotoken.tel/images/slider_slide_5.jpg)
    background-size: cover;
    background-attachment: fixed;background-repeat: no-repeat;
    background-position: center;
    text-align: center;
    justify-content: center;
    align-items: center;
    text-align: center;
}
.bigger{
    padding: 30px;
    height: 300px;
}
.text {
    margin: auto;
    padding: 30px;
    height: 1200px;
    background-color: rgba(0,0,0,0.3);
    text-align: center;
    min-width: 950px;
    max-width: 950px;
}
.img{
    width:500px;
    height:300px;
    padding-bottom:30px;
    margin-left:50px;
    margin-right:50px;
}
<div class= "text">
    <div><img class = "img" src = "https://www.gaincontact.com/files/2016/10/Globelanguageshomepage-1.jpg" align= "left">
    <p>1st Paragraph</p></div>
    <div><img class = "img" src = "https://img00.deviantart.net/c3e2/i/2015/136/f/a/rinne_rokudou_rokumon__kyoukai_no_rinne_minimalism_by_greenmapple17-d8tm8om.png" align= "right">
    <p>2nd Paragraph</p></div>
    <div><img class = "img" src = "http://smart-defence.co.uk/wp-content/uploads/2015/03/art.jpg" align="left">
    <p>3rd Paragraph</p></div>
    <div><img class = "img" src = "https://www.markchadwick.co.uk/wp-content/uploads/2015/03/Spin-Painting-18-1000x643.jpg" align="right"> . 
    <p>4th Paragraph</p></div>
</div>

2 个答案:

答案 0 :(得分:1)

overflow: hidden添加到每个div

就足够了
.text > div {
    overflow: hidden;
}

请看下面的代码:

body{
    background-image:url(http://www.icotoken.tel/images/slider_slide_5.jpg)
    background-size: cover;
    background-attachment: fixed;background-repeat: no-repeat;
    background-position: center;
    text-align: center;
    justify-content: center;
    align-items: center;
    text-align: center;
}
.bigger{
    padding: 30px;
    height: 300px;
}
.text {
    margin: auto;
    padding: 30px;
    height: 1200px;
    background-color: rgba(0,0,0,0.3);
    text-align: center;
    min-width: 950px;
    max-width: 950px;
}
.img{
    width:500px;
    height:300px;
    padding-bottom:30px;
    margin-left:50px;
    margin-right:50px;
}
.text > div {
    overflow: hidden;
}
<div class= "text">
    <div><img class = "img" src = "https://www.gaincontact.com/files/2016/10/Globelanguageshomepage-1.jpg" align= "left">
    <p>1st Paragraph</p></div>
    <div><img class = "img" src = "https://img00.deviantart.net/c3e2/i/2015/136/f/a/rinne_rokudou_rokumon__kyoukai_no_rinne_minimalism_by_greenmapple17-d8tm8om.png" align= "right">
    <p>2nd Paragraph</p></div>
    <div><img class = "img" src = "http://smart-defence.co.uk/wp-content/uploads/2015/03/art.jpg" align="left">
    <p>3rd Paragraph</p></div>
    <div><img class = "img" src = "https://www.markchadwick.co.uk/wp-content/uploads/2015/03/Spin-Painting-18-1000x643.jpg" align="right"> . 
    <p>4th Paragraph</p></div>
</div>

答案 1 :(得分:0)

我刚刚放display: flex;在每个.text > div上,只是将图像和文本正确地格式化为彼此。

要进一步定位,请查看flexbox

&#13;
&#13;
body {
  background-image: url(http://www.icotoken.tel/images/slider_slide_5.jpg)     background-size: cover;
  background-attachment: fixed;
  background-repeat: no-repeat;
  background-position: center;
  text-align: center;
  justify-content: center;
  align-items: center;
  text-align: center;
}

.bigger {
  padding: 30px;
  height: 300px;
}

.text {
  margin: auto;
  padding: 30px;
  height: 1200px;
  background-color: rgba(0, 0, 0, 0.3);
  text-align: center;
  min-width: 950px;
  max-width: 950px;
}

.img {
  width: 500px;
  height: 300px;
  padding-bottom: 30px;
  margin-left: 50px;
  margin-right: 50px;
}

.text > div {
  display: flex;
}

.text > div:nth-of-type(odd) img {
  order: 2;
}

.text > div:nth-of-type(odd) p {
  order: 1;
}
&#13;
<div class="text">
  <div><img class="img" src="https://www.gaincontact.com/files/2016/10/Globelanguageshomepage-1.jpg" align="left">
    <p>1st Paragraph</p>
  </div>
  <div><img class="img" src="https://img00.deviantart.net/c3e2/i/2015/136/f/a/rinne_rokudou_rokumon__kyoukai_no_rinne_minimalism_by_greenmapple17-d8tm8om.png" align="right">
    <p>2nd Paragraph</p>
  </div>
  <div><img class="img" src="http://smart-defence.co.uk/wp-content/uploads/2015/03/art.jpg" align="left">
    <p>3rd Paragraph</p>
  </div>
  <div><img class="img" src="https://www.markchadwick.co.uk/wp-content/uploads/2015/03/Spin-Painting-18-1000x643.jpg" align="right"> .
    <p>4th Paragraph</p>
  </div>
</div>
&#13;
&#13;
&#13;