In the following code, I tried to position the font awesome icon inside a text input tag.
But the styling of the <i>
tag does not apply.
After hours, I found out that if I remove the FontAwesome Javascript CDN, it works as expected!
I wonder what exactly goes wrong. Is this a bug in FontAwesome?
Here is the snippet, with FontAwesome Javascript CDN,
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/css/all.min.css">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/js/all.min.js"></script>
<style type="text/css">
input[type="text"] {
width: 50%;
border: 2px solid #aaa;
margin: 8px 0;
outline: none;
padding: 8px;
box-sizing: border-box;
}
.input-with-icon input[type="text"] {
padding-left: 40px;
}
.input-with-icon {
position: relative;
}
.input-with-icon i {
position: absolute;
left: 0;
top: 8px;
padding: 9px 8px;
color: #aaa;
transition: 0.3s;
}
</style>
</head>
<body>
<div class="input-with-icon">
<input type="text" placeholder="Your name">
<i class="fa fa-user fa-lg"></i>
</div>
</body>
</html>
And Now without the FontAwesome Javascript CDN,
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/css/all.min.css">
<style type="text/css">
input[type="text"] {
width: 50%;
border: 2px solid #aaa;
margin: 8px 0;
outline: none;
padding: 8px;
box-sizing: border-box;
}
.input-with-icon input[type="text"] {
padding-left: 40px;
}
.input-with-icon {
position: relative;
}
.input-with-icon i {
position: absolute;
left: 0;
top: 8px;
padding: 9px 8px;
color: #aaa;
transition: 0.3s;
}
</style>
</head>
<body>
<div class="input-with-icon">
<input type="text" placeholder="Your name">
<i class="fa fa-user fa-lg"></i>
</div>
</body>
</html>