Div under input field - html

I want to display a div exactly below an input field. Of course, it's simple to achieve this, but I want this to work also with mobile. It's not working to good with media queries, so is there another way?
It's a live search. I want the div #display to be exactly under the input.
It's working on desktop machines, but not on mobile devices. Is there a general way or do I really have to use media queries with a fixed margin, width, and height?
#display {
background-color: #f2f2f2;
position: absolute;
width: 227px;
border: solid;
border-top: none;
border-radius: 0px 0px 5px 5px;
border-width: thin;
z-index: 1 !important;
}
.live-search {
min-height: 30px;
display: flex;
align-items: center;
}
<form class="form-inline my-2 my-lg-0" action="search.php" method="post" autocomplete="off">
<input type="search" name="search" required="" placeholder="Search">
<button class="btn my-2 my-sm-0" id="search-btn" type="submit">Search</button>
</form>
<div id="display" style="display: block;">
<a href="candidate.php?id=82925298">
<div class="live-search">
<li>82925298, Webdeveloper</li>
</div>
</a>
</div>

#display {
background-color: #f2f2f2;
width: 181px;
border: solid;
border-top: none;
border-radius: 0px 0px 5px 5px;
border-width: thin;
z-index: 1 !important;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
<form action="search.php" method="post" ...>
<input type="search" name="search" ...>
<button id="search-btn" type="submit">
Search
</button>
</form>
<div id="display">
<a href="candidate.php?id=82925298">
<div class="live-search">
<li>82925298, WebDeveloper</li>
<li>82925299, WebDesigner</li>
</div>
</a>
</div>

Related

How can set element alignment which is inside parent with the child style setting in element style attributes?

.popup {
position: relative;
display: inline-block;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.popup .popuptext {
visibility: hidden;
width: 160px;
background-color: #555;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 8px 0;
position: absolute;
z-index: 1;
bottom: 125%;
left: 50%;
margin-left: -80px;
}
I have above codes in my css file that added in html head <link href="/static/styles.css" rel="stylesheet">
In my html there where many uses of .popupand .popuptext and I wont change above styles.
In the html code is here↓
<div class="popup" style="display: inline"><div class="popuptext" id="tableHeader">
<label>data type</label>
<br>
<input type="checkbox" name="not_null"> NOT NULL
<br>
<input type="checkbox" name="unique"> UNIQUE
<br>
<button class="btn btn-danger" type="submit" name="delete">Delete</button>
</div></div>
All elements above are aligned as center.
But I need centralize the Delete button and the label and other input elements be left aligned.
As I consist change style from html code and stylesheet has other uses, I have tried below↓
<div class="popup" style="display: inline"><div class="popuptext" id="tableHeader">
<label>data type</label>
<br>
<span style="text-align: left;"><input type="checkbox" name="not_null"> NOT NULL</span>
<br>
<span style="text-align: left;"><input type="checkbox" name="unique"> UNIQUE</span>
<br>
<button class="btn btn-danger" type="submit" name="delete">Delete</button>
</div></div>
But input elements remain centralist and not left aligned!
I need input get left aligned only with change style settings in html element attributes.
Leaving the html as it is, you could style the .popuptext children as display:block so that they will take the whole width. Then you can style indipendently its parts:
The <label> element - its content gets centered with text-align: center
The <input> elements - they get aligned to left with text-align: left; but just because we are actually styling their parents
<span>
The <button> element - this required margin: 0 auto meaning that the left
and right margins will be set to the maximum available space in the
row
Everything else in the styles here in the demo is for decoration purpose.
.popup{
border: solid;
width: 10em;
background: lightgray;
}
.popuptext > *{
display: block;
}
.popuptext > span{
text-align: left;
}
.popuptext > label{
text-align: center;
margin-bottom: .5em;
}
.popuptext > button{
margin: .5em auto;
border: none;
background: red;
color: white;
padding: .8em .6em;
border-radius: 5px;
}
<div class="popup">
<div class="popuptext" id="tableHeader">
<label>data type</label>
<span><input type="checkbox" name="not_null"> NOT NULL</span>
<span><input type="checkbox" name="unique"> UNIQUE</span>
<button class="btn btn-danger" type="submit" name="delete">Delete</button>
</div>
</div>
You can restructure your HTML and CSS as such:
.popup .popuptext {
width: 160px;
background-color: #555;
color: #fff;
border-radius: 6px;
padding: 8px 0;
position: absolute;
z-index: 1;
}
.popuptext .checkbox-holder {
width: fit-content;
margin: auto;
}
<div class="popup" style="display: inline">
<div class="popuptext" id="tableHeader">
<div style="text-align: center;"><label>data type</label></div>
<div class="checkbox-holder">
<div><input type="checkbox" name="not_null" id="not_null"> <label for="not_null">NOT NULL</label></div>
<div><input type="checkbox" name="unique" id="unique"> <label for="unique">UNIQUE</label></div>
</div>
<div style="text-align:center"><button class="btn btn-danger" type="submit" name="delete">Delete</button>
</div>
</div>
</div>

Reducing modal window size to fit form fields modifing CSS

I'm building a webpage and I need to create a registration and login form.
I wrote all the html/css code but I can't understand how to make fields to fit the form. I tried to modifie .modal-dialog and .modal-content CSS and by modifing .modal-content padding I can reduce the size of fields but a big white space remains all around them.
How can I eliminate this white space?
.modal {}
.modal-content {
padding: 80px;
}
.modal-body input {
padding: 5px;
margin-bottom: 30px;
width: 100%;
box-sizing: border-box;
box-shadow: none;
outline: none;
border: none;
border-bottom: 2px solid #999;
}
.modal-body input[type="submit"] {
border-radius: 25px;
font-size: 20px;
height: 40px;
cursor: pointer;
background: rgb(255, 69, 0);
color: #fff;
margin-bottom: 0;
}
.modal-body input[type="submit"]:hover {
background: rgb(255, 127, 80);
color: #fff;
}
.modal-body form div {
position: relative;
}
.modal-body form div label {
position: absolute;
top: 3px;
pointer-events: none;
left: 0;
transition: .5s;
}
.modal-body input:focus~label,
.modal-body input:valid~label {
left: 0;
top: -16px;
color: rgb(169, 169, 169);
font-size: 12px;
font-weight: bold;
}
.modal-body input:focus,
.modal-body input:valid {
border-bottom: 2px solid rgb(169, 169, 169);
}
<!--Nav bar buttons-->
<form>
<!-- Button trigger modal -->
<button id="signupBtn" type="button" class="btn btn-primary" data-toggle="modal" data-target="#signupModalBtn">Registrati</button>
<button id="loginBtn" type="button" class="btn btn-primary" data-toggle="modal" data-target="#loginModalBtn">Log
In</button>
</form>
<!-- Modal SignUp-->
<div class="modal fade" id="signupModalBtn" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="contentinfo">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Registrati e inizia ad imparare!</h5>
<button id="signupCloseBtn" type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form>
<div>
<input type="text" name="Username" required="">
<label>Username</label>
</div>
<div>
<input type="text" name="First Name" required="">
<label>First Name</label>
</div>
<div>
<input type="text" name="Second Name" required="">
<label>Second Name</label>
</div>
<div>
<input type="email" name="Email" required="">
<label>Email </label>
</div>
<div>
<input type="password" name="Passowrd" required="">
<label>Password</label>
</div>
<div>
<input type="password" name="Re-Enter Password" required="">
<label>Re-Enter Password</label>
</div>
<input id="singupInternalBtn" type="submit" value="Registrati" name="Submit">
</form>
</div>
<div class="modal-footer">
<p id="signupBtnTextFooter">Hai già un account?Effettua il Log In!</p>
</div>
</div>
</div>
</div>
I'd like to create a registration/logIn form like Udemy ones (speaking about size),I'll add an img of what I got now!
https://ibb.co/StStxbH
Try giving below css, as modal-dialog need to have max-width, you need to set max-width for it like below,
body {
background: #000;
padding: 20px;
}
.modal-dialog {
max-width: 600px;
background: #FFF;
margin: auto;
}
.modal-content {
padding: 20px;
}
.modal {}
.modal-content {
padding: 80px;
}
.modal-body input {
padding: 5px;
margin-bottom: 30px;
width: 100%;
box-sizing: border-box;
box-shadow: none;
outline: none;
border: none;
border-bottom: 2px solid #999;
}
.modal-body input[type="submit"] {
border-radius: 25px;
font-size: 20px;
height: 40px;
cursor: pointer;
background: rgb(255, 69, 0);
color: #fff;
margin-bottom: 0;
}
.modal-body input[type="submit"]:hover {
background: rgb(255, 127, 80);
color: #fff;
}
.modal-body form div {
position: relative;
}
.modal-body form div label {
position: absolute;
top: 3px;
pointer-events: none;
left: 0;
transition: .5s;
}
.modal-body input:focus~label,
.modal-body input:valid~label {
left: 0;
top: -16px;
color: rgb(169, 169, 169);
font-size: 12px;
font-weight: bold;
}
.modal-body input:focus,
.modal-body input:valid {
border-bottom: 2px solid rgb(169, 169, 169);
}
body {
background: #000;
padding: 20px;
}
.modal-dialog {
max-width: 600px;
background: #FFF;
margin: auto;
}
.modal-content {
padding: 20px;
}
<!--Nav bar buttons-->
<form>
<!-- Button trigger modal -->
<button id="signupBtn" type="button" class="btn btn-primary" data-toggle="modal" data-target="#signupModalBtn">Registrati</button>
<button id="loginBtn" type="button" class="btn btn-primary" data-toggle="modal" data-target="#loginModalBtn">Log
In</button>
</form>
<!-- Modal SignUp-->
<div class="modal fade" id="signupModalBtn" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="contentinfo">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Registrati e inizia ad imparare!</h5>
<button id="signupCloseBtn" type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form>
<div>
<input type="text" name="Username" required="">
<label>Username</label>
</div>
<div>
<input type="text" name="First Name" required="">
<label>First Name</label>
</div>
<div>
<input type="text" name="Second Name" required="">
<label>Second Name</label>
</div>
<div>
<input type="email" name="Email" required="">
<label>Email </label>
</div>
<div>
<input type="password" name="Passowrd" required="">
<label>Password</label>
</div>
<div>
<input type="password" name="Re-Enter Password" required="">
<label>Re-Enter Password</label>
</div>
<input id="singupInternalBtn" type="submit" value="Registrati" name="Submit">
</form>
</div>
<div class="modal-footer">
<p id="signupBtnTextFooter">Hai già un account?Effettua il Log In!</p>
</div>
</div>
</div>
</div>

How to add in input form button cancel

I would like to do something like this.
but i dont know how to do it in Bootstrap correctly
Here's my html code where i get only like this.
<form class="navbar-form" role="search">
<div class="input-group add-on">
<input type="text" [(ngModel)]="text" class="form-control" placeholder="Search" name="text">
<button class="btn btn-default" type="submit" (click)="clear()"><i class="glyphicon glyphicon-remove"></i></button>
<div class="input-group-btn">
<button class="btn btn-default" type="submit" (click)="search()"><i class="glyphicon glyphicon-search"></i></button>
</div>
</div>
</form>
I honestly think that buttons are a pain in the butt and are outdated. I much rather use a simple div, a or in this case i tag.
Therefore this might not be completely what OP asked for but in my eyes it is a more elegant solution.
The secret to this solution is using the flex property to the wrapper, which makes it possible to automatically size its children within its space.
.field {
display: flex;
position: relative;
max-width: 285px;
min-width: 200px;
width: 100%;
flex-direction: row;
}
Please check out the snippet for a more specific example. This works in all modern browsers and from internet explorer 10.
var input = document.getElementById("search");
function clearInput() {
input.value = "";
}
function search () {
console.log("searching");
// Implement search function here...
}
.field {
display: flex;
position: relative;
max-width: 285px;
min-width: 200px;
width: 100%;
flex-direction: row;
}
.field > input[type=text] {
flex: 1;
padding: 0.6em 0.6em 0.6em 1.5em;
border: 1px solid #c4c4c4;
border-right: none;
display: block;
}
.field > div {
padding: 0.4em 0;
background-color: #fff;
border: 1px solid #c4c4c4;
border-left: none;
border-radius: 1px;
display: inline-block;
cursor: pointer;
}
.field > div > i {
padding: 0.2em 0.8em;
background-color: inherit;
color: #555555;
border: none;
border-left: 1px solid #c4c4c4;
margin-right: 1px;
}
.field > div:last-child > i {
border-left: none;
}
.field > div:hover > i {
color: #009BDB;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css" rel="stylesheet"/>
<div class="field">
<input type="text" id="search" placeholder="Search..." />
<div>
<i class="fa fa-times" onclick="clearInput()"></i>
</div>
<div>
<i class="fa fa-search" onclick="search()"></i>
</div>
</div>
You could play around with position: relative,
for example:
html:
<form class="navbar-form" role="search">
<div class="input-group add-on">
<input type="text" [(ngModel)]="text" class="form-control" placeholder="Search" name="text">
<button class="btn btn-default test" type="submit" (click)="clear()"><i class="glyphicon glyphicon-remove"></i></button>
<div class="input-group-btn">
<button class="btn btn-default" type="submit" (click)="search()"><i class="glyphicon glyphicon-search"></i></button>
</div>
</div>
</form>
css:
.form-control {
position:relative;
}
.test {
position:relative;
right:20px;
}
example jsfiddle: https://jsfiddle.net/DTcHh/92025/

How to center a button

I'm trying to center the submit button at the bottom.
Here is the code:
* {
margin: 0px;
padding: 0px;
}
body {
font-size: 120%;
background: #F8F8FF;
}
.header {
width: 30%;
margin:50px auto 0px;
color: white;
background: #5F9EA0;
text-align:center;
border: 1px solid #B0C4DE;
border-bottom: none;
border-radius: 10px 10px 0px 0px;
padding: 20px;
}
form, .content {
width: 576px;
margin: 0px auto;
padding: 20px;
border: 1px solid #B0C4DE;
background: white;
border-radius: 0px 0px 10px 10px;
}
.input-group {
margin: 10px 0px 10px 0px;
}
.input-group label {
display: block;
text-align: left;
margin: 3px;
}
.input-group input {
height: 20px;
width: 60%;
padding: 5px 10px;
font-size: 1em;
border-radius: 1px;
border: 1px solid gray;
margin-left: 3px;
}
.btn {
padding: 8px;
font-size: 1em;
color: white;
background: #5F9EA0;
border: none;
border-radius: 5px;
margin:0 auto;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Register-Art and chill</title>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
<div class="header">
<h2> Register </h2>
</div>
<form method="post" action="register.php">
<div class="input-group">
<label> Username </label>
<input type="text" name="username">
</div>
<div class="input-group">
<label> Email </label>
<input type="email" name="email">
</div>
<div class="input-group">
<label> Password </label>
<input type="password" name="password_1">
</div>
<div class="input-group">
<label> ConfirmPassword </label>
<input type="password" name="password_2">
</div>
<div class="input-group">
<button type="submit" class="btn"> Register </button>
</div>
</form>
</body>
</html>
Replace your .btn CSS class with this:
.btn {
padding: 8px;
font-size: 1em;
color: white;
background: #5F9EA0;
border: none;
border-radius: 5px;
margin:0 auto;
display:block;
}
The problem is the default display:inline-block
You can put text-align: center; on the container that the button is in, i.e. .input-group. Of course if you put it in .input-group, all the other elements whose parent is an .input-group will be centered as well, so you might have to make a class just for the button or put an inline style on the button's .input-group parent.
CSS
.input-group-btn {
text-align:center;
}
HTML
<div class="input-group input-group-btn">
<button type="submit" class="btn"> Register </button>
</div>
Add display: block; to .btn class
To make it more neat and clean, replace your html with the following code:-
<form method="post" action="register.php">
<div class="form-inner">
<div class="input-group">
<label> Username </label>
<input type="text" name="username">
</div>
<div class="input-group">
<label> Email </label>
<input type="email" name="email">
</div>
<div class="input-group">
<label> Password </label>
<input type="password" name="password_1">
</div>
<div class="input-group">
<label> ConfirmPassword </label>
<input type="password" name="password_2">
</div>
<div class="input-group">
<button type="submit" class="btn"> Register </button>
</div>
</div>
</form>
And add this to your CSS:-
.form-inner {
width: 60%;
}
Live example here:- https://jsfiddle.net/sq6zow6v/

How to position inline textbox and button using bootstrap above the Google Map?

I need to position the textbox and button inline and that's correct. But when I try different view example tablet view the textbox fit but the button stay in the position. Please see the image.
<input id="search" class="form-control" type="text" placeholder="Search Location" style="margin-left: 100px; margin-top: 10px; position: absolute; width: 30%; z-index: 1;">
<input type="button" class="btn btn-default" onclick="location.reload();" style="margin-left: 700px; width: 10%; margin-top: 10px; position: absolute; z-index: 1; background-color: #ffffff; border: 1px solid #dce4ec; color: #2c3e50" value="Refresh" />
<div id="map" style="position: relative;"></div>
using this #chaitz9:
<input id="search" class="form-control" placeholder="Search Location" style="margin-top: 10px; width: 30%; z-index: 1; margin-left: 100px;" type="text">
<input class="btn btn-default" onclick="location.reload();" style="margin-top: 10px; z-index: 1; background-color: rgb(255, 255, 255); border: 1px solid rgb(220, 228, 236); color: rgb(44, 62, 80); width: 15%;" value="Refresh" type="button">
<div id="map" style="position: relative;"></div>
the output:
Edited: Try using this CSS. I have now wrapped the input fields into a div and given the div property of display: table. And to the input fields display: table-cell
.loc_div{
display: table !important;
width:100%;
}
#search{
margin-left: 100px;
margin-top: 10px;
width: 30%;
z-index: 1;
position:relative;
display:table-cell;
}
.btn {
background-color: #ffffff;
border: 1px solid #dce4ec;
color: #2c3e50;
margin-top: 10px;
width: 20%;
z-index: 1;
margin-left: 10px;
display:table-cell;
}
<div class="loc_div">
<input id="search" class="form-control" placeholder="Search Location" type="text">
<input class="btn btn-default" onclick="location.reload();" value="Refresh" type="button">
</div>
<div id="map" style="position: relative;"></div>