Ich habe diese Schaltfläche "Kaufen" (comprar), die ich am Ende von div einfügen möchte, damit sie an der Schaltfläche "Kaufen" ausgerichtet sind.

Z.B:

button button button

Nicht:

button            button
       button    
#content01{
 min-height:500px;
 display: flex;
 flex-direction: row;
 flex-wrap: wrap;
}

.produto{
  display: inline-block;
  margin-top: 20px;
  margin-right: 20px;
  margin-bottom: 20px;
  border: 2px solid #F6F6F6;
  width: 246px;
  text-align: center;
  vertical-align: top;
  padding-bottom:10px;
}


.comprar_button {
  background: green;
  padding:10px;
  color: #fff;
  text-align:center;
  font-weight:bold;
  vertical-align:bottom;
  align-self: flex-end;
}

.comprar_button a{
  color: #fff!important;
}

.comprar_button img{
  width: 15px;
  height: 15px;
}
<div id="content01">
    
  <div class="produto">Some text<br><br><br><b>$ 20.00</b><br><br>
      <br><span class="comprar_button">COMPRAR</span>
  </div>

  <div class="produto">Some text text some text some text some text<br><br><br><b>$ 20.00</b><br><br>
      <br><span class="comprar_button">COMPRAR</span>
  </div>

  <div class="produto">Some text<br><br><br><b>$ 20.00</b><br><br>
      <br><span class="comprar_button">COMPRAR</span>
  </div>

  <div class="produto">Some text Some text Some text Some text Some text Some text Some text Some text Some text<br><br><br><b>$ 20.00</b><br><br>
      <br><span class="comprar_button">COMPRAR</span>
  </div>

</div>

https://jsfiddle.net/j72u8Lx5/

Wie kann ich die Schaltfläche "comprar" ausrichten?

0
RGS 19 Feb. 2020 im 22:32

3 Antworten

Beste Antwort

Weisen Sie display: flex auch Ihren .produto DIVs mit flex-direction: column und align-items: center zu. Fügen Sie dann margin-top: auto zum .comprar_button hinzu, um es an den Boden des Containers zu verschieben (und entfernen Sie einige andere überflüssige Dinge, siehe unten):

#content01{
 min-height:500px;
 display: flex;
 flex-wrap: wrap;
}

.produto{
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 20px;
  margin-right: 20px;
  margin-bottom: 20px;
  border: 2px solid #F6F6F6;
  width: 246px;
  text-align: center;
  padding-bottom:10px;
}


.comprar_button {
  background: green;
  padding:10px;
  color: #fff;
  font-weight:bold;
  margin-top: auto;
}

.comprar_button a{
  color: #fff!important;
}

.comprar_button img{
  width: 15px;
  height: 15px;
}
<div id="content01">
    
  <div class="produto">Some text<br><br><br><b>$ 20.00</b><br><br>
      <br><span class="comprar_button">COMPRAR</span>
  </div>

  <div class="produto">Some text text some text some text some text<br><br><br><b>$ 20.00</b><br><br>
      <br><span class="comprar_button">COMPRAR</span>
  </div>

  <div class="produto">Some text<br><br><br><b>$ 20.00</b><br><br>
      <br><span class="comprar_button">COMPRAR</span>
  </div>

  <div class="produto">Some text Some text Some text Some text Some text Some text Some text Some text Some text<br><br><br><b>$ 20.00</b><br><br>
      <br><span class="comprar_button">COMPRAR</span>
  </div>

</div>
1
Johannes 19 Feb. 2020 im 20:09

Mit flex habe ich die Änderungen im Code kommentiert: https://jsfiddle.net/3jenapsb

#content01{
 min-height:500px;
 display: flex;
 flex-direction: row;
 flex-wrap: wrap;
}

.produto{
  
  display: flex;/*added*/
  flex-direction:column;/*added*/
  align-items:center;/*added*/
  margin-top: 20px;
  margin-right: 20px;
  margin-bottom: 20px;
  border: 2px solid #F6F6F6;
  width: 246px;
  text-align: center;
  vertical-align: top;
  padding-bottom:10px;
}

b{
  flex-grow:1;/*added*/
}

.comprar_button {
	background: green;
	padding:10px;
	color: #fff;
	text-align:center;
	font-weight:bold;
	vertical-align:bottom;
	width:150px;/*added*/
}
.comprar_button a{
	color: #fff!important;
}
.comprar_button img{
	width: 15px;
	height: 15px;
}
<div id="content01">

<div class="produto">Some text<br><br><br><b>$ 20.00</b><br><br>
		<br><span class="comprar_button">COMPRAR</span>
</div>
    
<div class="produto">Some text text some text some text some text<br><br><br><b>$ 20.00</b><br><br>
		<br><span class="comprar_button">COMPRAR</span>
</div>

<div class="produto">Some text<br><br><br><b>$ 20.00</b><br><br>
		<br><span class="comprar_button">COMPRAR</span>
</div>

<div class="produto">Some text Some text Some text Some text Some text Some text Some text Some text Some text<br><br><br><b>$ 20.00</b><br><br>
		<br><span class="comprar_button">COMPRAR</span>
</div>
   
   
   </div>
0
Ayman Morsy 19 Feb. 2020 im 20:09

Ist das was du willst? Es wurde die absolute Position verwendet.

https://jsfiddle.net/usv7jLhm/

.produto{
    position: relative;
    display: inline-block;
    margin-top: 20px;
    margin-right: 20px;
    margin-bottom: 20px;
    border: 2px solid #F6F6F6;
    width: 246px;
    text-align: center;
    vertical-align: top;
    padding-bottom:10px;
}

.comprar_button {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translate(-50%, -50%);
    background: green;
    padding:10px;
    color: #fff;
    text-align:center;
    font-weight:bold;
    vertical-align:bottom;
    align-self: flex-end;
}
1
Dominik Lev 19 Feb. 2020 im 20:00