HTML CSS Header images not floating correctly - html

Afternoon all,
I'm trying to create a basic header
White space at top with an image that floats left and an image that floats right.
Then below this a grey background with some options and a button on left and some nav buttons on right.
The requirements are that the header will always be 100% width and that when you scroll down the page the header always stays at the top.
I have this working fine with my current HTML and CSS however when I reduce screen size e.g. snap right on my laptop 1368x768 resolution on laptop the image on the right floats below the buttons on the right hand side but inside the grey border?!
Left image size = 480x80
Right image size = 264x80
HTML
<div id="banner">
<img src="/images/img1.png" style="float:left"/>
<img src="/images/img2.png" style="float:right"/>
</div>
<div id="header">
<div id="header_left">
<form action= "<?php echo $_SERVER['PHP_SELF']; ?>" method ="POST">
<select name=dbselector>
<?php
echo '<option value="1"';
if ($_COOKIE[$cookie] == "x") {
echo ' selected="selected"';}
echo '>1</option>';
echo '<option value="2"';
if ($_COOKIE[$cookie] == "y")
{echo ' selected="selected"';}
echo '>2</option>';
?>
</select>
<input name="submit_button" type="submit" value="Submit"/>
</form>
</div>
<div id="header_right">
<?php date_default_timezone_set('Europe/London'); echo date('h:i:s');?>
<input type="button" value="Back" onclick="history.go(-1)">
<a href="www.google.co.uk" style="text-decoration: none">
<input type="button" value="Home">
</a>
<input type="button" value="Refresh" onClick="history.go(0)" >
<input type="button" value="Forward" onclick="history.go(1)">
</div>
</div>
CSS
#header
{
width: 100%;
position: fixed;
background:#58575b;
padding-top: 0px;
padding-bottom:0.5em;
margin: 0px
}
#banner
{
background:#fff;
width:100%;
height: 5em;
}
#header_left
{
float: left;
padding: 0em;
padding-left: 0.5em;
margin: 0em;
}
#header_right
{
float: right;
padding: 0em;
margin: 0em;
padding-right: 0.5em;
}
Any ideas why it is behaving like this?!
Thanks in advance

In a few comments of the starting post you say something about it not working properly in Internet explorer or Firefox.
It works in chrome right?
So it may be such a thing something isn't compatible with firefox or IE.
Not many use IE for the fact it is decommissioned by microsoft.
So, now let's focus just on Firefox and smaller screens as that also seems to be a issue.
Solution for small screens: Use viewports or media queries (either or should fix it)
<meta name="viewport" content="width=device-width, initial-scale=1">
For the issues with FireFox can you explain what it does? You just mention the issue for small screens exactly what it is doing but didn't explain the issues with Firefox (IE)
Thanks!

Solution was very basic...
The only thing different between the jsfiddle and my live code were the images.
I have checked the images and they have loads of whitespace in them hence why it moves down!
Took the images straight of our corporate site so I didn't even both to check for whitespace in the image itself.....
Argh!

Related

Float a form over an image and down to the right

Hello Stack Overflowians, I'm trying to float a form over a background image and I think I'm not doing it right. This is for our company gateway that I'm having to rebuild after many years in production. Below is what I have so far. The first image is my version of it. See how I got the background image to center? https://postimg.cc/nCmTfxVz Now that parts working good.
Next is the old site and the image is way to the left. https://postimg.cc/jn76T6b9
Not meaning to trick our clients, but they really like our old gateway right now, so I'm trying to style it as close as possible to the original one. As you can see, I've been successful in getting it close. (The rounded corners on the new input boxes are fine.) And the placement of the inputs are good with me too. It's just that, I don't believe I'm doing this right, as you can see in my HTML <div class="row" style="margin-top: -190px;"> that's what I'm having to do for now to push the whole form down.
I noticed here (How to place an Html form over an Image) about half-way down the page, #Scott added padding-top: 120px; to the form{} code. I tried adding his CSS but it pushed the form way down off the image.
Note: I still have to place a header up above with the "Registration" and "Forgot Password" links, but I'm not worried about that. I'll work that out myself. If you guys could just steer me in the right direction, or show me a better way to do this, I would be very appreciative. Thanks.
Oh, and here's what it looked like when I would go into responsive mode in Firefox like I was viewing it on a phone. https://postimg.cc/qtq30ccL So I added the media query stuff as you can see in the CSS. And now I have it looking like this. https://postimg.cc/m14q5G7D
Oh, and one more thing. Here's something else to keep in mind. Every now and then, we will be putting a message bar at the top of the page that says something like "Gateway will be down for maintenance over the weekend." or something similar. I will probably just put a Bootstrap banner up there since its so easy and quick to do. So it would be nice to just be able to float everything down while I do that. Just something extra to keep in mind. (-: So below is all of my code.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no" />
<title>Gateway Reboot v.3.0</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto+Condensed">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.1/dist/css/bootstrap.min.css" integrity="sha384-zCbKRCUGaJDkqS1kPbPd7TveP5iyJE0EjAuZQTgFLD2ylzuqKfdKlfG/eSrtxUkn" crossorigin="anonymous">
<!--link rel="stylesheet" href="Contact-Form-Clean.css"/-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<style>
body{
font-family: 'Roboto Condensed', Arial, sans-serif;
}
.coolbox { /* this is a hold-over from the old web application */
display: block;
font-family: 'Roboto Condensed', Arial, sans-serif;
font-size: 12px;/* was 12.87px */
line-height: 16px;
border: 2px #708090 solid;
height: 22px;
width: 155px;
padding-left: 6px;/* because Bootstrap was putting too much padding on the left */
}
label{
margin-bottom: 0;
}
form{
margin-left: 200px;
}
#media only screen and (min-width: 768px) {
form{
margin-left: 25%;
}
/*img {
opacity: 0.6;
}*/
}
#media only screen and (max-width: 600px) {
form{
margin-left: 25%;
margin-top: 15%;
}
img {
opacity: 0.1;
}
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-lg-12">
<img src="bigbackKey.png" class="img-fluid d-block mx-auto" alt="Sample Image" />
<!--section class="contact-clean"-->
<div class="row" style="margin-top: -190px;"><!--Just doing this for now to push the "form" row down. I know it's probably not the right way to do it.-->
<div class="col-md-6"></div>
<div class="col-md-6">
<form method="post">
<div class="form-group">
<label for="username">Username</label>
<input type="text" class="form-control coolbox" id="username" name="username" />
<!--/div-->
<!--By combining these 2 divs, it removed a big gap between the username box/label and password box/label.-->
<!--div class="form-group"-->
<label for="password">Password</label>
<input type="password" class="form-control coolbox" id="password" name="password" />
</div>
<div class="form-group"><button class="coolbox" type="submit">Login</button></div>
</form>
</div>
</div>
<!--/section-->
</div>
</div>
</div>
</body>
</html>

Making a Search bar Responsive

I am working on a new homepage at http://www.bkd.com/new-test-2.htm
We have a search bar that was previously built by a different developer who is no longer here.
I am trying to make the search bar further to the right of the screen but also still be responsive. I am not sure what I am doing wrong. I have tried a lot of different things and when I make the browser smaller it just jumps below the navigation. This is what I do not want to happen.
Here is the coding for the whole light grey bar:
<div class="clear"></div>
<div class="span-8">
<a class="left" style="padding: 0px 0px 0px 0px; margin-left: 80px;" href="/">
<img src="/images/common/header/logo.png" border="0"></a> </div>
<div style="margin-top:25px;" class="span-0 last">
<form action="/search/">
<input type="image" src="/images/common/search/search-icon-new.png" style="margin-left: 220px; float:left; outline:none" alt="Search">
<input type="text" name="zoom_query" value="Search" style=" background- image:url(/images/common/search/search-field-new.png); background-repeat: repeat-x; margin: 0; line-height:26px; height: 26px; width:200px; color:#666; background-color:#fff; border:none; outline:hidden; border-radius: 7px; float:right; padding: 0px 0px 0 10px; margin-left: 0px;" onFocus="this.value=this.value.replace(/^Search$/, '')">
</form>
</div>
Can anyone tell me what I am doing wrong or a better way to achieve what I am trying to do. Please let me know if I need to provide any more information.
Thank you in advance!
-Marcy-
The search bar is breaking down because the marker icon beside it has an unnecessary margin of 220px, giving the whole search div a width of 462px which causes it to break down on lower screen size.. change the following
<input type="image" src="/images/common/search/search-icon-new.png" style="margin-left: 220px; float:left; outline:none" alt="Search">
to
<input type="image" src="/images/common/search/search-icon-new.png" style=" float:left; outline:none" alt="Search">
to move the search bar to the right, apply float:right to the container div as follows:
<div style="margin-top:25px; float:right" class="span-0 last">
i suggest using external stylesheets instead of applying inline style, external stylesheets are likely to be cached, hence loading might become faster on consecutive visits. Also it makes your html more readable as well.

CSS cross browser issue with floated div

