Making my header & wrapper fluid/responsive with % doesnt seem to work - html

So i wanted to make my website fluid. So i started with my wrapper and header. The css:
#wrapper {
max-width:1600px;
width:100%;
margin:0 auto;
}
#header {
margin: 0 auto;
width: 100%;
height: 7.5%;
background-color: #0066FF;
display: table-cell;
vertical-align: middle;
}
The HTML:
<div id="wrapper">
<div id="header">
<div id="logo_wrapper">
<span class="logonaam1">O</span><span class="logonaam2">b</span><span class="logonaam1">l</span><span class="logonaam2">e</span><span class="logonaam1">c</span><span class="logonaam2">t</span><span class="logonaam1">a</span><span class="logonaam2">r</span><span class="logonaam1">e</span>
</div>
<form action="login.php" method="post">
<div id="aanmeldform_submit">
<input type="submit" name = "submit_login" value="Aanmelden" id="submit_knop" />
</div>
<div id="aanmeldform_wachtwoord">
<input type="password" name ="password" value="" id="aanmeld_knop" required placeholder="Voer je wachtwoord in" />
</div>
<div id="aanmeldform_email">
<input type="email" name="email" value="" id="aanmeld_knop" required placeholder="Voer je e-mail in" autofocus/>
</div>
</form>
</div>
The header should span the entire width of the screen, just like the wrapper. But for some reason, when i set the width of the header also to 100% the header only is like 1/3 of the screen. When i change the width of my header to around 1 - 10 % it DOES span the whole width for some reason. Anyone know what is causing this? Also included a fiddle for better understanding: http://jsfiddle.net/4J7JJ/
When you set the header in the fiddle to 1% you can see it does span the entire width for some reason..
Thanks in advance!

Try change display
#header {
margin: 0 auto;
width: 100%;
height: 7.5%;
background-color: #0066FF;
display: inline-table; /* that fix the problem */
vertical-align: middle;
}

Related

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 do I align my search-input and submit-button to the center of the page?

Sorry, I know this is super basic but I've been through my coding reference books all day and I think my mind's a little buggered. I need to get BOTH the input field AND the "submit" button in one line, in the center of the page, similar to Google.
.logo {
width: 50%;
display: block;
margin: auto;
}
.input-fields {
padding: 3%;
width: 40%;
display: block;
margin: auto;
font-size: 90%;
}
.submit {
padding: 3%;
width: 15%;
}
<header>
<img class="logo" src="OnSaleTodayMobile.png" alt="OnSaleToday.co.za">
</header>
<div class="form-wrapper">
<form class="center">
<input class="input-fields" name="search" type="text" placeholder="Search for anything...">
<input class="input-fields submit" name="find" type="submit" value="Find">
</form>
</div>
The problem I'm getting is that the button is stacking underneath the text-field. What am I missing out?
Well Google has it vertically and horizontally aligned so you should try something like this (simplified version):
* {margin: 0; padding: 0; box-sizing: border-box}
html, body {width: 100vw; height: 100vh}
body {
display: flex;
justify-content: center;
align-items: center;
}
.align-me {
display: flex;
flex-direction: column;
align-items: center;
}
.align-me > .form-wrapper > .center {
display: flex;
}
<div class="align-me">
<header>
<img class="logo" src="OnSaleTodayMobile.png" alt="OnSaleToday.co.za">
</header>
<div class="form-wrapper">
<form class="center">
<input class="input-fields" name="search" type="text" placeholder="...">
<input class="input-fields submit" name="find" type="submit" value="Search">
</form>
</div>
</div>
But their design is not responsive and this is.
What you are seeing is the default behaviour of display:block.
Using display:inline-block will make them block elements so you can add padding, etc, but make them inline so they will appear beside each other (assuming they fit, and other styles don't change the default behaviour).
Just change the display from block to inline-block in your CSS here:
.input-fields {
[...]
display:inline-block;
}
Working snippet:
.logo {width: 50%; display:block; margin:auto;}
.input-fields {
padding:3%;
width:40%;
display:inline-block; /* change this from block to inline-block */
vertical-align: middle; /* this will help with any vertical alignment issues */
margin:auto;
font-size:90%;
}
.submit {
padding:3%;
width:15%;
}
/* Add this this to center your inputs -
you included the "center" class in your HTML but not it in your CSS */
.center { text-align:center}
<header><img class="logo" src="OnSaleTodayMobile.png" alt="OnSaleToday.co.za"/></header>
<div class="form-wrapper">
<form class="center">
<input class="input-fields" name="search" type="text" placeholder="Search for anything..."/>
<input class="input-fields submit" name="find" type="submit" value="Find"/>
</form>
</div>
You are missing a
display: inline-block;
on the elements you want to display in line. You currently have 'display: block;' This will push elements on to there own line.
You may also want:
vertical-align: middle;
To make them vertically aligned relative to each other.
To make sure they both stay dead center in the page put them all in a container (or just use your existing form container) and style it like:
position: absolute;
top: 50%;
left: 0;
right: 0;
transform: translateY(-50%);
text-align: center;
This will ensure no matter what the screen size is the container is in the middle both vertically and horizontally.

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>

Aligning Web Forms

I have two forms that I want to align. I was able to figure out how to align the height, but I can't get the width to work the way I want.
In my situation, I want the left box to fill in the remaining space. Using 'auto' just fills in the space to fit the contents. So instead of an expanding form, there is a gap between the two forms.
The reason I require this is I also have PHP around this form. There is a flag that dictates whether or not the second form shows up. So if there is only one form, I want it to expand the entire space. If there is two forms, I want them to share the space.
The way I thought of doing this would be to set the right form to a specific width and have the left form mold to whether or not anything else exists. I just can't figure out how to get the left form to expand itself without specifying an exact width.
I've included the HTML and CSS below as well as a JSFiddle reference.
HTML
<div class="section">
<div class="container">
<form>
<fieldset class="left">
<legend>PC Management</legend>
<div>
<input type='submit' value='Backup' />
<input type='submit' value='Backup' />
<input type='submit' value='Backup' />
</div>
</fieldset>
</form>
<form>
<fieldset class="right">
<legend>PC Management</legend>
<div>
</div>
</fieldset>
</form>
</div>
</div>
CSS
.section {
margin: 0 auto;
text-align: center
}
.container {
height: 100px;
width: 500px;
}
.container form, .container fieldset, .container input {
height: 100%;
display: inline;
}
.left {
width: auto;
float: left;
}
.right {
width: 40%;
float: right;
}
display: flex will get you the dynamic resizing that you want without needing any JavaScript:
.section {
margin: 0 auto;
text-align: center
}
.container {
height: 100px;
width: 500px;
display: flex;
}
.container form {
flex: 1 1 auto;
}
.container form, .container fieldset, .container input {
height: 100%;
}
<div class="section">
<div class="container">
<form class="left">
<fieldset>
<legend>PC Management</legend>
<div>
<input type='submit' value='Backup' />
<input type='submit' value='Backup' />
<input type='submit' value='Backup' />
</div>
</fieldset>
</form>
<form class="right">
<fieldset>
<legend>PC Management</legend>
<div>
</div>
</fieldset>
</form>
</div>
</div>
http://jsfiddle.net/eeLfx9d6/1/

html footer problem

i'm new to html and im having some problems adding a footer. More specifically, when i add the footer, the 'form' gets pulled until it reaches the footer - like this http://tinypic.com/view.php?pic=jhbw5g&s=7 . How can i stop it from extending the body of the form?
html code
<body>
<div id="formWrapper">
</center>
<form method ="post" action="addMember.php">
<label for="name">Username:</label>
<input name="name"/>
<label for="password">Password:</label>
<input name="password"/>
<label for="email">Email:</label>
<input name="email"/>
<p>
<fieldset>
<input class="btn" name="submit" type="Submit" value="Register"/>
<input class="btn" name="reset" type="reset" value="Clear Form">
</fieldset>
</form>
<div class="push"></div></div>
<div class="footer">
<p>Copyright (c) 2008</p>
</div>
</body>
Stylesheet
#formWrapper{
width:400px;
border:solid 5px #F1F1F1;
margin-top:300;
margin-bottom:10;
margin-right: auto;
margin-left: auto;
background-color: #AFC8DE;
padding-top: 10px;
min-height: 100%;
height: auto !important;
height: 100%;
}
html, body { height: 100%; }
.push{ background-color: #903; margin: 50px; }
.footer { height: 4em; background-color: #103; }
More specifically min-height: 100%; makes it drag out but unsure how to fix it.
I don't know what exactly your needs are, but for one your footer div is within the form wrapper, so it will follow the height of whatever that wrapper is.
http://jsfiddle.net/7SgGT/
Here is something I quickly put together. This should get you started on what you're looking for I believe.
There are a few of problems in your HTML code as posted.
a "center" end-tag with no start
the second "input" tag is not closed
empty div.push tag?
the indents look off (maybe due to stackoverflow formatting?)
Please reexamine your HTML and edit the question with updated HTML if the problem does not resolve.
Try something like this..
<div id="container">
<div id="header"></div>
<div id="body"></div>
<div id="footer"></div>
</div>
and the CSS..
html, body {margin:0; padding:0; height:100%;}
#container {min-height:100%; position:relative;}
#body {padding:10px; padding-bottom:60px; /* Height of the footer */}
#footer {position:absolute; bottom:0; width:100%; height:60px; /* Height of the footer */;
}