51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

如何在使用CSS的FLEXBOX时移除我的图标周围的空白空间?

英文:

How can i remove empty space around my ICON when i using FLEXBOX in CSS?

问题 {#heading}

当我使用flexbox时,如何去掉图标周围的蓝色背景色?

无法将子元素的属性一般化为其父元素。

我没有全局背景颜色。

我在FONTAWSOME.com网站上使用了图标。

* {
    direction: ltr;
    background-color: #55efc4;
    box-sizing: border-box;
}

body {
    font-size: 16px;
}

.container {
    display: flex;
    flex-direction: column;
    background-color: white;
    margin: 150px 500px;
}

.title {
    font-size: 2em;
    color: white;
    background-color: #00b894;
    border: 1px solid white;
    padding: 20px;
    justify-content: center;
    align-items: center;
    text-align: center;
}

.user {
    background-color: white;
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-content: center;
    align-items: center;
    margin: 10px;
    padding: 10px;
    align-self: center;
}

#usericon {
    position: relative;
    align-self: auto;
    padding: 0px;
}

.userid {
    position: relative;
    background-color: white;
    align-self: auto;
}

#idname {
    position: relative;
    align-self: center;
    background-color: white;
    border: none;
    border-bottom: 2px solid #999;
    border-radius: 5px;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    -ms-border-radius: 5px;
    -o-border-radius: 5px;
}

#idname:focus {
    outline: none;
    border: none;
    border-bottom: 2px solid #00b894;
    -webkit-transition: 3s;
}

<!DOCTYPE html>
<html>

<head>
    <title>登录</title>
    <meta charset="UTF-8" />
    <script src="https://kit.fontawesome.com/5dd6c7af4c.js" crossorigin="anonymous"></script>
    <link rel="stylesheet" href="./css/main.css">
</head>

<body>
    <div class="container">
        <div class="title">登录表单</div>
        <div class="user">
            <form class="userid" action="">
                <label id="usericon" for="idname"><i class="fa-solid fa-user"></i></label>
                <input type="text" name="idname" id="idname">
            </form>
        </div>
        <div></div>
        <div></div>
    </div>
</body>

</html>

我的结果 我不想使用inline-flex。谢谢! 英文:

I'm a beginner, can anyone explain how can i remove that Blue background color around my icon when i'm using flexbox?
i can't generalization my properties for children to their parent.
i haven't no global BG color.
i used FONTAWSOME.com website for icons.
result

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

<!-- language: lang-css -->

*{
direction: ltr;
background-color: #55efc4;
box-sizing: border-box;
}
body{
font-size: 16px;
}
.container{
display: flex;
flex-direction: column;
background-color: white;
margin: 150px 500px;
}
.title{
font-size: 2em;
color: white;
background-color: #00b894;
border: 1px solid white;
padding: 20px;
justify-content: center;
align-items:center;
text-align: center;
}
.user{
background-color: white;
display: flex;
flex-direction: row;
justify-content: center;
align-content: center;
align-items: center;
margin: 10px;
padding: 10px;
align-self: center;
}
#usericon{
position: relative;
align-self:auto; 
padding: 0px; 
}
.userid{ 
position: relative;
background-color: white;
align-self:auto;
}
#idname{
position: relative;
align-self: center;
background-color: white;
border: none;
border-bottom: 2px solid #999 ;
border-radius: 5px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
-ms-border-radius: 5px;
-o-border-radius: 5px;
}
#idname:focus{
outline: none;
border: none;
border-bottom: 2px solid #00b894;
-webkit-transition: 3s;
}

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

&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;login&lt;/title&gt;
&lt;meta charset=&quot;UTF-8&quot; /&gt;
&lt;script src=&quot;https://kit.fontawesome.com/5dd6c7af4c.js&quot; crossorigin=&quot;anonymous&quot;&gt;&lt;/script&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;./css/main.css&quot; &gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div class=&quot;container&quot;&gt;
&lt;div class=&quot;title&quot;&gt;LOGIN FORM&lt;/div&gt;
&lt;div class=&quot;user&quot;&gt;
&lt;form class=&quot;userid&quot; action=&quot;&quot;&gt;
&lt;label id=&quot;usericon&quot; for=&quot;idname&quot;&gt;&lt;i class=&quot;fa-solid fa-user&quot;&gt;&lt;/i&gt;&lt;/label&gt;
&lt;input type=&quot;text&quot; name=&quot;idname&quot; id=&quot;idname&quot;&gt;
&lt;/form&gt;
&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;

<!-- end snippet -->

my resaulti don't want to using inline-flex. THANKS

答案1 {#1}

得分: 0

你可以尝试将#usericon{}添加background-color: white
如果你有*{background-color: "cyan"},它会使所有元素的背景变为青色,请查看你的CSS文件中是否有这个青色并找出原因。 英文:

you can try adding background-color: white to #usericon{}.
If you have *{background-color: &quot;cyan&quot;} it makes all the elements backgrounds cyan, look in your css where you have that cyan color and find the cause.


赞(1)
未经允许不得转载:工具盒子 » 如何在使用CSS的FLEXBOX时移除我的图标周围的空白空间?