[英]How to create a white border circle having white exclamation mark inside a box having a yellow background in html/css?
I am trying to create a white border circle having a white exclamation mark inside a yellow background box. 我正在尝试在黄色背景框中创建带有白色感叹号的白色边框圆圈。 The HTML and CSS code of the yellow background box is:
黄色背景框的HTML和CSS代码为:
HTML: HTML:
<p class="my-paragraph-style">List your dependents and enter their personal information. Pay close attention to information regarding your spouse’s smoking habits.</p>
CSS: CSS:
.dependents .my-paragraph-style
{
background: #EABB27;
padding: 20px;
line-height: 1.4;
position: relative;
top: -25px;
}
The pictorial representation of the yellow background box which I have got from the above code (HTML and CSS) is: 从上面的代码(HTML和CSS)获得的黄色背景框的图形表示为:
My task is to make a white border circle having a white exclamation mark inside a yellow box. 我的任务是在黄色框内制作一个带有白色感叹号的白色边框圆圈。 Below is an image what I exactly want inside a yellow background box:
下面是我在黄色背景框中想要的图像:
In order to achieve that, I have cropped the circle from the section of a yellow background box. 为了实现这一点,我从一个黄色背景框的部分裁剪了圆圈。 After cropping it, I have used the following CSS code in order to get the circle inside the box.
裁剪后,我使用了以下CSS代码来将圆放入框内。
@media screen and (max-width: 767px) and (min-width: 320px)
{
.info-mobile-header-sections
{ /* Info icon for header parts of sections */
background: url(img/147811205179656.png) no-repeat;
margin-top: -3px;
position: absolute;
z-index: 200;
left: 15px;
}
}
The 147811205179656.png is a cropped image 147811205179656.png是裁剪的图像
from the section of a yellow box.
从一个黄色框的部分。
By using the above CSS code, I am able to get only some section of the circle inside the yellow box and that too not aligned properly. 通过使用上面的CSS代码,我只能在黄色框内获得圆圈的某些部分,并且也无法正确对齐。 Let me know if I am following the right approach.
让我知道我是否遵循正确的方法。
CSS CSS
.my-paragraph-style
{
background: #EABB27;
padding: 40px;
line-height: 1.4;
position: relative;
top: -25px;
}
.my-paragraph-style:before {
content:"!";
position: absolute;
top: 40px;
left: 10px;
color: #fff;
border: 1px solid #fff;
height: 20px;
width: 20px;
text-align: center;
border-radius: 50%
}
You can tinker with the css as per your liking. 您可以根据自己的喜好修改CSS。
No need to use an image here, it's easier, faster, more scalable and flexible to use a pseudo element like ::before
here: 无需在此处使用图片,使用伪造元素(如
::before
更加容易,快捷,可扩展且灵活:
.my-paragraph-style { background: #EABB27; padding: 20px 20px 20px 50px; line-height: 1.4; position: relative; font-family: arial, helvetica, sans-serif; color: white; font-weight: bold; font-size: 14px; max-width: 300px; } .my-paragraph-style::before { display: block; position: absolute; left: 20px; top: 23px; content: "!"; border-radius: 50%; border: 1px solid yellow; width: 20px; height: 20px; line-height: 22px; text-align: center; color: yellow; font-weight: normal; }
<p class="my-paragraph-style">List your dependents and enter their personal information. Pay close attention to information regarding your spouse's smoking habits.</p>
You can create that with just :before
pseudo-element and Flexbox
. 您可以使用
:before
伪元素和Flexbox
来创建它。
.my-paragraph-style { background: #EABB27; padding: 20px; max-width: 300px; display: flex; color: white; } .my-paragraph-style:before { flex: 0 0 30px; height: 30px; border: 1px solid white; margin-right: 20px; border-radius: 50%; content: '!'; display: flex; align-items: center; justify-content: center; font-size: 20px; }
<p class="my-paragraph-style">List your dependents and enter their personal information. Pay close attention to information regarding your spouse's smoking habits.</p>
.my-paragraph-style { background: #EABB27; padding: 20px 20px 20px 50px; line-height: 1.4; color: #fff; } .my-paragraph-style:before { content: '!'; height: 20px; width: 20px; display: block; border: 2px solid red; border-radius: 50%; text-align: center; color: red; float: left; margin-left: -35px; }
<p class="my-paragraph-style">List your dependents and enter their personal information. Pay close attention to information regarding your spouse's smoking habits.</p>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.