简体   繁体   English

如何使用CSS在另一个div内的div内调整图像大小?

[英]how to resize images inside a div inside another div with css?

I want to only resize images that are in a div with a specific class, inside an other div with an other specific class. 我只想调整具有特定类的div中具有其他特定类的div中的图像的大小。 but the images which are only inside the div which is inside the other div should not be resized. 但仅应调整位于另一个div内的div内的图像的大小。

This works if I want to resize images inside a classed div: 如果我要在已分类的div中调整图像大小,则此方法有效:

div.classname>img { width:something; }

but this doesn't work: 但这不起作用:

div.classname2 > div.classname > img { width:something; }

Markup 标记

<div class="classname2">
    <div class="classname">
        <img>
    </div>
</div>

But I can't refer to it with the inside class name. 但是我不能用内部类名来引用它。

So, to make it really clear, i need to resize these images: 因此,要弄清楚,我需要调整这些图像的大小:

<div class="classname2">
    <div class="classname">
        <img>
    </div>
</div>

But not these: 但不是这些:

<div class="classname">
    <img>
</div>

I think this should work 我认为这应该工作

CSS 的CSS

.classname2 .classname img { width: 200px; }

I feel like your css rule should work 我觉得您的CSS规则应该有效

div.classname2 > div.classname > img { width:something; }

Does this fiddle show what you're trying to illustrate? 这个小提琴是否显示您要说明的内容? If so, perhaps you just have overriding CSS rules somewhere? 如果是这样,也许您只是在某个地方有重载的CSS规则?

Having: 具有:

<div class="parentDiv">
    <img class="img1">
    <div class="childDiv">
        <img class="img2">
    </div>
</div>

do it like this: 像这样做:

.parentDiv > img { width: 100px }

will just effect <img> s having class="img1" not those having class="img2" 只会影响具有class="img1" <img>而不影响具有class="img2"那些

Edit the only the single image you want without changing the rest, by going to that specific tag and putting the following style attributes. 通过转到该特定标签并放置以下样式属性,可以仅编辑所需的单个图像,而无需更改其余图像。

<img class = "example" style = "width: 50px !important;">

UPDATE 更新

Give this a try, add "!important" to the inside class to override the parent. 尝试一下,在内部类中添加“!important”以覆盖父类。

div.classname2 > div.classname > img { width:something !important; }

如何调整羽毛笔编辑器的大小以适应<div> ?</div><div id="text_translate"><p> 我希望羽毛笔编辑器自动适应父&lt;div&gt;元素。</p><p> 我创建了&lt;div&gt;元素,并在其中再次创建了一个&lt;div&gt;元素,该元素将成为 quill 编辑器的容器。 工具栏是自动创建的。 我使用 css 将父&lt;div&gt;元素的大小调整为width:50%和height:50% ,我希望其中的所有内容(羽毛笔编辑器和工具栏)都适合其中,但是羽毛笔编辑器的某些部分会出现父&lt;div&gt;元素的。</p><p> <strong>HTML:</strong></p><pre class="lang-html prettyprint-override"> &lt;,-- parent div element: in which quill editor should fit --&gt; &lt;div id="parent" style="width;50%:height;70%:border:2px solid green"&gt; &lt;!-- Quill editor div --&gt; &lt;div id="editor"&gt; &lt;/div&gt; &lt;/div&gt;</pre><p> <strong>Javascript:</strong></p><pre> var tool = [[{ 'header': '1' }, { 'header': '2' }], [{ size: ['small', false, 'large', 'huge'] }], ['bold', 'italic', 'underline', 'strike'], [{ 'color': [] }, { 'background': [] }, { 'font': [] }, { 'align': [] }], ['image',]]; var option = { placeholder: 'Compose an epic...', theme: 'snow', modules: { toolbar: tool }, bounds:'#parent' }; var quill = new Quill('#editor', option);</pre><p> 我在父 div 周围放了一个绿色边框,我发现编辑器从边框出来了。 请看截图:</p><p> <a href="https://i.stack.imgur.com/RlASQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RlASQ.png" alt="截屏"></a></p><p> 注意:我只想保持父 div 的大小固定。 所以,请告诉我该怎么办?</p><p> 编辑:我将整个代码(html 文件)上传到我的服务器(<a href="http://tu.unaux.com/game.html" rel="nofollow noreferrer">这里</a>)。 问题仍然存在。 请检查一下,您可以使用“检查元素”查看整个代码。</p></div> - How to resize quill editor to fit inside a <div>?

暂无
暂无

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

相关问题 另一个 DIV 中的 DIV 未加载图像 - DIV inside another DIV Not Loading Images 在 JS 代码中使用 css 来调整 div 的大小 - Using css inside JS code to resize a div 重复图像,然后在DIV中重复另一个图像 - Repeating images followed by another image inside a DIV 如何调整svg的大小以适应div? - How to resize a svg to fit inside a div? 如何从对象内部调整div的大小? - how to resize a div from inside an object? 如何调整羽毛笔编辑器的大小以适应<div> ?</div><div id="text_translate"><p> 我希望羽毛笔编辑器自动适应父&lt;div&gt;元素。</p><p> 我创建了&lt;div&gt;元素,并在其中再次创建了一个&lt;div&gt;元素,该元素将成为 quill 编辑器的容器。 工具栏是自动创建的。 我使用 css 将父&lt;div&gt;元素的大小调整为width:50%和height:50% ,我希望其中的所有内容(羽毛笔编辑器和工具栏)都适合其中,但是羽毛笔编辑器的某些部分会出现父&lt;div&gt;元素的。</p><p> <strong>HTML:</strong></p><pre class="lang-html prettyprint-override"> &lt;,-- parent div element: in which quill editor should fit --&gt; &lt;div id="parent" style="width;50%:height;70%:border:2px solid green"&gt; &lt;!-- Quill editor div --&gt; &lt;div id="editor"&gt; &lt;/div&gt; &lt;/div&gt;</pre><p> <strong>Javascript:</strong></p><pre> var tool = [[{ 'header': '1' }, { 'header': '2' }], [{ size: ['small', false, 'large', 'huge'] }], ['bold', 'italic', 'underline', 'strike'], [{ 'color': [] }, { 'background': [] }, { 'font': [] }, { 'align': [] }], ['image',]]; var option = { placeholder: 'Compose an epic...', theme: 'snow', modules: { toolbar: tool }, bounds:'#parent' }; var quill = new Quill('#editor', option);</pre><p> 我在父 div 周围放了一个绿色边框,我发现编辑器从边框出来了。 请看截图:</p><p> <a href="https://i.stack.imgur.com/RlASQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RlASQ.png" alt="截屏"></a></p><p> 注意:我只想保持父 div 的大小固定。 所以,请告诉我该怎么办?</p><p> 编辑:我将整个代码(html 文件)上传到我的服务器(<a href="http://tu.unaux.com/game.html" rel="nofollow noreferrer">这里</a>)。 问题仍然存在。 请检查一下,您可以使用“检查元素”查看整个代码。</p></div> - How to resize quill editor to fit inside a <div>? 如何调整大svg的大小以适应div - how to resize a large svg to fit inside a div 如何将 position 中的一个 div 放入另一个 div 中的 reactJs? - How to position a div inside another div in reactJs? 如何在另一个div内插入div? - How to insert div inside another div? 如何在另一个div内追加一个div? - How to append a div inside a another div?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM