Icon font inside text input - css

How to put a awesome icon font inside the bootstrap input type text aligned at left and with some margin-right relative to the placeholder text using bootstrap? Im doing like this: https://jsfiddle.net/tbeay2vd/1/ and using the bootstrap class "input-group-addon" it works but I would like to have a input text like:
Do you know how to do that using bootstrap?
Html:
<div class="container">
<div class="row justify-content-center">
<div class="col col-md-7">
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-search"></i></div>
<input type="text" class="form-control" id="inlineFormInputGroup" placeholder="Search...">
</div>
<!-- How to do this input text below using bootstrap ? -->
<div class="example">
<i class="fa fa-search"></i> Search..
</div>
</div>
</div>
</div>

Try this:
$('input').on('focus', function () {
$(this).parent().addClass('active');
});
.example {
margin-top:30px;
border:1px solid gray;
border-radius:4px;
padding:15px;
}
.example >i {
margin-right:10px;
}
.search-input {
border: none;
width: 90%;
}
.search-input:focus{
outline: none;
}
.example.active {
border-color: #80bdff;
}
.search-box .input-group-addon {
background: none;
}
.search-box input {
border-left: none;
}
.search-box.active .input-group-addon {
border-color: #80bdff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row justify-content-center">
<div class="col col-md-7">
<div class="input-group search-box">
<div class="input-group-addon"><i class="fa fa-search"></i></div>
<input type="text" class="form-control" id="inlineFormInputGroup" placeholder="Search...">
</div>
<!-- Hpw to do this layout using bootstrap ? -->
<div class="example">
<i class="fa fa-search"></i>
<input type="text" class="search-input" id="inlineFormInputGroup" placeholder="Search...">
</div>
</div>
</div>
</div>

.input-group >.fa{
position: absolute;
z-index: 10;
top: 37%;
left: 20px;
}
.input-group .form-control{
padding-left: 40px;
height: 60px;
border: black solid 1px;
position: relative;
border-radius: 5px!important;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row justify-content-center">
<div class="col col-md-7">
<div class="input-group">
<i class="fa fa-search"></i>
<input type="text" class="form-control" id="inlineFormInputGroup" placeholder="Search...">
</div>
</div>
</div>
</div>

Related

`ng-scope` class causing issues with the UI

I have an issue where the ng-scope css class is causing issues with my UI.
Essentially I want my toDoListRow div to have a height of 70%.
But this will not apply unless I define the ng-scope class to have a height of 100%, the issue with that is it then causes unexpected behaviour further down the line whenever a new scope is applied.
I have tried setting the ng-scope to have a min height instead of just height, but this still means my toDoListRow has no height at all.
See first image for what it should look like.
Second image is what it looks like when I don't apply any height to the ng-scope class or use min-height:100%.
index.html
<!DOCTYPE html>
<html lang="en" ng-app="ToDoListApp">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>To Do App</title>
<script src="angular/angular.min.js"></script>
<script src="app.module.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<link rel="stylesheet" href="app/assets/css/styles.css">
<link href="https://fonts.googleapis.com/css?family=Acme&display=swap" rel="stylesheet">
<script src="https://kit.fontawesome.com/4c765e5630.js" crossorigin="anonymous"></script>
</head>
<body>
<div ng-controller="homePageCtrl">
<div class="row header">
<div class="col-12">
<h1>DOINGO</h1>
<p>0 Open Tasks</p>
</div>
</div>
<div class="row toDoListRow">
<div class="row newItem" ng-show="toDoList.length > 1" ng-repeat="item in toDoList">
<div class="col-2">
<button class="itemComplete btn"><i class="far fa-check-circle fa-2x"></i></button>
</div>
<div class="col-8">
<h4>{{item.project}}</h4>
<p>{{item.task}}.</p>
</div>
<div class="col-2">
<button class="btn deleteItem"><i class="far fa-times-circle fa-2x"></i></button>
</div>
</div>
</div>
<div class="row addItemRow">
<div class="col-12 text-center">
<button type="button" class="btn btn addItem" data-toggle="modal" data-target="#newItemModal">
<i class="fas fa-plus-circle fa-3x"></i>
</button>
<div class="modal fade" id="newItemModal" tabindex="-1" role="dialog" aria-labelledby="newItemModal"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title col-11 text-center" id="newItemModal">Add new item</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form ng-submit="addNewToDoTask()">
<div class="form-group">
<label for="projectInput"><strong>Project</strong></label>
<input type="text" class="form-control" id="projectInput"
ng-model="projectInput" placeholder="Enter the name of the project">
</div>
<div class="form-group">
<label for="taskInput"><strong>Task</strong></label>
<input type="text" class="form-control" id="taskInput" ng-model="taskInput"
placeholder="Enter your task details">
</div>
<button type="submit" class="btn modalSubmitButton">Add</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"
integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous">
</script>
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.0/dist/umd/popper.min.js"
integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous">
</script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"
integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous">
</script>
</body>
</html>
styles.css
html,
body {
height: 100%;
width: 100%;
}
.row {
margin: 0;
}
.ng-scope {
min-height: 100%;
}
.header {
background-color: rgb(35, 35, 80);
color: white;
height: 20%;
width: 100%;
text-align: center;
padding-top: 2.5rem;
}
h1 {
font-family: 'Acme', sans-serif;
margin: 0;
}
.toDoListRow {
height: 70%;
width: 100%;
background-color: rgb(252, 70, 100);
}
.newItem {
width: 100%;
margin-top: 2rem;
}
.addItemRow {
height: 10%;
background-color: rgb(252, 70, 100);
}
button {
display: inline-block;
}
.modal-title {
text-align: center;
color: white;
}
.modal-header {
background-color: rgb(35, 35, 80);
}
.modal-body {
background-color: rgb(252, 70, 100);
}
.modalSubmitButton {
background-color: rgb(35, 35, 80);
color: white;
}
Don't use the ng-scope class for that purpose.
Instead define your own classes:
̶.̶n̶g̶-̶s̶c̶o̶p̶e̶ ̶{̶
.toDoList {
height: 100%;
}
.toDoListRow {
height: 70%;
width: 100%;
background-color: rgb(252, 70, 100);
}
And use it in the template:
<div ng-controller="homePageCtrl" class="toDoList">
<div class="row header">
<div class="col-12">
<h1>DOINGO</h1>
<p>0 Open Tasks</p>
</div>
</div>
<div class="row toDoListRow">
<div class="row newItem" ng-repeat="item in toDoList"
ng-show="toDoList.length > 1" >
<div class="col-2">
<button class="itemComplete btn">
<i class="far fa-check-circle fa-2x"></i>
</button>
</div>
This will make your CSS and HTML easier to understand, debug, test, and maintain.
New AngularJS developers often do not realize that ng-repeat, ng-switch, ng-view, ng-include and ng-if all create new child scopes, so the problem often shows up when these directives are involved.1

How to align text messages of a chat window to the bottom?

I'm building a chat window - the height 100% works perfectly, but I can't make the messages appear on the bottom.
HTML:
<div class="d-flex justify-content-center">
<div class="container container-child">
<div class="card">
<div class="card-body">
<div class="text-left"><span class="badge badge-pill badge-secondary" title="2020-01-01 09:00:00">Hello</span></div>
<div class="text-right"><span class="badge badge-pill badge-primary" title="2020-01-01 09:00:00">World</span></div>
</div>
<div class="card-footer">
<div class="input-group input-group-sm">
<input type="text" class="form-control" placeholder="Your message..." autofocus />
<div class="input-group-append">
<button type="button" class="btn btn-primary"><i class="fa fa-paper-plane-o fa-fw"></i><span class="d-none d-sm-inline"> Send</span></button>
</div>
</div>
</div>
</div>
</div>
</div>
CSS:
.d-flex {
height: 100%;
}
.card {
height: 100%;
}
.card-body {
overflow-y: auto;
}
.badge {
font-weight: 400;
}
Screenshot:
You can align your texts to the bottom by turning .card-body into a flex element with display: flex, and then setting margin-top: auto on both .text-left and .text-right.
Unfortunately this brings the right-hand text to the left, and places it on the same line. This can be resolved by adding justify-content: space-between to .card-body, and a margin-bottom of about 20px to .text-left.
This can be seen in the following:
.d-flex {
height: 100vh; /* Changed purely for Stack example */
}
.card {
height: 100%;
}
.card-body {
overflow-y: auto;
}
.badge {
font-weight: 400;
}
/* NEW */
.card-body {
display: flex;
justify-content: space-between;
}
.text-left, .text-right {
margin-top: auto;
}
.text-left {
margin-bottom: 20px;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<div class="d-flex justify-content-center">
<div class="container container-child">
<div class="card">
<div class="card-body">
<div class="text-left"><span class="badge badge-pill badge-secondary" title="2020-01-01 09:00:00">Hello</span></div>
<div class="text-right"><span class="badge badge-pill badge-primary" title="2020-01-01 09:00:00">World</span></div>
</div>
<div class="card-footer">
<div class="input-group input-group-sm">
<input type="text" class="form-control" placeholder="Your message..." autofocus />
<div class="input-group-append">
<button type="button" class="btn btn-primary"><i class="fa fa-paper-plane-o fa-fw"></i><span class="d-none d-sm-inline"> Send</span></button>
</div>
</div>
</div>
</div>
</div>
</div>
Note that given this seems to be a chat application (that would write the messages out sequentially), you'll want to adjust the margin-bottom of each element to have the same value (of 20px in my example) added to it as each new message is generated.

Make text box stop growing after sm break point?

I have a bootstrap 4 input text box. I want make it stop growing after sm break point, so that it won't expand to the full screen width.
Use col-md-* in wrap div of input...
the sm takes all screen and from md and up it takes width as you set in col-md-*
See fiddle:https://jsfiddle.net/s9q4d681/3/
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<div class="container">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input type="email" class="form-control" placeholder="Enter email">
</div>
</div>
</div>
</div>
.row {
margin-top: 20px;
}
.col {
background: #f8f9fa;
border: solid 1px #ddd;
padding: 5px 10px;
}
.col-sm-6 {
background: #f8f9fa;
border: solid 1px #ddd;
padding: 10px;
}
input{
max-width: 340px;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col">
Col-6
</div>
<div class="col">
Col-6
</div>
</div>
<div class="row">
<div class="col-sm-6">
<form action="">
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
</div>
</form>
</div>
</div>
</div>
You can simply restrict input field width using max-width CSS property.

bootstrap3 datetimepicker div cut off calendar

I would like that the calendar to appear outside the .row div but div must have both scrolls bar.
If div have overflow popierty cut off calendar.
I tried set widgetParent to body, but then position of calendar is wrong. Not near input.
<div class="container">
<div class="row" style="border: 1px solid #000; width: 150px; height: 200px; overflow: scroll;">
<div class='col-sm-6'>
<div class="form-group">
<div class='input-group date' id='datetimepicker1'>
<input type='text' style="width: 40px;" class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
</div>
</div>
example
$(function() {
$('#datetimepicker1').datetimepicker();
// $('#datetimepicker1').datetimepicker({widgetParent: 'body'});
});
.row {
position: relative;
border: 1px solid #000;
width: 150px;
height: 200px;
overflow: show;
}
.row #datetimepicker1 {
position: absolute;
z-index: 10001;
top: 20px;
right: 20px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.min.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class='col-sm-6'>
<div class="form-group">
<div class='input-group date' id='datetimepicker1'>
<input type='text' class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
</div>
</div>
Try not to write inline css , instead you can give class and then write css in that class.
Is this the same that you are looking for?
Hope this helps.
Change your .row's overflow to 'show.'
So:
<div class="row" style="border: 1px solid #000; width: 150px; height: 200px; overflow: show;">

Bootstrap big margin below help-block class

I am making this simple form using bootstrap but there seems to be a big margin below the .help-block class. How can I remove it without affecting the responsiveness or am I doing something wrong?
.user-help {
background: red;
color: white;
text-align: center;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class='container'>
<form class='form-horizontal'>
<div class='form-group'>
<input id='fname' type='text' class='form-control' placeholder='First Name'>
<div class='help-block user-help'>First name missing</div>
</div>
<div class='form-group'>
<button type='submit' class='btn btn-primary btn-block'>Sign Up</button>
</div>
</form>
</div>
Apply margin-bottom: 0; to .user-help and .form-group specifying their parent div class.
.form-group .user-help {
background: red;
color: white;
text-align: center;
margin-bottom: 0;
}
.form-horizontal .form-group {
margin-bottom: 0;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class='container'>
<form class='form-horizontal'>
<div class='form-group'>
<input id='fname' type='text' class='form-control' placeholder='First Name'>
<div class='help-block user-help'>First name missing</div>
</div>
<div class='form-group'>
<button type='submit' class='btn btn-primary btn-block'>Sign Up</button>
</div>
</form>
</div>
A big margin below the .help-block class, There are two reasons:
.form-group has style with margin-bottom: 15px;
.help-block has style with margin-bottom: 10px;
You can change or remove margin-bottom value of either the first .form-group class or .help-block class.

Resources