简体   繁体   English

博文中的图片

[英]images inside the blog posts

I'd like to define the appearance of my images inside the section (I'm trying to add a border to the image - but I can't reference the image directly because the images are added dynamically - as content of blog posts.) Can you advise me on how to do that? 我想在部分中定义我的图像的外观(我正在尝试为图像添加边框 - 但我无法直接引用图像,因为图像是动态添加的 - 作为博客文章的内容。)你能告诉我怎么做吗? Do I have to create a new section/id/div? 我是否必须创建一个新的部分/ id / div? How can I than say to the machine: In the section/id/div I created I would like you to apply these styls to the images." ? thanks, D. 我怎么能对机器说:在我创建的部分/ id / div中,我希望你将这些样式应用于图像。“?谢谢,D。

If content is added dynamically, styles are applied automatically as new content is added to the DOM, you don't need to worry about that. 如果动态添加内容,则在将新内容添加到DOM时会自动应用样式,您无需担心这一点。 Inject the content you want, and as long as there is CSS-rules that match that content, the browser will handle the rest. 注入所需的内容,只要有符合该内容的CSS规则,浏览器就会处理其余内容。

Update 更新

I realize that I might have misunderstood your question at first. 我意识到我最初可能误解了你的问题。 If the user is completely in control of the markup of the blog post, I guess the best way would be to use a selector, that select every image within a container that wrap each blog post. 如果用户完全控制博客文章的标记,我想最好的方法是使用选择器,选择包装每篇博文的容器中的每个图像。

Lets say each blog post is rendered within an element with class post . 让我们说每个博客文章都在一个带有课程post的元素中呈现。 Then you could do something like this: 然后你可以做这样的事情:

.post img {
   border: 1px solid #000;
} 

Yes you need to get a reference to the image or the block in which the images is going to be displayed. 是的,您需要获得图像或将要显示图像的块的引用。 Then apply the css rules to the image or block you will then get the styles on the image. 然后将css规则应用于图像或块,然后您将获得图像上的样式。 I would prefer class="" if there are many and id="" if there is only one. 如果有很多,我更喜欢class=""如果只有一个,我会更喜欢id=""

If you have img inside any elements like below, 如果你有img里面的任何元素,

<div class="someclass">
     <img src="" />
</div>

then at CSS, 然后在CSS,

.someclass{
    your rules go here.    
}

or if you want to directly have styles on image then you HTMl will be like below and CSS same as above. 或者如果你想在图像上直接使用样式,那么HTMl将如下所示,CSS与上面相同。

<img class="someclass" src="" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM