Solution 1 :

I would do css with container. you can add row and columns between containers if you would like. Edit button position with “top” and “left” in css.

.container {
  position: relative;
  left:20%;
  width: 100%;
  max-width: 400px;
}

.container img {
  width: 100%;
  height: auto;
}

.btn {
  position: absolute;
  top: 50%;
  left: -20%;
  transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
  background-color: #555;
  color: white;
  font-size: 16px;
  padding: 12px 24px;
  border: none;
  cursor: pointer;
  border-radius: 5px;
  text-align: center;
}

.btn:hover {
  background-color: black;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>

</style>
</head>
<body>

<div class="container">
  <img src="https://www.w3schools.com/howto/img_snow.jpg" alt="Snow" style="width:100%">
  <button class="btn">Button 1</button>
</div>
<div class="container">
  <img src="https://www.w3schools.com/howto/img_snow.jpg" alt="Snow" style="width:100%">
  <button class="btn">Button 2</button>
</div>
<div class="container">
  <img src="https://www.w3schools.com/howto/img_snow.jpg" alt="Snow" style="width:100%">
  <button class="btn">Button 3</button>
</div>



</body>
</html>

Solution 2 :

You could achieve this with display: flex for the three image... divs. For that you have to put the buttons in the corresponding image... div. Therefor no div#left_side is div#right_side is necessary. To align the buttons to the bottom you could use align-items: flex-end:

#content>div {
  display: flex;
  align-items: flex-end;
}

Working example: (simplified for demonstration)

#content {
  /*siehe oben */
  background: transparent top left no-repeat;
}

#content>div {
  display: flex;
  align-items: flex-end;
  margin: 40px 0;
}

#content #image1 {
  margin-top: 12px;
}

#content #image3 {
  margin-bottom: 10px
}

.button {
  background-color: #4CAF50;
  border: none;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 0 2px;
  cursor: pointer;
}
<div id='content'>
  <div id='image1'>
    <a href='#' class='button' id='button_1'>Button 1</a>
    <img src="https://via.placeholder.com/300" alt="product_1">
  </div>
  <div id='image2'>
    <a href='#' class='button' id='button_2'>Button 2</a>
    <img src="https://via.placeholder.com/300" alt="product_1">
  </div>
  <div id='image3'>
    <a href='#' class='button' id='button_3'>Button 3</a>
    <img src="https://via.placeholder.com/300" alt="product_1">
  </div>
</div>

Solution 3 :

just use grid layout with each cell containing an image and its coresponding button

Problem :

I am new to HTML-CSS and I am trying to restyle a webpage as an exercise for a university course. I am struggling to put buttons on the left side next to the image to the right side, so that they both look neat on the page. This is what I reached by now:

enter image description here

The problem is, that if I move the first button on the top it will push down the other and they will look messy and not anchored to the images right. Is there actually a way to anchor buttons to images in HTML-CSS, so that stay in the position assigned? And how can I assign the same distance to vertical elements in CSS?
I tried with margin-bottom / margin-top but I don“t think it is a good way to solve the problem.

Thank you in advance for every suggestion.

<div id='content'>
  <div class='spacer'></div>
  <!--Anfang linksseiteiger Container mit Links-Buttons-->
  <div id='left_side'>
    <a href='#' class='button' id='button_1'>Button 1</a>
    <a href='#' class='button' id='button_2'>Button 2</a>
    <a href='#' class='button' id='button_3'>Button 3</a>
  </div>
  <!--Ende linksseiteiger Cont#ainer mit Links-Buttons-->

  <!--Anfang rechtseitiger Container mit Bilder-->
  <div id=right_side>
    <div id='image1'>
      <img src="img/product_1.jpg" alt="product_1">
    </div>
    <div id='image2'>
      <img src="img/product_2.jpg" alt="product_1">
    </div>
    <div id='image3'>
      <img src="img/product_3.jpg" alt="product_1">
    </div>
  </div>
  <!-- Ende rechtseitiger Container-->
  <div class='spacer'></div>
#content {
  /*sehe oben */
  background: transparent top left no-repeat;
}

#right_side {
  width: 300px;
  margin-top: 50px;
  margin-right: 15px;
  margin-bottom: 20px;
}

#left_side {
  width: 100px;
  margin-left: 50px;
  position: relative;
  margin-bottom: -170px;
  margin-top: 20px;
}

#image1 {
  margin-top: 12px;
  margin-bottom: 40px;
}

#image2 {
  margin-top: 20px;
  margin-bottom: 40px;
}

#image3 {
  margin-bottom: 10px
}

.button {
  background-color: #4CAF50;
  border: none;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 4px 2px;
  cursor: pointer;
}

#button_1 {
  text-decoration: none;
  color: white;
  margin-top: 220px;
}

#button_2 {
  margin-top: 250px;
}

#button_3 {
  position: static;
  margin-top: 198px;
}

Comments

Comment posted by Weyers de Lange

So just to be clear you want all the buttons to display on the right side of the images ?

Comment posted by Franz Biberkopf

No, on the left side but with the same distance from each other

By