I've created a few pages in Firefox and everything was looking as it should. Made a quick flip to Chrome and Safari and noticed that my opt-in form in the header of this page is not displaying as it should. I would like for the entire opt-in div to be inside the header div. From what I can tell it is in the header div in Firefox, but pretty much every other browser shows it below the main navigation.
Here is the CSS for the header and the opt-in form that should be in it:
.header{height: 302px;min-width: 100%; background-color: #265f8b;
margin: 0 auto;}
.opt-in {height: 280px; width: 800px;background-color: #c7e877;float: right;
margin-right: 200px;margin-top: 10px;border:5px solid #8db530;
border-radius: 10px;position: relative;}
Here is the HTML:
<div class='header'>
<img style='border: 1px solid black;' src='images/main-logo.jpg'></img>
<div class='opt-in'>
<p>Enter your name and email below to get
<span style='font-weight: bolder;'>Free Instant Access</span> to the most comprehensive
guide available on how to ..</p>
<p><span style='font-weight: bolder;'>Over 10,000 people</span> have enjoyed my eBook and receive
a weekly newsletter with exclusive tips!</p>
<table>
<form method='post' action='opt-in-form.php'>
<tr><td><input type='text' name='name' value='Enter Name...' /></td></tr>
<tr><td><input type='text' name='email' value='Enter Your Email...' /></td></tr>
<input class='opt-in-button' type='image' src='images/opt-in-button.png' alt='Submit Form' />
</table>
</form>
<img class='book-cover' src="images/book-cover-new.png"></img>
</div>
</div>
You'll notice that I have included it in the header div and have a float right on it.
http://fairchildwebsolutions.com/packattack/index.php
The top left logo needs a float: left. that should solve the problem.
Float the logo img left.
float:left
Also specify a width for the img element too. width:auto will do also.

why is this css not working ? want to put to left

I am really stuck in this silly issue. i am spending 4 hours now only on this problem.
I have a page: http://bibago.de/test.html. If you resize the page to 320px width (iphone size), it should come to this state: http://imagebin.org/267953
but what not working is that input field is not in the middle in iphone size.
this is my css:
.newsletter{
width: 300px;
padding-top: 40px;
padding-bottom: 40px;
clear: both;
}
html
<div class="newsletter">
<p class="overinput">zu bibago auf dem laufenden bleiben</p>
<div class="input-group newsletter1">
<input type="text" class="form-control" id="email" placeholder="Hier Ihre E-Mail-Adresse eintragen..">
<span class="input-group-btn">
<button class="btn btn-default" style="background-color: #156ac6;color: #ffffff" type="button" onclick="senden()">Senden</button>
</span>
</div>
</div>
what is causing this? please help, i need to put that input field with its title in center as shown in image.
You have a relative margin (.newsletter {margin-left: 30%;} in the non-320px version) and an absolute negative margin (.newsletter1 {margin-left:-15px}).
30% of 300px is 96px, -15px results in a left margin of 81px for the input element, which is simply too much. (Also, relative and absolute values shouldn't be mixed, as those will most likely result in such behaviour).
If you want to center a fixed-width element, better use an automatically deduced margin:
.newsletter{
width: /* ... */
margin: auto;
}

IE8 displaying wrong piece of CSS sprite

There are a million issues with sprites and IE8 i've read about online, however, they all seem to deal with the issue of the sprites not showing up at all. Mine is showing up, its just showing the wrong piece of the sprite. It works fine in all other browsers.
Heres the CSS
div.searchForm input[type=text] {
border: 0;
padding: 0 10px;
margin: 0;
background: url(../img/sprite.png) 0 -125px no-repeat;
background-size: 115% 235px;
width: 600px;
height: 30px;
float: left;
font-size: 12px;
color: #fff;
-webkit-appearance: none;
-webkit-border-radius: 0;
}
and the html:
<section id="secondary6">
<h1 class="hidden">Search</h1>
<div class="clearfix">
<div class="grid_4">
<nav class="grid_2 secondary">
<h1 class="hidden">Search Secondary Navigation</h1>
</nav>
<div class="searchForm">
<input type="text" placeholder="search">
<input type="button">
<input type="submit" class="hidden" >
</div>
</div>
</div>
</section>
basically you click the search button, and it displays a search bar that should be hidden otherwise. Like I said it works in other browsers.
IE8 doesn't support background-size (see https://developer.mozilla.org/en-US/docs/Web/CSS/background-size#Browser_compatibility), so that's what you'll have to work around. Depending on your needs, you might try IE7.js (which works with other versions of IE) or a conditional comment to adjust the position of the image for IE8. Or, just make sure your raw image doesn't need to be re-sized.
What happens when You assign class or ID to particular text input field?
for example..
div.searchForm input.classInput {
/* css code here */
}
Also ...
..where is element form tag wrapper, form name, form action ?
The input fields should not reside in a document on a way You presented.. without form tag..
Which software actually generated this code for You?
Is it dreamweaver?
Basic and proper example of valid HTML input form ..
<form id="formID" name="formName" method="post" action="#">
<input type="text" name="textUno" value="" />
<input type="text" name="textDue" value="" />
<button type="submit" name="do_processing"> Go! </button>
</form>