Bootstrap spinner overlay form (not whole page) - html

I would like to have bootstrap spinner that is on top of the form (it overlays form). However, the only thing I was able to get is to overlay the whole page. I am using Bootstrap.
<style>
.overlay {
position: fixed;
width: 100%;
height: 100%;
z-index: 1000;
top: 40%;
left: 0px;
opacity: 0.5;
filter: alpha(opacity=50);
}
</style>
<div class="overlay" id="loading" >
<div class="d-flex justify-content-center">
<div class="spinner-border" role="status" >
<span class="sr-only">Loading...</span>
</div>
</div>
</div>
<form method="post">
<div class="form-group">
<label for="num">Enter number <span>?</span></label>
<input id="num" type="text" class="form-control"/>
</div>
<button type="submit" class="btn btn-primary">Check </button>
</form>

U should put the spinner inside your form like this
<form method="post">
<div class="overlay" id="loading" >
<div class="d-flex justify-content-center">
<div class="spinner-border" role="status" >
<span class="sr-only">Loading...</span>
</div>
</div>
</div>
<fieldset disabled>
<div class="form-group">
<label for="num">Enter number <span>?</span></label>
<input id="num" type="text" class="form-control"/>
</div>
<button type="submit" class="btn btn-primary">Check </button>
</fieldset>
</form>
then give the spinner an absolute position
form {
position: relative;
border: 1px solid red
}
.overlay {
position: absolute;
top: 50%;
left: 50%;
opacity: 0.5;
transform: translate(-50%, -50%);
}

Related

How do I make a <label> stay on the same line as it's <form>

I haven't been able to figure out how to implement their tips into my styling. How can I get my label to be on the left of my input, on the same line? Also I'm just learning how to code so sorry for the inevitable sloppy-ness. This is my code:
body {
background-color: #f5f5f5;
;
}
.rng_box {
background-color: white;
width: 70%;
max-width: 800px;
left: 50%;
top: 460px;
border-radius: 20px;
padding: 20px;
position: absolute;
transform: translate(-50%, -50%);
box-shadow: 0px 2px 6px 2px #E5E5E5;
border: solid 3px #DEDEDE;
}
.title {
text-align: center;
}
.form-control {
width: 180px;
height: 30px;
margin-left: 45px;
}
.btn {
margin: 1px;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
<div class="rng_box">
<h1 class="title">Random Number Generator</h1>
<div>
<form id="minAndMax">
<label for="min">Minimum:</label><br>
<input type="number" id="min" name="min" class="form-control" value="1">
<label for="max">Maximum:</label><br>
<input type="number" id="max" name="max" class="form-control" value="10">
<br>
<div class="buttons">
<button type="button" class="btn btn-success" onclick="generateRN()">Generate 🎉</button>
<button type="button" class="btn btn-danger" onclick="ignoreFields()">Ignore Fields</button>
<button type="reset" class="btn btn-primary">Clear</button>
</div>
</form>
</div>
<hr>
<h1 id="rng_answer">0</h1>
</div>
It's easy, wrap your label and input inside a div and use flex.
https://www.w3schools.com/css/css3_flexbox.asp
Check the code below:
.label-wrap{
display:flex;
}
<div class='label-wrap'>
<label for="min">Minimum:</label><br>
<input type="number" id="min" name="min" class="form-control" value="1">
</div>
The reason is that .form-control css class has a display: block property in the _forms.scss file.
Such a property automatically makes the component goes to a new line. You can use display: inline-block !important instead and you will see the input going on the same line as the label.
In addition to this, you have also <br> tags right next your label tag to be removed.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
<link rel="stylesheet" href="RNG.css">
<title>Random Number Generator</title>
<link rel="icon" type="image/png" href="/Users/trippyrock/Desktop/ToolScape/favicon.png">
<style>
body {
background-color: #f5f5f5;;
}
.rng_box {
background-color: white;
width: 70%;
max-width: 800px;
left: 50%;
top: 460px;
border-radius: 20px;
padding: 20px;
position: absolute;
transform: translate(-50%,-50%);
box-shadow: 0px 2px 6px 2px #E5E5E5;
border: solid 3px #DEDEDE;
}
.title {
text-align: center;
}
.form-control {
width:180px;
height:30px;
margin-left: 45px;
display: inline-block !important;
}
.btn {
margin: 1px;
}
</style>
</head>
<body>
<div class= "rng_box">
<h1 class="title">Random Number Generator</h1>
<div>
<form id="minAndMax">
<label for="min">Minimum:</label>
<input type="number" id="min" name="min" class="form-control" value="1">
<br>
<label for="max">Maximum:</label>
<input type="number" id="max" name="max" class="form-control" value="10">
<br>
<div class="buttons">
<button type="button" class="btn btn-success" onclick="generateRN()">Generate 🎉</button>
<button type="button" class="btn btn-danger" onclick="ignoreFields()">Ignore Fields</button>
<button type="reset" class="btn btn-primary">Clear</button>
</div>
</form>
</div>
<hr>
<h1 id="rng_answer">0</h1>
</div>
<script src="RNG.js"></script>
</body>
</html>
if you are using bootstrap. you can use the bootstrap forms with other utility classess.
<div class="shadow-sm w-75 mx-auto mt-4 p-3 rounded-lg mw-75 text-center">
<h1>Random Number generator</h1>
<form class="form-horizontal" id="minAndMax">
<div class="form-group row">
<label class="col-4 col-form-label">Minimum:</label>
<div class="col-8">
<input type="number" id="min" name="min" class="form-control" value="1" />
</div>
</div>
<div class="form-group row">
<label class="col-4 col-form-label">Maximum:</label>
<div class="col-8">
<input type="number" id="max" name="max" class="form-control" value="10" />
</div>
</div>
<div class="d-flex justify-content-center">
<button type="button" class="btn btn-success mr-2" onclick="">Generate &#x1f389</button>
<button type="button" class="btn btn-danger mr-2" onclick="">Ignore Fields</button>
<button type="reset" class="btn btn-primary" onclick="">Clear</button>
</div>
</form>
</div>

How could I put new block on top of the another block

I've had a block 'jumbotron' it has next css parameters:
.jumbotron {
position: absolute;
top: 50%;
left:50%;
transform: translate(-50%,-50%);
background: rgba(0, 0, 0, 0.7);
border-radius: 20px;
}
It's looks so good in the centre of window. But now I want put "container button-block"on that. With next css parameters it looks great too..
.button-block {
position: absolute;
top: 5%;
left: 36%;
}
But if I try to change windows size my 'button-block' is starting to dance and brakes design. How can I stick these buttons to jumbotron block What decision will more common?
.jumbotron {
position: absolute;
top: 50%;
left:50%;
transform: translate(-50%,-50%);
background: rgba(0, 0, 0, 0.7);
border-radius: 20px;
}
.button-block {
position: absolute;
top: 5%;
left: 36%;
}
<div class="page-header" style="background-image: url('../assets/img/background_presentation.jpg');">
<div class="container button-block">
<button type="button" class="btn btn-default btn-circle btn-xl active">1</button>
<button type="button" class="btn btn-default btn-circle btn-xl">2</button>
<button type="button" class="btn btn-default btn-circle btn-xl">3</button>
</div>
<div class="container">
<header class="jumbotron">
<h2 class="text-center text-white header">What is the property Address</h2>
<form>
<div class="form-group">
<label for="inputAddress" class="text-white">Address</label>
<input type="text" class="form-control" id="inputAddress">
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label for="inputCity" class="text-white">City</label>
<input type="text" class="form-control" id="inputCity">
</div>
<div class="form-group col-md-6">
<label for="inputZip" class="text-white">Zip</label>
<input type="text" class="form-control" id="inputZip">
</div>
</div>
<div class="col-md-12 text-center block-buttons">
<button type="submit" class="btn btn-neutral btn-lg">Continue</button>
</div>
</form>
</header>
</div>
</div>
Something like this?
.container{text-align: center;}
.jumbotron {
position: relative;
top: 50%;
display: inline-block;
margin-top: 25%;
/*transform: translate(-50%,-50%);*/
background: rgba(0, 0, 0, 0.7);
border-radius: 20px;
}
.button-block {
position: absolute;
top: -22px;
left: 36%;
}
<div class="page-header" style="background-image: url('../assets/img/background_presentation.jpg');">
<div class="container">
<header class="jumbotron">
<div class="container button-block">
<button type="button" class="btn btn-default btn-circle btn-xl active">1</button>
<button type="button" class="btn btn-default btn-circle btn-xl">2</button>
<button type="button" class="btn btn-default btn-circle btn-xl">3</button>
</div>
<h2 class="text-center text-white header">What is the property Address</h2>
<form>
<div class="form-group">
<label for="inputAddress" class="text-white">Address</label>
<input type="text" class="form-control" id="inputAddress">
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label for="inputCity" class="text-white">City</label>
<input type="text" class="form-control" id="inputCity">
</div>
<div class="form-group col-md-6">
<label for="inputZip" class="text-white">Zip</label>
<input type="text" class="form-control" id="inputZip">
</div>
</div>
<div class="col-md-12 text-center block-buttons">
<button type="submit" class="btn btn-neutral btn-lg">Continue</button>
</div>
</form>
</header>
</div>
</div>

Button format becomes disorganized when screen size is reduced

I've included a snippet below. If you run the snippet at full screen, you'll see the effect I want (buttons 1 and 2 on the left, and 3 and 4 on the right). However when you make the window smaller, buttons 1 and 2 move to the right and above button 3 and 4, which move to the left.
I could fix this with media queries but I think it would be better to just figure out what I can do to fix this without them.
#lower-bar {
background-color: #0F6292;
height: 80px;
position: relative;
}
.center-left {
position: relative;
top: 50%;
transform: translate(40%, 70%);
}
.center-center {
position: relative;
top: 50%;
transform: translate(25%, 70%);
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<section id='lower-bar'>
<div class='row'>
<div class='col-md-6'>
<div class='center-left'>
<input type="button" id='btn-1' class=" btn c-btn-quiz" value="1">
<input type="button" id='btn-2' class=" btn c-btn-quiz" value="2">
</div>
</div>
<div class='col-md-6'>
<div class='center-center'>
<input type="button" id='3' class="btn c-btn-quiz" value="3">
<input type="button" id="4" class="btn c-btn-quiz" value="4">
</div>
</div>
</div>
</section>
Add this changes to your codes,
#lower-bar {
background-color: #0F6292;
width:100%;
height: 80px;
position: relative;
}
.center-left {
width:50%;
height:auto;
float:left;
margin-top:30px;
}
.center-center {
width:50%;
height:auto;
float:left;
margin-top:30px;
}
Maybe this will help because it seems like you could greatly simplfy this by using pull-right and pull-left is this is to remain the same across viewports. See Quick Floats
#lower-bar {
background-color: #0F6292;
padding: 10px 0;
position: relative;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<section id="lower-bar">
<div class="container">
<div class="pull-left">
<input type="button" id="btn-1" class="btn c-btn-quiz" value="1">
<input type="button" id="btn-2" class="btn c-btn-quiz" value="2">
</div>
<div class="pull-right">
<input type="button" id="3" class="btn c-btn-quiz" value="3">
<input type="button" id="4" class="btn c-btn-quiz" value="4">
</div>
</div>
</section>
I think the best solution would to use flex boxes.
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<link rel="stylesheet" href="style.css" />
<section id='lower-bar'>
<div class='row'>
<div class='center-left'>
<input type="button" id='btn-1' class=" btn c-btn-quiz" value="1">
<input type="button" id='btn-2' class=" btn c-btn-quiz" value="2">
</div>
<div class='center-center'>
<input type="button" id='3' class="btn c-btn-quiz" value="3">
<input type="button" id="4" class="btn c-btn-quiz" value="4">
</div>
</div>
Here is the css
#lower-bar {
background-color: #0F6292;
display: flex;
}
.row {
display: flex;
align-items: center;
width: 100%;
}
.center-left {
display: flex;
margin-left: 25%;
}
.center-left input {
margin-left: 2px;
margin-right: 2px;
}
.center-center {
display: flex;
margin-left: auto;
margin-right: 25%;
}
.center-center input {
margin-left: 2px;
margin-right: 2px;
}

How to give a space between model label and model text field

I am trying to give a space between label and text field using twitter bootstarp.
bellow is the screenshot
I want to give a space between
User Name label space User Name text field
same withe other field.
how can I do that
This is my code
<div class="modal fade" id=addNewUser tabindex="-1" role="dialog" aria-labelledby="helpModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myModalLabel">New User</h4>
</div>
<div class="modal-body">
<form class="AddUser" role="form">
<div class="input-group col-md-8"> <span class="input-group-addon ">User Name</span>
<input class="form-control" type="text" class="form-control" placeholder="User Name" />
</div>
<div class="input-group col-md-8"> <span class="input-group-addon">Password </span>
<input class="form-control" type="text" class="form-control" placeholder="Password" />
</div>
<div class="input-group col-md-8"> <span class="input-group-addon">Roles</span>
<div class="checkbox">
<label>
<input type="checkbox">Admin</label>
</div>
</div>
<div class="input-group col-md-8"> <span class="input-group-addon">Status</span>
<div class="radio">
<label>
<input type="radio">Active</label>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default blue-btn">Add User</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</form>
</div>
</div>
</div>
</div>
When I am applying this
.input-group-addon { display: inline-block; margin-right: 12px; width: 80px; }
Css Which I am using
.input-group-addon {
min-width:100px;
text-align:left;
}
.modal-dialog {
height: 80%;
padding-top:10%;
}
.modal-content {
height: 60% !important;
overflow:visible;
}
.modal-body {
height: 70%;
overflow: auto;
}
.modal-footer {
position:absolute;
bottom:0;
left:0;
right:0;
}
Insert &nbsp to the end of your captions
&nbsp is the entity used to represent a non-breaking space. It is essentially a standard space, the primary difference being that a browser should not break (or wrap) a line of text at the point that this occupies.
OR using CSS..
Provide your stylesheet with a class for form input elements making use of the margin: style.
In this case you would use a style on the class="input-group-addon" field.
.input-group-addon {
margin-right: 1em;
}
maybe try something like:
.input-group-addon { display: inline-block; margin-right: 12px; width: 80px; }

