Home > other >  Can't move buttons to the right side
Can't move buttons to the right side

Time:12-30

I have problem where I can't move objects in div (buttons in this case) to one side.

I have this HTML:

      <div class='post-div'>
        <h1>There will be title</h1>
        <div class='post-content-and-actions'>
          <div class='peace-of-content'>
            <p>Here will be a little bit of content and Lorem ipsum</p>
          </div>
          <div class='actions'>
            <button class='edit'>EDIT</button>
            <button class='edit delete'>DELETE</button>
          </div>
        </div>
      </div>

And css:

.post-div {
  width: 1000px;
  height: 150px;
  padding: 8px;
  .post-content-and-actions {
    width: 100%;
    display: flex;
    .peace-of-content {
      width: 700px;
    }
    .actions {
      width: 300px;
      .edit {
        width: 100px;
        height: 30px;
        font-size: 15px;
        background-color: green;
        &.delete {
          background-color: red;
        }
      }
    }
  }
}

In actions section I want to move all buttons to the right and whatever I do, I just can't. float: right, right: 0 etc. Actually, I have no idea why!

CodePudding user response:

You could add text-align: right; to .actions :

    ...
    .actions {
      width: 300px;
      text-align: right;
      ...

CodePudding user response:

Flexbox will easily achieve this..

.actions {
    display: flex;
    justify-content: flex-end;
    width: 300px;
    .edit {
        width: 100px;
        height: 30px;
        font-size: 15px;
    }
  • Related