HTML 按钮不能正确显示在列表项旁边

标签 html css vue.js sass

我正在构建传统的待办事项列表应用程序,以努力增加我对 Vuejs 的理解。大多数功能都按预期工作,但我的待办事项显示不正确。每个元素都应该有一个“删除”按钮,该按钮显示在其行的右侧,但按钮渗入了下面的行(见图)。

令我恼火的是复选框显示正确,但按钮显示不正确。我已经尝试将按钮的所有 css 更改为复选框的 css,但这没有用

TodoItem.vue

<template lang="html">
  <li class="todo-item" v-bind:class="{ 'is-complete': todo.completed }">
    <div class="checkbox-holder">
      <input type="checkbox" v-on:change="markComplete(todo.id)" />
    </div>
    <h2>{{ todo.title }}</h2>
    <button v-on:click="deleteTodo(todo.id)" class="del">x</button>
  </li>
</template>

应用.scss

.todos {
  position: absolute;
  display: block;
  width: 656px;
  background-color: white;
  margin-left: 266px;
  border-right: $generic-border;
  min-height: calc(100vh);
  padding-left: 40px;
  padding-right: 40px;
  padding-top: 80px;
  padding-bottom: 80px;

  @include mq("900px") {
    margin-left: 0;
    width: auto;
  }
  h2 {
    font-size: 20px;
    font-weight: normal;
  }
  &__list li {
    line-height: 1.4;
    color: #333;
    font-size: 14px;
    list-style-type: none;
    border-bottom: 1px solid #f0f0f0;
    margin-bottom: 20px;
    margin-top: 20px;
    padding: 20px;
    &.is-complete {
      text-decoration: line-through;
    }
    button {
      @include btn("30px");
      float: right;
      display: block;
    }
    .checkbox-holder {
      margin-right: 20px;
      margin-left: 20px;
      align-items: center;
      justify-content: center;
      line-height: 16px;
      float: left;
      .checkbox {
        cursor: pointer;
        border-color: gray;
        color: #343434;
        height: 16px;
        width: 16px;
        border: 1px solid gray;
        border-radius: 16px;
      }
    }
  }
}

这是按钮的显示方式。 incorrect output

最佳答案

你可以看到下面的代码。

li {
  display: flex;
  align-items: center;
}
<ul>
  <li class="todo-item">
    <div class="checkbox-holder">
      <input type="checkbox"/>
    </div>
    <h2>Hello world</h2>
    <button>x</button>
  </li>
</ul>

关于HTML 按钮不能正确显示在列表项旁边,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57939730/

相关文章:

html - 溢出-y和位置: absolute cause the offset when scroll bar is not at the top

css - 需要有关 CSS 代码的解释

php - 在PHP中从MySQL数据库获取数据,解析错误: syntax error,意外 '<'

jquery - 使用 jQuery 的悬停问题

html - 大字在手机 View 中显示错误

javascript - 如何管理使用 AWS Amplify Authentication 创建的用户

javascript - Nuxt Js asyncData 返回值表现得很奇怪。

javascript - 覆盖 console.log 时如何显示 Promise 对象的状态和值

html - &lt;input type ="range"> 垂直时样式不适用于拇指

javascript - 为什么我的函数在其中使用箭头函数时被识别为对象?