How would I make this div responsive - html

first off i'd like to say that I am god awful at designing and using CSS, so I was wondering if I could get some help with making my div responsive. It is currently sitting at the middle of the screen which is working, however, it gets all squished in (width wise and height wise) when used on different screens. The text does also not change. Even when used on a 1080p monitor, it has scroll bars on, so i'm really stuck on how to style it. I have pasted the HTML and CSS below.
<div id="mainForm">
<form id="userForm" method="post">
<p id="userP">Username: <br>
<input id="Username" type="text" name="Username" placeholder="Username" onfocus="this.placeholder='';" onblur="this.placeholder='Username';">
<p id="passP">Password: <br>
<input id="Password" type="password" name="Password" placeholder="Password" onfocus="this.placeholder='';" onblur="this.placeholder='Password';">
<p id="emailP">Email: <br>
<input id="Email" type="text" name="Email" placeholder="Email Address" onfocus="this.placeholder='';" onblur="this.placeholder='Email Address';">
<p id="authP">Auth Code: <br>
<input id="auth2" type="text" name="Auth" placeholder="Auth Code" onfocus="this.placeholder='';" onblur="this.placeholder='Auth Code';"><br>
<input type="submit" id="submit" name="submit" value="Login"/>
<h4>Don't have an account? <a href="register.php" >Register!</a></h4>
</form>
</div>
CSS for the main DIV:
#mainForm{
width: 20vw;
height: 40vh;
background-color: white;
margin:auto;
font-family: Montserrat;
text-align: center;
align-items: center;
margin-top: 2%;
position: absolute;
overflow: auto;
margin: auto;
position: absolute;
top: 0; left: 0; bottom: 0; right: 0;
}
CSS for form elements:
#Username, #Password, #Email, #Auth, #auth2 {
border: none; border-bottom: 2px solid;
padding: 0.5%;
margin-left: 1%;
width:40%;
transition: width 1s;
-webkit-transition: width 0.8s;
text-align: center;
font-size: 16px;
}
#Username:focus, #Password:focus, #Email:focus, #auth2:focus {
width: 60%;
}
#userP, #passP, #emailP, #authP{
font-size: 20px;
}
#userP{
margin-top:15%;
}
Thanks.

first of all set the meta viewport tag in your head of HTML
<meta name="viewport" content="width=device-width, initial-scale=1">
second of all use bootstrap framework which is totally responsive, then wrap your div in columns
<div class="container">
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<!-- your form goes here -->
</div>
</div>
</div>
inside <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12"> you can add more classes and alter their CSS property like max-width, min-width, margin-top etc.

You might want to just stick to using pixels instead of vw and vh with such a small window to work with. I would suggest a height and width of 300px (I checked and it looks alright concerning the content.)
As #Friday Ameh pointed out, usually you would want to work with media-queries, but in this case the size of the width isn't going to leave the screen because the smallest screensize (mobile) is usually around 350px anyway.
You might want to use a media-query for larger screens so it doesn't stay as small as 300px, but that's up to you and dependent on your design.
Can I help you any further?

you need to add height in pixel
#mainForm {
width: 320px;
height: 340px;
background-color: white;
font-family: Montserrat;
text-align: center;
align-items: center;
overflow: hidden;
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
margin: auto;
}
#Username, #Password, #Email, #Auth, #auth2 {
border: none; border-bottom: 2px solid;
padding: 0.5%;
margin-left: 1%;
width:40%;
transition: width 1s;
-webkit-transition: width 0.8s;
text-align: center;
font-size: 16px;
}
#Username:focus, #Password:focus, #Email:focus, #auth2:focus {
width: 60%;
}
#userP, #passP, #emailP, #authP{
font-size: 20px;
}
#userP{
margin-top:15%;
}
<div id="mainForm">
<form id="userForm" method="post">
<p id="userP">Username: <br>
<input id="Username" type="text" name="Username" placeholder="Username" onfocus="this.placeholder='';" onblur="this.placeholder='Username';">
<p id="passP">Password: <br>
<input id="Password" type="password" name="Password" placeholder="Password" onfocus="this.placeholder='';" onblur="this.placeholder='Password';">
<p id="emailP">Email: <br>
<input id="Email" type="text" name="Email" placeholder="Email Address" onfocus="this.placeholder='';" onblur="this.placeholder='Email Address';">
<p id="authP">Auth Code: <br>
<input id="auth2" type="text" name="Auth" placeholder="Auth Code" onfocus="this.placeholder='';" onblur="this.placeholder='Auth Code';"><br>
<input type="submit" id="submit" name="submit" value="Login"/>
<h4>Don't have an account? <a href="register.php" >Register!</a></h4>
</form>
</div>

