html - 即使在使用 CSS 添加列表元素后,修复图像右下角的位置

标签 html css angular typescript

enter image description here

即使在列表 (li) 中添加元素后,我也想“修复”右下角的图像(铅笔)。目前,当我在列表中添加文本时,图像(铅笔)向下移动,这不是我想要的。请提出建议。

HTML:

<div class="notes">
  <h3>Notes</h3>
  <div class="notes-content">
    <div *ngIf="showNotes">
      <ul>
        <li *ngFor="let note of notesList">
          <span>{{note}}</span>
        </li>
        <li>
          <input type="text" name="newNote" placeholder="Type here" [(ngModel)]="newNote" />
        </li>
      </ul>
    </div>
    <div class="addNoteBtn">
      <img src="../../common/images/edit-note1.png" alt="Add Note" (click)="addNote()"/>
    </div>
  </div>
</div>

CSS:

.notes {
  margin-top: 20px;
  margin-left: 20px;
  h3 {
    font-size: 14px;
    font-weight: 500;
    line-height: 17px;
  }
  .notes-content {
    border: 1px solid #FFFFFF;
    border-radius: 3px;
    box-shadow: inset 2px 2px 3px 0 #FFFFFF;
    height: 150px;
    ul {
      padding-top: 10px;
      list-style-type: inherit;
      li input {
        background-color: #171717;
        border: none;
        &:focus {
          outline: none;
        }
      }
    }
    .addNoteBtn {
      float: right;
      margin-top: 15px;
      img {
        cursor: pointer;
      }
    }
  }
}

组件:

  name:string;
  notesList: Array<string> = [];
  newNote: string = '';
  show: boolean = false;
  constructor() {
    this.name = 'Angular2'
    this.notesList = ['a', 'b', 'c'];
    this.show = true;
  }

  addNote(): void {
    this.notesList.push(this.newNote);
  }

示例 Plunker:

https://plnkr.co/edit/cFi75ggSA8nESetupOo5

最佳答案

您可以在容器 .notes-content 上添加一个relative 位置。

并在您的图片上添加一个绝对位置。

.notes-content {
  position:relative;
  border: 1px solid #ccc;
  border-radius: 3px;
  box-shadow: inset 2px 2px 3px 0 #FFFFFF;
}

.addNoteBtn {
  position:absolute;
  bottom:5px;
  right:5px;
}

Demo

关于html - 即使在使用 CSS 添加列表元素后,修复图像右下角的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41098372/

相关文章:

html - Mozilla Firefox 和 Internet Explorer 之间的字体差异

html - 在 Bootstrap 中使用单选按钮更改标签字体大小时出现对齐问题

css - 一个元素中同时处理两个css框架的最佳攻略

angular - 类型 'By' 与类型 'Locator' 没有共同的属性

angular - 所有观察到的 NGXS 选择器是否都会在任何状态更改时执行?

html - 如何在 IE 7 中查看错误

jquery - Nth-child 应用于每个按钮

angular - 如何在 formcontrol 中设置默认 bool 值 false

html - 为什么我的图像不会扩展到 div 的完整大小?

java - 在 Java 中呈现 HTML