user9279766
user9279766

Reputation:

Each paragraph next to each image

I have 4 different paragraphs and 4 images which each correspond to each image. I would like to have each paragraph right next to each image.

Any help welcome, please

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>

Upvotes: 1

Views: 46

Answers (2)

StefanBob
StefanBob

Reputation: 5128

I just put display: flex; on each .text > div, which just properly formats the image and text next to each other.

For further positioning check out flexbox

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;
}
<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>

Upvotes: 0

Alex M
Alex M

Reputation: 2836

It's enough to add overflow: hidden to each div:

.text > div {
    overflow: hidden;
}

Look at the below snippet:

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>

Upvotes: 1

Related Questions