Related

My Contact field does not do anything when I change the top field

.contact-form {
width: 85%;
max-width: 600px;
background: #f1f1f1;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
padding: 30px 40px;
box-sizing: border-box;
border-radius: 8px;
text-align: center;
box-shadow: 0 0 20px #000000b3;
font-family: "Work Sans", sans-serif;
}
/* This is the css */
<body>
<div class="contact-form">
<h1>Contact Us</h1>
<div class="txtb">
<label>Full Name :</label>
<input type="text" name="" value="" placeholder="Enter Your Name">
</div>
<div class="txtb">
<label>Email :</label>
<input type="email" name="" value="" placeholder="Enter Your Email">
</div>
<div class="txtb">
<label>Phone Number :</label>
<input type="text" name="" value="" placeholder="Enter Your Phone Number">
</div>
<a class="btn">Send</a>
</div>
</body>
My Problem is that even though i have the top: 50%, it does not center vertically
but the left: 50% makes it centered horizontally so I am confused as to why the top isn't working.
Thanks for helping out!
I have tried the code and it is aligned in center from left and top both.
I have a suggestion for you that next time you code try using vw instead of %, it will help you to make your webpage/website more responsive.

Div class min-width still resizing

Good day, so i have a login function encased in a div tag. I would just like to freeze the div if i resize. I tried adding min-width and display: inline-block but its still resizing. Any help would be appreciated. Also, using a pixel value still wont work.
the screenshot shows that min-width:300% !important; did not work.
I also placed my code in JS Fiddle: https://jsfiddle.net/wvhgsek9/
HTML:
<form class="reg_log_box login_box form-group">
<br>
<div class="row">
<div class="col-md-12">
<p>EMAIL</p>
<input type="text" placeholder="EMAIL" autocomplete="off" name="email"
value="<?php
if(isset($_POST["email"])) {
echo($_POST["email"]);
} ?>">
</div>
<div class="col-md-12">
<p>PASSWORD</p>
<input type="text" placeholder="PASSWORD" autocomplete="off" name="password">
</div>
</div>
<input type="submit" id="login" name="login" value="LOGIN" class="reg_signup">
<p class="center_font">NO ACCOUNT YET? REGISTER HERE</p>
<br>
</form>
CSS:
.login_box {
min-width: 30% !important;
display: inline-block
}
.reg_log_box {
width: 50%;
padding: 10px 70px 10px;
background: #fff;
opacity: 0.9;
border-radius: 30px;
margin: 0 auto;
}
Using
.login_box {
min-width: 30% !important;
display: inline-block
}
Is not going to work because that will mean to resize the box always to 30% of what ever the browser window's width is.
Instead, supply a pixel based value e.g.
.login_box {
min-width: 300px;
}
Edit:
To fully stop resizing completely then change your width to a pixel based value.
.reg_log_box {
width: 500px;
padding: 10px 70px 10px;
background: #fff;
opacity: 0.9;
border-radius: 30px;
margin: 0 auto;
}
You can then remove .login_box css all together...
try resize: block;
block
The element displays a mechanism for allowing the user to resize it in the block direction (either horizontally or vertically, depending on the writing-mode and direction value).
https://developer.mozilla.org/en-US/docs/Web/CSS/resize

How make textboox and button left margin always same by resizing the screen

