【发布时间】:2020-09-12 10:21:51
【问题描述】:
我正在尝试在 vuejs 中的 v-html 上的 ap 标签内设置 img 标签的样式,我可以直接设置 p 标签的样式,但选择 img 标签有点困难,因为 p ~ img 和 p + img 不会工作有没有办法解决这个问题。 v-html 的内容来自 wp-rest api
v-html 内容
<p><img class="aligncenter" src="https://images.unsplash.com/photo-1488590528505-98d2b5aba04b?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80" alt="turned on gray laptop computer"></p>
SinglePost.vue
<div class="works__content_grid">
<p class="works__content" v-html="work.post.content.rendered"></p>
</div>
<style lang='sass' scoped>
.works
&__content
p
img
width: 100px
</style>
【问题讨论】:
-
不能嵌套段落,即一个段落元素不能有
<p>后代。如果可能,为什么不使用后代选择器p img { ... }? -
@connexo 我尝试将其更改为 div 标签,但仍然无法正常工作
-
<p>也不能包含<div>。
标签: javascript html css vue.js sass