如何在HTML形状实体内部着色背景?

huangapple go评论56阅读模式
英文:

How to color the background within the square HTML shape entity?

问题

Using HTML,我想创建一个带有黑色边框和绿色背景的正方形。我一直在使用HTML中的正方形形状实体&#9633。问题是,当我使用background-color样式时,它填充整个div。如何只在形状内部获得带有黑色边框和绿色的效果?

以下是我尝试过的内容,但最终将整个div着色为绿色。我只想处理形状并指定背景的颜色。

<div style="font-size:60px;background-color:#000;border: 2px solid #000;color:#388004;">&#9633;</div>
英文:

Using HTML I want to create a square inline with a black border and green background. I have been using the square shape entity in HTML &amp;#9633. The issue is when I use the background-color style it fills the entire div. How do I get this shape with a black border and green just within the shape?

Below is what I have tried, but it ends up with coloring the entire div as green. Would love just to work with the shape and specify the coloring of the background only.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

&lt;div style=&quot;font-size:60px;background-color:#388004;&quot;&gt;&amp;#9633;&lt;/div&gt;

<!-- end snippet -->

答案1

得分: 0

<div style="border:2px solid black;width:23px;height:23px;background-color:#388004;"></div>
英文:

Your current code.

<!-- begin snippet: js hide: true console: true babel: false -->

<!-- language: lang-html -->

&lt;div style=&quot;font-size:60px;background-color:#388004;&quot;&gt;&amp;#9633;&lt;/div&gt;

<!-- end snippet -->

If my understanding is correct, you want a box or square with black border and filled with green color.

I don't know if this could help you, but if that so...
Make another div that will fill the your &amp;#9633; or box and remove the background-color in the parent div.

Using a static css, you can do like this.

<!-- begin snippet: js hide: true console: true babel: false -->

<!-- language: lang-html -->

&lt;div style=&quot;position:relative;font-size:60px;&quot;&gt;
  &lt;div style=&quot;position:absolute;top:30px;left:6px;width:23.5px;height:23.5px;background-color:#388004;&quot;&gt;&lt;/div&gt;
  &amp;#9633;
&lt;/div&gt;

<!-- end snippet -->

But, if you just want a box with black border filled with green color and this &amp;#9633; is not required, you can actually do it with just one div by setting up it's border.

<!-- begin snippet: js hide: true console: true babel: false -->

<!-- language: lang-html -->

&lt;div style=&quot;border:2px solid black;width:23px;height:23px;background-color:#388004;&quot;&gt;&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年5月10日 12:43:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/76214958.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定