简体   繁体   English

将Fontawesome-icon与w3输入字段放入同一行

[英]Get Fontawesome-icon into the same line as a w3-input field

So I was working on a webpage as I ran into this problem over here. 所以当我在这里遇到这个问题时,我正在开发一个网页。 I wanted to create my first form with w3.css (not bootstrap), which worked perfectly fine. 我想用w3.css(不是bootstrap)创建我的第一个表单,该表单工作得很好。 But after trying multiple times to add a fa -Fontawesome-Icon in front of my text input field (the height of the fa-icon matches the height of the text input, they are both in the same row), I´m now asking you guys in the community out there - 但是在尝试多次在我的文本输入字段前添加fa -Fontawesome-icon(fa-icon的高度与文本输入的高度匹配,它们都在同一行)之后,我现在要问的是你们社区里的你们-
How can I get the Fontawesome-Icon to the same height and same row/line of a text input field? 如何将Fontawesome-Icon设置为与文本输入字段相同的高度和相同的行/行?
Here´s my code: 这是我的代码:

 body { background-color: black; } 
 <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/> <link href="https://www.w3schools.com/w3css/4/w3.css" rel="stylesheet"/> <form class="w3-container w3-white"> <div class="w3-row-padding"> <div class="w3-col m12"> <i class="fa fa-envelope-o fa-2x fa-fw" aria-hidden="true"></i><p><input class="w3-input w3-animate-input" type="text" placeholder="E-Mail" style="width: 50%;"></p> </div> </div> </form> 

How can I get this working? 我该如何工作?
Thanks for all answers in advance, as always, 与往常一样,感谢您提前提供所有答案,
- SearchingSolutions -搜索解决方案

 body { background-color: black; } .input-icon{ float:left; } 
 <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/> <link href="https://www.w3schools.com/w3css/4/w3.css" rel="stylesheet"/> <form class="w3-container w3-white"> <div class="w3-row-padding"> <div class="w3-col m12"> <p> <i class="fa fa-envelope-o fa-2x fa-fw input-icon" aria-hidden="true"></i> <input class="w3-input w3-animate-input" type="text" placeholder="E-Mail" style="width: 50%;"> </p> </div> </div> </form> 

This does the trick. 这可以解决问题。 There are better ways but this is the base. 有更好的方法,但这是基础。 You can remove or adapt the expand effect. 您可以删除或调整扩展效果。 You can also use position absolute on the icon and padding on the container. 您也可以在图标上使用绝对位置,在容器上使用填充。

The problem is that the input element inherits display: block .w3-input class. 问题是input元素继承了display: block .w3-input类。 You can overwrite this by simply giving an id to the element and setting display: inline . 您可以通过简单地给元素赋予ID并设置display: inline来覆盖它。 Add those: 添加这些:

#inline-input {
    display: inline;
}

* *

<input id = "inline-input" class="w3-input w3-animate-input" type="text" placeholder="E-Mail" style="width: 50%;">

Edit: Also remove <p></p> tags. 编辑:同时删除<p></p>标记。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM