I am working with this snippet: http://bootsnipp.com/snippets/featured/modal-login-with-jquery-effects
Using bootstrap 3.3.6
Two questions:
Why is there a white background behind my modal? Or how should I debug this?
Why is my modal only centering within that white background? I need it to center in the middle of the screen.
My css:
/* #####################################################################
#
# Project : Modal Login with jQuery Effects
# Author : Rodrigo Amarante (rodrigockamarante)
# Version : 1.0
# Created : 07/28/2015
# Last Change : 08/02/2015
#
##################################################################### */
/*#import url(http://fonts.googleapis.com/css?family=Roboto);
* {
font-family: 'Roboto', sans-serif;
}*/
#login-modal .modal-dialog {
width: 350px;
position: relative;
top: 50%;
left: 50%;
margin-top: -25px;
margin-left: 0px;
padding: 20px;
}
#login-modal input[type=text], input[type=password] {
margin-top: 10px;
}
#div-login-msg,
#div-lost-msg,
#div-register-msg {
border: 1px solid #dadfe1;
height: 30px;
line-height: 28px;
transition: all ease-in-out 500ms;
}
#div-login-msg.success,
#div-lost-msg.success,
#div-register-msg.success {
border: 1px solid #68c3a3;
background-color: #c8f7c5;
}
#div-login-msg.error,
#div-lost-msg.error,
#div-register-msg.error {
border: 1px solid #eb575b;
background-color: #ffcad1;
}
#icon-login-msg,
#icon-lost-msg,
#icon-register-msg {
width: 30px;
float: left;
line-height: 28px;
text-align: center;
background-color: #dadfe1;
margin-right: 5px;
transition: all ease-in-out 500ms;
}
#icon-login-msg.success,
#icon-lost-msg.success,
#icon-register-msg.success {
background-color: #68c3a3 !important;
}
#icon-login-msg.error,
#icon-lost-msg.error,
#icon-register-msg.error {
background-color: #eb575b !important;
}
#img_logo {
max-height: 100px;
max-width: 100px;
}
/* #########################################
# override the bootstrap configs #
######################################### */
.modal-backdrop.in {
filter: alpha(opacity=50);
opacity: .8;
}
.modal-content {
background-color: #ececec;
border: 1px solid #bdc3c7;
border-radius: 0px;
outline: 0;
margin: 15% auto;
position: relative;
}
.modal-header {
min-height: 16.43px;
padding: 15px 15px 15px 15px;
border-bottom: 0px;
}
.modal-body {
position: relative;
padding: 5px 15px 5px 15px;
}
.modal-footer {
padding: 15px 15px 15px 15px;
text-align: left;
border-top: 0px;
}
.checkbox {
margin-bottom: 0px;
}
.btn {
border-radius: 0px;
}
.btn:focus,
.btn:active:focus,
.btn.active:focus,
.btn.focus,
.btn:active.focus,
.btn.active.focus {
outline: none;
}
.btn-lg, .btn-group-lg>.btn {
border-radius: 0px;
}
.btn-link {
padding: 5px 10px 0px 0px;
color: #95a5a6;
}
.btn-link:hover, .btn-link:focus {
color: #2c3e50;
text-decoration: none;
}
.glyphicon {
top: 0px;
}
.form-control {
border-radius: 0px;
}
My html:
!-- BEGIN # MODAL LOGIN -->
<div class="modal fade" id="login-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header" align="center">
<img class="img-circle" id="img_logo" src="images/hhb.png">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
</div>
<!-- Begin # DIV Form -->
<div id="div-forms">
<!-- Begin # Login Form -->
<form id="login-form">
<div class="modal-body">
<div id="div-login-msg">
<div id="icon-login-msg" class="glyphicon glyphicon-chevron-right"></div>
<span id="text-login-msg">Type in User Name and Password</span>
</div>
<input id="login_username" class="form-control" type="text" placeholder="Username (type ERROR for error effect)" required>
<input id="login_password" class="form-control" type="password" placeholder="Password" required>
<div class="checkbox">
<label>
<input type="checkbox"> Remember me
</label>
</div>
</div>
<div class="modal-footer">
<div>
<button type="submit" class="btn btn-primary btn-lg btn-block">Login</button>
</div>
<div>
<button id="login_lost_btn" type="button" class="btn btn-link">Lost Password?</button>
<button id="login_register_btn" type="button" class="btn btn-link">Register</button>
</div>
</div>
</form>
<!-- End # Login Form -->
Solved this. Here is what I did for any one just starting:
You can use the developer tools to identify where there might be a conflict in your code.
For me I was referencing two conflicting versions of bootstrap.
Related
Whenever i change the background color of a button in CSS, it becomes unclickable. Same happens if i remove button border in css
HTML
<div class="row">
<button onclick="click('7')" class="btn">7</button>
<button onclick="click('8')" class="btn">8</button>
<button onclick="click('9')" class="btn">9</button>
<button onclick="click('/')" class="btn">/</button>
</div>
CSS
.btn{
width: 60px;
height: 60px;
margin-left: 30px;
margin-top: 25px;
background: beige;
}
Certainly in Google Chrome using click as the function name was causing an issue - changing that to clicker, for instance, seems to alleviate that issue and it works as expected.
function clicker(val) {
document.getElementById("screen").value += val
}
.btn {
width: 60px;
height: 60px;
margin-left: 30px;
margin-top: 25px;
background: beige;
cursor:pointer;
}
.btn:hover{
background:rgba(0,100,0,0.25)
}
#screen{
width:25rem;
height:2rem;
border:2px solid black;
margin:2rem 0;
background: beige;
}
<div class="row">
<button onclick="clicker('7')" class="btn">7</button>
<button onclick="clicker('8')" class="btn">8</button>
<button onclick="clicker('9')" class="btn">9</button>
<button onclick="clicker('/')" class="btn">/</button>
</div>
<input type='text' id='screen' />
An alternative using a delegated event listener
document.querySelector('.row').addEventListener('click',e=>{
document.querySelector('#screen').value+=e.target.textContent
})
.btn {
width: 60px;
height: 60px;
margin-left: 30px;
margin-top: 25px;
background: beige;
cursor: pointer;
}
.btn:hover {
background: rgba(0, 100, 0, 0.25)
}
#screen {
width: 25rem;
height: 2rem;
border: 2px solid black;
margin: 2rem 0;
background: beige;
}
<div class="row">
<button class="btn">7</button>
<button class="btn">8</button>
<button class="btn">9</button>
<button class="btn">/</button>
</div>
<input type='text' id='screen' />
try background-color
and it is still clickable, I think you are missing the :hover s
.btn{
width: 60px;
height: 60px;
margin-left: 30px;
margin-top: 25px;
background-color: beige;
}
.btn:hover {
background-color:gray;
}
<div class="row">
<button onclick="click('7')" class="btn">7</button>
<button onclick="click('8')" class="btn">8</button>
<button onclick="click('9')" class="btn">9</button>
<button onclick="click('/')" class="btn">/</button>
</div>
I have created a basic form, where the user has to input various contact details. My Send button however, does not work. Im trying to use HTML and CSS only for this form, but I'm not opposed to using JS if that's what is needed for this to be functional.
I have looked up various ways for a solution, but most things involve using php, which is not something I am able to use for this. As stated before, I'm really just trying to stick with HTML.
My button does have type="submit" and href="myemail#email.com" (I have my actual email in there). However, my button does not click, or at least it does not give the appearance of clicking nor does it send anything to my email. I also thought it was just a web browser issue, but I have tried both chrome and safari and no luck.
<section class="modal-section">
<button class="modal-button" id="open">Click Me</button>
<div class="modal-container" id="modal_container">
<div class="modal">
<div class="form-container" id="form-container">
<h1 class="form-header">Connect With Me.</h1>
<p>I would love to respond to your queries and help you succeed. Feel free to contact me!</p>
<div class="contact-box">
<div class="contact-left">
<h3 class="form-header3">Send your request</h3>
<form>
<div class="input-row">
<div class="input-group">
<label>Name</label>
<input type="text" placeholder="Your Name" required>
</div>
<div class="input-group">
<label>Phone</label>
<input type="text" placeholder="(888) 888-8888">
</div>
</div>
<div class="input-row">
<div class="input-group">
<label>Email</label>
<input type="email" placeholder="YourEmail#Email.com" required>
</div>
<div class="input-group">
<label>Subject</label>
<input type="text" placeholder="You're Hired!" required>
</div>
</div>
<label>Message</label>
<textarea rows="5" placeholder="You are so cool, please make my website cool too!" required></textarea>
<button class="form-button" type="submit" value="Send" href="mailto:johnsonisaiah13#yahoo.com">SEND</button>
</form>
</div>
<div class="contact-right">
<h3 class="form-header3">Reach Me</h3>
<table>
<tr>
<td>Email</td>
<td>Johnsonisaiah13#yahoo.com</td>
</tr>
<tr>
<td>Location</td>
<td>Fort Stockton, TX</td>
</tr>
</table>
</div>
</div>
</div>
<button class="modal-button" id="close">Close Me</button>
</div>
</div>
</section>
/* //////////////////////////////////////////////////////////////
//////////////// MODAL SECTION ///////////////////////
////////////////////////////////////////////////////////////// */
.modal-section {
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
margin: 0;
}
.modal-container {
background-color: rgba(0, 0, 0, 0.3);
display: flex;
align-items: center;
justify-content: center;
position: fixed;
top: 0;
left: 0;
height: 100vh;
width: 200vh; /* make 100 for smaller screen */
opacity: 0;
pointer-events: none;
}
.modal-button {
/* background-color: #39FF14;
color: #1F2022;
border-radius: 5px;
padding: 10px 25px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
font-size: 14px; */
background-color: white;
padding: 10px 18px;
font-weight: bold;
color: #1F2022;
display: inline-block;
margin: 30px 0;
border-radius: 5px;
}
.modal-button:hover {
background-color: #39FF14;
}
.modal {
background-color: white;
padding: 30px 50px;
border-radius: 5px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
width: 1000px;
max-width: 100%;
text-align: center;
}
.modal-header {
margin: 0;
}
.modal-text {
font-size: 14px;
opacity: 0.7;
}
.modal-container.show {
opacity: 1;
pointer-events: auto;
}
/* <!-- /////////////////////////////////////////////////////////////
///////////////////// CONTACT ME / HIRE ME /////////////////////////
///////////////////////////////////////////////////////////// --> */
.form-container {
width: 80%;
margin: 50px auto;
}
.contact-box {
background: white;
display: flex;
}
.contact-left {
flex-basis: 60%;
padding: 40px 60px;
}
.contact-right {
flex-basis: 40%;
padding: 40px;
background: #39FF14;
}
.form-header {
margin-bottom: 10px;
color: white;
}
.form-container p {
margin-bottom: 40px;
color: white;
}
.input-row {
display: flex;
justify-content: space-between;
margin-bottom: 20px;
}
.input-row .input-group {
flex-basis: 45%;
}
input {
width: 100%;
border: none;
border-bottom: 1px solid #39FF14;
outline: none;
padding-bottom: 5px;
}
textarea {
width: 100%;
border: 1px solid #39FF14;
outline: none;
padding: 10px;
box-sizing: border-box;
}
label {
margin-bottom: 6px;
display: block;
color: black;
}
.form-button {
background-color: #39FF14;
width: 100px;
border: none;
outline: none;
color: black;
height: 35px;
border-radius: 30px;
margin-top: 20px;
box-shadow: 0px 5px 15px 0px rgba(0, 14.5, 38.9, 48.6);
pointer-events: auto;
}
.form-header3 {
/* color: orange; */
font-weight: 600;
margin-bottom: 30px;
}
tr td:first-child {
padding-right: 20px;
}
tr td {
padding-top: 20px;
}
You can try refering to this old question some time ago. Not sure if it still works, but hope it helps.
html button to send email
I have this code:
.link {
cursor: pointer;
}
.dropdown-content {
margin-top: 10px;
margin-left: -10px;
position: absolute;
min-width: 100px;
min-height: 50px;
color: #5A3895;
float: left;
display: none;
background-color: #FDEBCF;
border: 3px solid #999999;
}
.inside-dropdown-content {
margin-top: 10px;
margin-left: -10px;
position: absolute;
min-width: 100px;
min-height: 50px;
color: #5A3895;
float: left;
display: none;
background-color: #FDEBCF;
border: 3px solid #999999;
}
.dropdown-button:hover>.dropdown-content {
display: block;
background-color: #FDEBCF;
}
.dropdown-button:hover {
background-color: #FDEBCF;
}
.inside-dropdown-button:hover>.inside-dropdown-content {
display: block;
background-color: #FDEBCF;
}
.inside-dropdown-button:hover {
background-color: #FDEBCF;
}
.name-label p {
font-size: 30px;
margin: auto;
text-align: center;
}
.name-label {
float: left;
padding-left: 10px;
}
.header {
border: 1.5px solid #999999;
background-color: #FDEBCF;
font-size: 20px;
font-family: Arial;
overflow: hidden;
}
button:not(.impressum-link):not(.inside-dropdown-button) {
font-size: 20px;
min-width: 100px;
min-height: 50px;
color: #5A3895;
float: left;
background-color: #FDEBCF;
border-style: solid;
border-color: #999999;
border-width: 1px 3px 1px 3px;
}
.impressum-link {
font-size: 20px;
min-width: 100px;
min-height: 50px;
color: #5A3895;
float: right;
background-color: #FDEBCF;
border-style: solid;
border-color: #999999;
border-width: 1px 3px 1px 3px;
}
<div class="header">
<div class="dropdown">
<button type="button" class="link">
<span>Home</span>
</button>
</div>
<div class="dropdown">
<button type="button" class="dropdown-button">
<span>Publications</span>
<div class="dropdown-content">
<button type="button" class="inside-dropdown-button">
<span>Recent Publications</span>
<div class="inside-dropdown-content">
<p>year</p>
A link to whatever
</div>
</button>Other Publications</div>
</button>
</div>
<div class="name-label">
<p>Website</p>
</div>
<button type="button" class="link impressum-link">
<span>Impressum</span>
</button>
</div>
I put in everything as I don't know what causes the problem.
I want to have the inside-dropdown-button inside of dropdown-content, but the browser (tested on Firefox and Chrome) seems to change
<div class="dropdown">
<button type="button" class="dropdown-button">
<span>Publications</span>
<div class="dropdown-content">
<button type="button" class="inside-dropdown-button">
<span>Recent Publications</span>
<div class="inside-dropdown-content">
<p>year</p>
A link to whatever
</div>
</button>Other Publications</div></button>
</div>
to:
<div class="dropdown">
<button type="button" class="dropdown-button">
<span>Publications</span>
<div class="dropdown-content">
</div></button><button type="button" class="inside-dropdown-button">
<span>Recent Publications</span>
<div class="inside-dropdown-content">
<p>year</p>
A link to whatever
</div>
</button>Other Publications</div>
Notice the extra </div></button> before <button type="button" in the 5th line. This extra </div> causes there to be to many </div>'s, messing up the header class, and putting impressum-link outside of the header. Why is this and how do I get around it?
If I change it in the Browser, it works, but when I copy the code out of the browser to the script and remove the extra tags, it puts them in again.
A button cannot contain another button so the browser assumes you have made an error and closes it for you.
Also note that button elements cannot contain links (and vice versa).
Permitted content
Phrasing content but there must be no Interactive content
I am trying to position the search bar on a background image. I am also trying to position a button at the bottom and center of the image. Following that, I will have containers.
What I am trying to achieve.
But what I am stuck and confused with positioning. The glyphicon is not working as well?
My Code
<style>
.card {
border: 0px solid;
}
.drop-shadow {
-webkit-box-shadow: 0 0 2px 2px rgba(0, 0, 0, .5);
box-shadow: 0 0 10px 1px rgb(211, 211, 211, 0.8);
border-radius: 0px;
}
.container-fluid {
width: auto
}
.container-fluid.drop-shadow {
margin-top: 2%;
margin-left: 5%;
margin-right: 5%
}
.img-fluid {
height: 200px;
}
#child {
width: 100%;
height: 20px;
margin: auto;
text-align: center;
bottom: 0px;
position: absolute;
}
.btn-checkin {
display: inline-block;
text-align: center;
white-space: nowrap;
color: #fff;
border-color: #EC008c;
text-transform: uppercase;
background-color: #EC008c;
font-family: 'Open Sans', 'Helvetica Neue', Arial, sans-serif;
padding: 0.375rem .75rem;
font-size: 13px;
border-radius: .25rem;
}
</style>
</head>
<body id="page-top">
<div class="card">
<img class="img-fluid" src="img/1847p.png" alt="Card image cap">
<div class="col-md-5">
<div class="form-group">
<div class="icon-addon addon-lg">
<input type="text" placeholder="Search Class" class="form-control" style="height:30px;position:absolute" id="email">
<label for="email" class="glyphicon glyphicon-search" rel="tooltip" title="email"></label>
</div>
</div>
</div>
<div id="child">
<button class="btn-checkin">Check in</button>
<div class="container-fluid drop-shadow">
<div class="row">
frsjafksdalkdfsa
</div>
fsdfdasasd
</div>
</div>
</div>
Problems to target :
Get the search bar on the background pic
Set the background pic always on top of the screen with full width but with certain height. I currently hard coded the height to 200px. Is there a way that it can be responsive?
I am also stuck with the glyphycon issue, why is it not displayed?
How do I position the button at the bottom of the image and in the
center?
Use margin-top with negative value to make the form goes on the image.
Glyphicons look to be working great simply here.
* {
box-sizing: border-box;
}
img {
width: 100%;
}
div#form-box {
margin-top: -95px;
text-align: center;
}
div#input-group {
width: 80%;
margin: 0 auto 20px;
position: relative;
background-color: #fff;
border: none;
border-radius: 5px;
}
input#email, label[for="email"] {
display:inline-block;
vertical-align: middle;
}
input#email {
width: calc(100% - 40px);
padding: 10px;
border: none;
}
label[for="email"] {
width: 40px;
line-height: 40px;
}
button#btn-checkin {
display: inline-block;
padding: 6px 10px;
border: none;
border-radius: 5px;
background-color: #EC008c;
color: #fff;
text-align: center;
text-transform: uppercase;
}
<head>
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css" />
</head>
<img src="http://wonderfulengineering.com/wp-content/uploads/2016/01/Desktop-Wallpaper-4.jpg" />
<div id="form-box">
<form>
<div id="input-group">
<label for="email" class="glyphicon glyphicon-search"></label><!--
--><input type="text" placeholder="Search Class" id="email">
</div>
<br/>
<button id="btn-checkin">Check-in</button>
</form>
</div>
<br/>
<br/>
<br/>
.card{
border:0px solid;
position:relative;
height:200px;
background:url('https://preview.ibb.co/fex0wK/1847p.png') no-repeat top center;
background-size:cover;
}
.card img {
width:100%;
}
.search-box {
position : absolute;
display:inline-block;
bottom:-30px;
left:0;
right:0;
padding:15px;
text-align:center;
}
.drop-shadow {
-webkit-box-shadow: 0 0 2px 2px rgba(0, 0, 0, .5);
box-shadow: 0 0 10px 1px rgb(211, 211, 211, 0.8);
border-radius:0px;
}
.container-fluid{
width:auto
}
.container-fluid.drop-shadow {
margin-top:2%;
margin-left:5%;
margin-right:5%
}
.img-fluid {
height: 200px;
}
#child{
width:100%;
height: 20px;
margin: auto;
text-align: center;
margin-top: 40px;
}
.form-group {
width:100%;
margin-bottom:10px;
}
.btn-checkin{
display: inline-block;
text-align: center;
white-space: nowrap;
color: #fff;
border-color: #EC008c;
text-transform: uppercase;
background-color: #EC008c;
font-family:'Open Sans','Helvetica Neue',Arial,sans-serif;
padding: 0.375rem .75rem;
font-size: 13px;
border-radius: .25rem;
}
.icon-addon {
position:relative;
}
.icon-addon label {
position: absolute;
left: 2px;
top: 2px;
padding: 8px;
font-size: 20px;
}
.icon-addon input {
height:40px;
padding-left:35px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<body id="page-top">
<div class="card" >
<!-- <img class="img-fluid" src="img/1847p.png" alt="Card image cap"> -->
<div class="search-box">
<div class="form-group">
<div class="icon-addon addon-lg">
<input type="text" placeholder="Search Class" class="form-control" id="email">
<label for="email" class="glyphicon glyphicon-search" rel="tooltip" title="email"></label>
</div>
</div>
<button class="btn-checkin">Check in</button>
</div>
</div>
<div id="child">
<div class="container-fluid drop-shadow">
<div class="row">
frsjafksdalkdfsa
</div>
fsdfdasasd
</div>
</div>
Try this code...If you need any help, let me know.
Ok so you want to position the search bar inside a image.
Make a div with the image as background
background: image_source;
background-size: contain;
position: relative; //must to write
width: 100%;
height: 100px; //as much as you want
Then the css for search bar
position: absolute;
then use top, left,etc to position the search bar
I have section that has few elements inside. They are all on the same line/row. I used div elements combined with CSS to put all elements next to each other. I'm not sure if this is the best practice to layout the elements and I'm open to suggestions. My problem is message box that is triggered if user didn't meet search criteria. Field box is set to display:none. After user clicks on the Search if message shows up everything shifts to the left. I'm wondering if message can expand to the right side of the screen instead of pushing elements to the left? Also I'm wondering how that would affect smaller screen and what would be the best option in that case?
$('#searchBtn').on('click',searchFun);
function searchFun(){
var menuVal = $.trim($('#menu').val()),
searchFldVal = $.trim($('#searchFld').val());
if(!searchFldVal){
$('#searchMsg').addClass("error").show().text('This field is required.').delay(4000).fadeOut('slow').queue(function(){
$(this).removeClass("error").dequeue();
});
}else if(searchFldVal.length < 3){
$('#searchMsg').addClass("error").show().text('You must enter at least 3 characters to search on.').delay(4000).fadeOut('slow').queue(function(){
$(this).removeClass("error").dequeue();
});
}else{
console.log('Search record.');
}
}
section.mainBox{
width: 100%;
padding-top: 0;
background-color: white;
border: 2px solid #000099;
}
div#Container {
padding-top: 8px;
padding-bottom: 8px;
text-align: center;
background-color: #B0C4DE;
border-bottom: 2px solid #000099;
}
div.nextTo {
display: inline-block;
margin-left: 5px;
}
span.msgMainBox {
display:none;
margin: 2px 5px;
padding:2px 25px 2px 35px;
}
span.error {
border: 1px solid;
margin: 5px;
padding:5px 10px 5px 40px;
background-repeat: no-repeat;
background-position: 10px center;
border-radius: 3px;
display: block;
}
span.error {
color: #D8000C;
background-color: #FFBABA;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<section class="mainBox">
<div id="Container">
<div class="nextTo">
<select name="menu" id="menu">
<option value="1">Name</option>
<option value="2">DOB</option>
<option value="3">City</option>
</select>
</div>
<div class="nextTo">
<input type="text" name="searchFld" id="searchFld" size="24" maxlength="24" value="" title="Maximum size of the field is 24 characters." placeholder="Example: Marco Polo" />
</div>
<div class="nextTo">
<input type="button" name="searchBtn" id="searchBtn" value="Search"/>
</div>
<div class="nextTo">
<input type="button" name="lockBtn" id="lockBtn" value="Unlock" style="display:none" />
</div>
<div class="nextTo">
<span id="searchMsg" class="msgMainBox"></span>
</div>
</div>
</section>
You can make the element absolute position to avoid having the push effect. And for small screen it will go to the bottom:
$('#searchBtn').on('click', searchFun);
function searchFun() {
var menuVal = $.trim($('#menu').val()),
searchFldVal = $.trim($('#searchFld').val());
if (!searchFldVal) {
$('#searchMsg').addClass("error").show().text('This field is required.').delay(4000).fadeOut('slow').queue(function() {
$(this).removeClass("error").dequeue();
});
} else if (searchFldVal.length < 3) {
$('#searchMsg').addClass("error").show().text('You must enter at least 3 characters to search on.').delay(4000).fadeOut('slow').queue(function() {
$(this).removeClass("error").dequeue();
});
} else {
console.log('Search record.');
}
}
section.mainBox {
width: 100%;
padding-top: 0;
background-color: white;
border: 2px solid #000099;
}
div#Container {
padding-top: 8px;
padding-bottom: 8px;
text-align: center;
background-color: #B0C4DE;
border-bottom: 2px solid #000099;
}
div.nextTo {
display: inline-block;
margin-left: 5px;
}
div.nextTo:last-child {
position: absolute;
top: 6px;
}
span.msgMainBox {
display: none;
margin: 2px 5px;
padding: 2px 25px 2px 35px;
}
span.error {
border: 1px solid;
margin: 5px;
padding: 5px 10px 5px 40px;
background-repeat: no-repeat;
background-position: 10px center;
border-radius: 3px;
display: block;
}
span.error {
color: #D8000C;
background-color: #FFBABA;
}
#media all and (max-width:800px) {
div.nextTo:last-child {
position: static;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<section class="mainBox">
<div id="Container">
<div class="nextTo">
<select name="menu" id="menu">
<option value="1">Name</option>
<option value="2">DOB</option>
<option value="3">City</option>
</select>
</div>
<div class="nextTo">
<input type="text" name="searchFld" id="searchFld" size="24" maxlength="24" value="" title="Maximum size of the field is 24 characters." placeholder="Example: Marco Polo">
</div>
<div class="nextTo">
<input type="button" name="searchBtn" id="searchBtn" value="Search">
</div>
<div class="nextTo">
<input type="button" name="lockBtn" id="lockBtn" value="Unlock" style="display:none">
</div>
<div class="nextTo">
<span id="searchMsg" class="msgMainBox"></span>
</div>
</div>
</section>
You can do it with the positioning, some modifications to margins and padding and #media queries which, when screen width gets too narrow, display the error message below and horizontally centered:
$('#searchBtn').on('click',searchFun);
function searchFun(){
var menuVal = $.trim($('#menu').val()),
searchFldVal = $.trim($('#searchFld').val());
if(!searchFldVal){
$('#searchMsg').addClass("error").show().text('This field is required.').delay(4000).fadeOut('slow').queue(function(){
$(this).removeClass("error").dequeue();
});
}else if(searchFldVal.length < 3){
$('#searchMsg').addClass("error").show().text('You must enter at least 3 characters to search on.').delay(4000).fadeOut('slow').queue(function(){
$(this).removeClass("error").dequeue();
});
}else{
console.log('Search record.');
}
}
section.mainBox{
width: 100%;
padding-top: 0;
background-color: white;
border: 2px solid #000099;
}
div#Container {
position: relative; /* added */
padding-top: 8px;
padding-bottom: 8px;
text-align: center;
background-color: #B0C4DE;
border-bottom: 2px solid #000099;
}
div.nextTo {
display: inline-block;
margin-left: 5px;
}
span.msgMainBox {
display: none;
margin: 2px 5px;
padding: 2px 25px 2px 35px;
}
span.error {
border: 1px solid;
/* added */
position: absolute;
top: 50%;
right: 0;
transform: translateY(-50%); /* vertically centered */
margin: 0 5px; /* modified */
padding: 0 5px; /* modified */
/***/
background-repeat: no-repeat;
background-position: 10px center;
border-radius: 3px;
display: block;
}
span.error {
color: #D8000C;
background-color: #FFBABA;
}
/* added */
#media screen and (max-width: 630px) { /* adjust to your needs */
span.error {
top: calc(100% + 5px); /* + 5px "margin-top" */
left: 50%;
transform: translateX(-50%); /* horizontally centered */
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<section class="mainBox">
<div id="Container">
<div class="nextTo">
<select name="menu" id="menu">
<option value="1">Name</option>
<option value="2">DOB</option>
<option value="3">City</option>
</select>
</div>
<div class="nextTo">
<input type="text" name="searchFld" id="searchFld" size="24" maxlength="24" value="" title="Maximum size of the field is 24 characters." placeholder="Example: Marco Polo" />
</div>
<div class="nextTo">
<input type="button" name="searchBtn" id="searchBtn" value="Search"/>
</div>
<div class="nextTo">
<input type="button" name="lockBtn" id="lockBtn" value="Unlock" style="display:none" />
</div>
<div class="nextTo">
<span id="searchMsg" class="msgMainBox"></span>
</div>
</div>
</section>