英文:
How to color the background within the square HTML shape entity?
问题
Using HTML,我想创建一个带有黑色边框和绿色背景的正方形。我一直在使用HTML中的正方形形状实体□
。问题是,当我使用background-color
样式时,它填充整个div
。如何只在形状内部获得带有黑色边框和绿色的效果?
以下是我尝试过的内容,但最终将整个div
着色为绿色。我只想处理形状并指定背景的颜色。
<div style="font-size:60px;background-color:#000;border: 2px solid #000;color:#388004;">□</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 &#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 -->
<div style="font-size:60px;background-color:#388004;">&#9633;</div>
<!-- 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 -->
<div style="font-size:60px;background-color:#388004;">&#9633;</div>
<!-- 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 &#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 -->
<div style="position:relative;font-size:60px;">
<div style="position:absolute;top:30px;left:6px;width:23.5px;height:23.5px;background-color:#388004;"></div>
&#9633;
</div>
<!-- end snippet -->
But, if you just want a box with black border filled with green color and this &#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 -->
<div style="border:2px solid black;width:23px;height:23px;background-color:#388004;"></div>
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论