0

I don't understand what im doing wrong with the use of flexbox.

I'd like to have my button on the extreme right of the screen (but that does not happen) and the text input on the left. I'd like to do it using flexbox. here is the code:

* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}

form {
  display: flex;
  background: red;
}

button {
  align-self: flex-end;
  }
<div class="adder-comp">
  <form>
    <input type="text" placeholder="aggiungi compito.." />
    <button>crea</button>
  </form>
</div>
Johannes
  • 64,305
  • 18
  • 73
  • 130
Giuse
  • 65
  • 6

3 Answers3

1

Just use justify-content: space-between; on the parent instead:

* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}

form {
  display: flex;
  background: red;
  justify-content: space-between;
}
<div class="adder-comp">
  <form>
    <input type="text" placeholder="aggiungi compito.." />
    <button>crea</button>
  </form>
</div>

Alternatively, you can use margin-left: auto on the button:

* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}

form {
  display: flex;
  background: red;
}

button {
  margin-left: auto;
}
<div class="adder-comp">
  <form>
    <input type="text" placeholder="aggiungi compito.." />
    <button>crea</button>
  </form>
</div>
Johannes
  • 64,305
  • 18
  • 73
  • 130
0

Might be looking align-content vs align-self and justify-content in form tag.

<div class="adder-comp">
  <form>
    <input type="text" placeholder="aggiungi compito.." />
    <button>crea</button>
  </form>
</div>
* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}

form {
  display: flex;
justify-content: space-between;
  background: red;
}

button {
  align-content: flex-end;
  }
Thomas__
  • 320
  • 3
  • 13
0
form{
  display: flex;
  background: red;
  justify-content: space-between
}

Just add justify-content: space-between to the form

BucksDad
  • 15
  • 3