how make textbook and button left margin always same by resizing the screen?
this is my css code:
.forgot-password-textbox {
font-size: #textbox-font-size;
border-radius: #textbox-border-radius;
border: #border-lines solid #Black;
padding: #padding-40 / 4;
width: #forgot-password-textbox-width;
box-shadow: 0 1px #Grey;
margin-bottom: #forgot-password-textbox-margin-bottom;
position:relative;
}
.forgot-password-button {
margin-left: #forgot-password-textbox-button-margin-left;
margin-top: auto;
width: 40%;
height: 45px;
position:relative;
}
and this is my html:
<div>
<div>Email Address</div>
<div><input type="email" name="email" placeholder="example#email.com" id="email" class="forgot-password-textbox"></div>
<div>
<label id="Message" class="forgot-password-error-message"></label>
</div>
<div>
<input type="button" value="Submit" id="btn-reset-password" onclick="resetPasswordHandler()" class="orange-button forgot-password-button">
</div>
</div>
I need Email and submit button left margin stay same with all page sizes.
This is how I see the page with regular screen:
and this is when screen get smaller:
You can do box-sizing: border-box; on the input field, and then have the submit button use margin-left: auto. So long as both are display: block;, it should work.
Here is the JSBin for proof of concept: http://jsbin.com/helosub/1/edit?css,output

CSS - the correct way to align an image alongside two divs

This must be really basic but it has been doing my head in.
Here is a basic image of what I am trying to achieve
I have a container div with a 100% width.
I have a piece of text which I put in a paragraph tag and below that some input fields and a button. All of this should centered.
I have an image which should be just to the right of both the text and the fields and is roughly the same height as both of these divs.
When the viewport resizes larger the image should stay anchored to the end of the text and input fields - around 20px away. If I float the container with a % width it will keep drifting further as the windowsize increases?
I have tried the following:
an outer div for a container and two inner divs, one floated left (containing the text and inputs), the other right (with the image)
an outer container with 3 separate divs inside, 1 for the text line which is 100% width, followed by another for the input fields width 70%, final div width 30% for the image.
a container with one div inside it. the text and the image inside the paragraph and manually positioning the image, followed by the input fields.
and many other similar variations and yet somehow I still can't get what I'm looking for.
What is the correct way to do this? It seems so simple yet continues to elude me after hours of fiddling.
Please keep in mind that this code will exist inside a responsive template and so I am not looking to work with fixed values or positioning. I will need to restyle the inputs to stack on top of each other with the image on the right once resized to a mobile breakpoint (but for now that is irrelevant I think).
Any help is much appreciated for this task that is making me feel increasingly stupid! I must be missing something fairly basic..
Here is a fiddle example that anyone can feel free to edit. Fiddle
.inner {
margin: 0 auto;
text-align:center;
padding-bottom: 10px;
}
.container {
width: 100%;
background-color:beige;
}
.myImage {
padding-top: 10px;
}
<div class="container">
<div class="inner">
<p class="textSignup">
Get the latest tips on an interesting subject and a FREE extract from our Guide
<img class="myImage" src="http://www.vapld.info/images/ys/books.png" width="100" height="65">
</p>
<input type="text" name="FNAME" placeholder="Your first name" id="firstName">
<input type="email" name="EMAIL" size="11" placeholder="Your email" required="">
<input type="submit" value="Download my free ebook">
</div>
</div>
What you could do :
Float your .myImage to the right
Add a clearfix to .inner
Demo
.inner {
margin: 0 auto;
text-align:center;
padding-bottom: 10px;
max-width: 560px;
}
.inner:before,.inner:after {
content: "";
display: table;
}
.inner:after {
clear: both;
}
.container {
width: 100%;
background-color:beige;
}
.textSignup {
padding-bottom : 15px;
}
.myImage {
padding-top: 10px;
float:right;
}
<div class="container">
<div class="inner">
<p class="textSignup">
Get the latest tips on an interesting subject and a FREE extract from our Guide
<img class="myImage" src="http://www.vapld.info/images/ys/books.png" width="100" height="65">
</p>
<input type="text" name="FNAME" placeholder="Your first name" id="firstName">
<input type="email" name="EMAIL" size="11" placeholder="Your email" required="">
<input type="submit" value="Download my free ebook">
</div>
</div>
(see also this Fiddle)
You can try something like this
HTML
.inner {
width: 50%;
margin: 0 auto;
text-align: center;
padding-bottom: 10px;
font-size: 0;
}
.container {
width: 100%;
background-color: beige;
}
.left {
display: inline-block;
width: 80%;
font-size: 16px;
}
.right {
display: inline-block;
width: 20%;
}
<div class="container">
<div class="inner">
<div class="left">
<p class="textSignup">
Get the latest tips on an interesting subject and a FREE extract from our Guide
</p>
<input type="text" name="FNAME" placeholder="Your first name" id="firstName">
<input type="email" name="EMAIL" size="11" placeholder="Your email" required="">
<input type="submit" value="Download my free ebook">
</div>
<div class="right">
<img class="myImage" src="http://www.vapld.info/images/ys/books.png" width="100" height="65">
</div>
</div>
</div>
https://jsfiddle.net/vytnLbdu/
I've got an output that looks a lot like your mockup.
We've simply moved your image into the second column of a 2-column container. The line between your text and input fields are done with a <br> tag.
<div class="container">
<div class="left">
<p class="textSignup">Get the latest tips on an interesting subject and a FREE extract from our Guide</p><br>
<input type="text" name="FNAME" placeholder="Your first name" id="firstName">
<input type="email" name="EMAIL" size="11" placeholder="Your email" required="">
<input type="submit" value="Download my free ebook">
</div>
<div class="right">
<img class="myImage" src="http://www.vapld.info/images/ys/books.png" width="100" height="65">
</div>
</div>
Css:
.left
{
float: left;
width: 60%;
margin: 0 auto;
text-align:center;
padding-bottom: 10px;
}
.right{
width:40%;
float:right;
}
.container
{
width: 100%;
background-color:beige;
}
.myImage
{
padding-top: 10px;
}
You could use inline-block with absolute positioning to achieve something similar to your design. A point to note, however, there is no 'right' way of doing things in web design - there are just some approaches that 'should be avoided if possible'.
.inner {
margin: 0 auto;
text-align: center;
padding-bottom: 20px;
padding-top: 20px;
position: relative;
display: inline-block;
}
.container {
width: 100%;
text-align: center;
background-color: beige;
}
.myImage {
padding-top: 10px;
}
.inner img {
position: absolute;
left: 100%;
top: 0;
}
<div class="container">
<div class="inner">
Get the latest tips on an interesting subject and a FREE extract from our Guide
<img class="myImage" src="http://www.vapld.info/images/ys/books.png" width="100" height="65">
<br>
<input type="text" name="FNAME" placeholder="Your first name" id="firstName">
<input type="email" name="EMAIL" size="11" placeholder="Your email" required="">
<input type="submit" value="Download my free ebook">
</div>
</div>

How to turn a DIV into a form element?

I'm new to world of forms! I had made divs and css for the exact layout I want for the forms. Is there anyway to maybe just turn that div tag into button or a text field while still using the same css rules so the layout doesn't change?
Here is some code and demo to just check what I have going on.
HTML
<div id="loginContainer">
<div id="loginForm">
<div id="login"></div>
<div id="loginUsername"></div>
<div id="loginPassword"></div>
<div id="loginSubmit"></div>
</div>
<div id="registerForm">
<div id="register"></div>
<div id="registerName"></div>
<div id="registerEmail"></div>
<div id="registerPassword"></div>
<div id="registerPasswordConfirm"></div>
<div id="registerSubmit"></div>
</div>
</div>
CSS
#loginContainer {
width: 50%;
height: 50%;
position: absolute;
left: 21.8%;
top: 40%;
z-index:-9999;
}
#loginForm {
width:47.5%;
height: 100%;
float:left;
top: 0%;
position:relative;
}
#login {
width: 100%;
height: 10%;
top: 0;
background-image:url(../_images/_login/login.png);
background-size: 100% 100%;
position: absolute;
border-bottom-left-radius: 5px;
border-bottom-right-radius: 5px;
}
#loginUsername {
width: 100%;
height: 10%;
top: 15%;
background-color: #383d3f;
position: absolute;
border-radius: 5px;
}
#loginPassword {
width: 100%;
height: 10%;
top:30%;
background-color:#383d3f;
position:absolute;
border-radius: 5px;
}
#loginSubmit {
width: 100%;
height: 10%;
top: 45%;
background-color:#76c2bb;
position:absolute;
border-radius: 5px;
}
#registerForm {
width:47.5%;
height: 100%;
float:right;
top: 0%;
position:relative;
}
#register {
width: 100%;
height: 10%;
top:0%;
background-image:url(../_images/_register/register.png);
background-size: 100% 100%;
position:absolute;
border-bottom-left-radius: 5px;
border-bottom-right-radius: 5px;
}
#registerName {
width: 100%;
height: 10%;
top:15%;
background-color:#383d3f;
position:absolute;
border-radius: 5px;
}
#registerEmail {
width: 100%;
height: 10%;
top: 30%;
background-color:#383d3f;
position:absolute;
border-radius: 5px;
}
#registerPassword {
width: 100%;
height: 10%;
top: 45%;
background-color:#383d3f;
position:absolute;
border-radius: 5px;
}
#registerPasswordConfirm {
width: 100%;
height: 10%;
top: 60%;
background-color:#383d3f;
position:absolute;
border-radius: 5px;
}
#registerSubmit {
width: 100%;
height: 10%;
top: 75%;
background-color:#76c2bb;
position:absolute;
border-radius: 5px;
}
CLICK FOR DEMO
Sure you can, just replace the right elements with input with proper markup, add an opening and closing form tag, remove the borders, and you're good to go:
<div id="loginContainer">
<div id="loginForm">
<div id="login"></div>
<form method="post" name="loginForm">
<input id="loginUsername" type="text" name="loginUsername" />
<input id="loginPassword" type="text" name="loginPassword" />
<input id="loginSubmit" type="submit" name="loginSubmit" value="" />
</form>
</div>
<div id="registerForm">
<div id="register"></div>
<form method="post" name="loginForm">
<input id="registerName" type="text" name="registerName" />
<input id="registerEmail" type="text" name="registerEmail" />
<input id="registerPassword" type="text" name="registerPassword" />
<input id="registerPasswordConfirm" type="text" name="registerPasswordConfirm" />
<input id="registerSubmit" type="submit" name="registerSubmit" value="" />
</form>
</div>
</div>
#loginContainer input {
border:0
}
Here is your updated demo: http://jsfiddle.net/7w1adgko/2/
EDIT: Note that you may want to fill out the value property of the submit buttons so that users will actually know it's the submit button.
<input id="loginSubmit" type="submit" name="loginSubmit" value="Login" />
or...
<input id="registerSubmit" type="submit" name="registerSubmit" value="Register" />
Also, in order users to know what field is what, you may want to use the placeholder property.
<input id="loginUsername" type="text" name="loginUsername" placeholder="Username" />
<input id="loginPassword" type="text" name="loginPassword" placeholder="Password" />
or...
<input id="registerName" type="text" name="registerName" placeholder="Name" />
<input id="registerEmail" type="text" name="registerEmail" placeholder="Email" />
<input id="registerPassword" type="text" name="registerPassword" placeholder="Password" />
<input id="registerPasswordConfirm" type="text" name="registerPasswordConfirm" placeholder="Confirm Password" />
And to make it prettier, you could add some colour and padding to the inputs.
#loginContainer input {
border:0;
padding: 0 10px;
color:white
}
Here is your most recent fiddle with these changes: http://jsfiddle.net/7w1adgko/3/
EDIT 2: To make all the boxes have the same width, you could specify the same box model for type="text" and type="submit" inputs (source: CSS: Submit button looks smaller than text input and textarea)
#loginContainer input {
border:0;
padding: 0 10px;
color:white;
box-sizing: border-box;
-moz-box-sizing: border-box;
}
Here is the updated fiddle: http://jsfiddle.net/7w1adgko/4/
It would be better to start from the proper functional markup and then consider styling. For the functionality of a form, you need elements like input to set up the controls, label to have labels (captions) associated with controls, and form to contain the entire form. (And you probably should not have two forms side by side, it can be confusing.)
However, if you have designed a layout in a “DIVistic” way and you wish to turn it to a functional form element with working controls, you need to take into account that form-related elements have default rendering that you may need to override. A form element has top and bottom margin by default, label elements are inline elements (display: inline) as opposite to div elements that are blocks (display: block), and input elements are inline blocks that have borders and padding.
On the other hand, most (if not all) of your div elements are just containers, instead of being direct counterparts to controls. For example, the element <div id="loginUsername"></div> really needs some content, such as
<div id="loginUsername"><label for="uname">User name:</label>
<input id="uname" name="uname" required size="8" maxlength="8"></div>
Assuming that the content fits inside the div element as formatted in your current design, no change in the layout styling is then needed. (However, from the jsfiddle, it seems that you intend to use form controls without any labels. This would be a major usability and accessibility problem, and fixing it probably requires a redesign of the layout.)