Bootstrap: Centering 2 forms next to eachother in Carousel Template?

I am trying to center two forms sitting next to each other in twitter's bootstrap.
This is the template I am using given by Bootstrap
and this is the code I have so far. What it does is placing them on the top of each other.
<!-- Carousel
================================================== -->
<div id="myCarousel" class="carousel">
<div class="carousel-inner">
<div class="item active">
<img class="header" src="img/header_bg.jpg" alt="">
<div class="container">
<div class="row-fluid">
<div class="span12">
<div class="logo"><img src="img/logo.png" height="105px" width="96px"></div>
</div>
</div>
</div> <!-- container logo -->
<div class="container">
<div class="carousel-caption">
<form class="form-horizontal">
<div class="control-group">
<label class="control-label" for="inputEmail">Email</label>
<div class="controls">
<input type="text" id="inputEmail" placeholder="Email">
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword">Password</label>
<div class="controls">
<input type="password" id="inputPassword" placeholder="Password">
</div>
</div>
<div class="control-group">
<div class="controls">
<label class="checkbox">
<input type="checkbox"> Remember me
</label>
<button type="submit" class="btn">Sign in</button>
</div>
</div>
</form>
<form class="form-horizontal">
<div class="control-group">
<label class="control-label" for="inputEmail">Email</label>
<div class="controls">
<input type="text" id="inputEmail" placeholder="Email">
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword">Password</label>
<div class="controls">
<input type="password" id="inputPassword" placeholder="Password">
</div>
</div>
<div class="control-group">
<div class="controls">
<label class="checkbox">
<input type="checkbox"> Remember me
</label>
<button type="submit" class="btn">Sign in</button>
</div>
</div>
</form>
</div>
</div>
</div> <!-- item active -->
</div> <!-- carousel-inner -->
</div><!-- /.carousel -->
Here is the CSS:
/* Carousel base class */
.carousel {
margin-bottom: 60px;
}
.carousel .container {
position: relative;
z-index: 9;
}
.carousel-control {
height: 80px;
margin-top: 0;
font-size: 120px;
text-shadow: 0 1px 1px rgba(0,0,0,.4);
background-color: transparent;
border: 0;
z-index: 10;
}
.carousel .item {
height: 700px;
}
.carousel img.header {
position: absolute;
top: 0;
left: 0;
min-width: 100%;
height: 700px;
}
.carousel-caption {
background-color: transparent;
position: static;
max-width: 400px;
margin-top: 100px;
}
.carousel-caption h1,
.carousel-caption .lead {
margin: 0;
line-height: 1.25;
color: #fff;
text-shadow: 0 1px 1px rgba(0,0,0,.4);
}
.carousel-caption .btn {
margin-top: 10px;
}
.logo {
margin-left:-150px;
float:left;
}
Can someone please help me out with this ? : ) Thanks !
To get the forms side-by-side, we have to give them a 'float: left' CSS rule, like so:
.form-horizontal{
float: left;
}
Anyway, here's a JSFiddle with the new CSS: http://jsfiddle.net/4WwLX/1/