首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何样式化使用ngx-markdown呈现的内容?

如何样式化使用ngx-markdown呈现的内容?
EN

Stack Overflow用户
提问于 2020-12-30 19:15:45
回答 1查看 653关注 0票数 0

我正在用Angular建立一个博客,我想用Markdown创建我的帖子。我打算使用ngx-markdown来呈现它们。现在我正在创建一个"post创建“组件。问题是我希望在markdown上应用一些样式,但是我做不到。这是我的组件:

代码语言:javascript
复制
<div class="header-container">
  <h1 class="header">New post</h1>
  <button>Send</button>
</div>
<div class="main-container">
  <div class="post-editor">
    <label for="title">Title:</label>
    <input class="title-field" type="text" name="title"
      placeholder="E.g: Introduction to Programming" autocomplete="off"
      [(ngModel)]="post.title"
    >
    <textarea [(ngModel)]="post.content"></textarea>
  </div>
  <div class="post-preview">
    <markdown class="markdown" [data]="getPostAsString()" ngPreserveWhitespaces>
    </markdown>
  </div>
</div>
代码语言:javascript
复制
import { Component, OnInit } from '@angular/core';

interface Post {
  title: string;
  content: string;
}

@Component({
  selector: 'app-create-post',
  templateUrl: './create-post.component.html',
  styleUrls: ['./create-post.component.css']
})
export class CreatePostComponent implements OnInit {
  post: Post = {
    title: 'Introduction to Programming',
    content: 'Lorem ipsum dolor, sit amet...'
  };

  constructor() {
  }

  ngOnInit(): void {
  }

  getPostAsString(): string {
    return `# ${this.post.title}\n` + this.post.content;
  }
}
代码语言:javascript
复制
h1 {
  margin-top: 20px;
  color: blue;
}
label {
  font-size: 18px;
}
input, textarea {
  width: 100%;
}
input {
  height: 25px;
}
textarea {
  height: 300px;
}
button {
  margin-left: auto;
  height: 75%;
  align-self: center;
  font-size: 18px;
  padding: 5px 10px;
}

.header-container, .main-container {
  display: flex;
}
.post-editor, .post-preview {
  flex: 1;
}
.post-preview {
  padding-top: 20px;
}
.post-editor {
  margin-right: 40px;
}
.header {
  margin-bottom: 25px;
}
.title-field {
  display: block;
  margin-top: 5px;
  margin-bottom: 20px;
}

请注意以下规则:

代码语言:javascript
复制
h1 {
  color: blue;
}

我将其应用于测试目的。页面顶部标明"New Post“的页眉被设置了样式(蓝色),但markdown页眉却没有。我还尝试使用不同的选择器,如markdown h1.post-preview h1,但都不起作用。为什么它不工作,我怎样才能使它工作?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-12-30 19:21:07

通常,libray css更改在styles.css中有效,您应该尝试在styles.css中添加您的css代码块

代码语言:javascript
复制
.post-preview h1 {
  color: blue;
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65506079

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档