Why are only certain divs overlapping each other? - css

I'm having an issue where only certain divisions are overlapping each other vertically. My second gray "pageBreak" is mounting atop my "subHeader" regardless of padding fixes and trying to staying on top of clearing floats.
I've tried overflow, clearfix, old-school "clear: both;", and I'm still having the same problem. (I assume it's a float-related issue.) I even tried (as you can see in the code) using relative and absolute positioning to get my second "pageBreak" below my "subHeader" as it should be but no positioning value even moves the second "pageBreak." I also have my other divs below these referenced sneaking up to the top of my "subHeader." I rather not use these fixes as I want the CSS to be as dynamic as possible for obvious reasons.
I feel like the code is pretty neat but I'm obviously missing something fairly obvious. Any help would be greatly appreciated!
I've included the HTML and CSS of the page for your review.
HTML:
<div class="container">
<div class="header">
<div style="float:left">
<img src="images/Logo.gif" alt="Company Logo" width="345px" height="117px">
</div>
<div style="float: right;">
<h2>Company slogan.™</h2>
</div>
<div style="clear: both;"></div>
</div>
<div class="pageBreak">
</div>
<div class="subHeader">
<div style="float: left; width: 400px; text-align: left;">
</div>
<div class="form" style="float: right; width: 300px;">
<form id='login' action='login.php' method='post' accept-charset='UTF-8'>
<input type='hidden' name='submitted' id='submitted' value='1'/>
<div>
<label style="float: left;" for='username' >School Email</label>
<input style="float: right;" type='text' name='username' id='username' maxlength="50" /></br></br>
</div>
<div style="clear: both;">
<div>
<label style="float: left;" for='password' >Password</label>
<input style="float: right;" type='password' name='password' id='password' maxlength="50" />
</div>
<div style="clear: both;"></div>
<p style="font-size: 70%; text-align: right; line-height: 8px;">Forgot your password?</p>
<p style="font-size: 70%; text-align: right; line-height: 8px;">Want to register?</p>
<div>
<input type='submit' name='Submit' value='Log In' style="float: right;"/>
</div>
</form>
</div>
<div style="clear: both;"></div>
</div>
<div class="pageBreak" style="top: 400px;">
</div>
CSS:
.container {
width: 1000px;
margin-left: auto;
margin-right: auto;
border-radius: 15px;
background-color: white;
box-shadow: 10px 10px 40px #888;
}
.pageBreak {
margin-left: auto;
margin-right: auto;
width: 900px;
border-top: rgb(238,238,238) 3px solid;
}
.header {
padding-top: 30px;
padding-bottom: 30px;
padding-left: 50px;
padding-right: 50px;
}
.subHeader {
padding-top: 30px;
padding-bottom: 30px;
padding-left: 50px;
padding-right: 50px;
}

Don't know if this will solve the issue however it is too large for a comment...
Your HTML is malformed, you are missing a few closing tags. This could be a copy error for the last tag, however the first looks to be genuine.
See code below (I have commented where the corrections are needed):
<div class="container">
<div class="header">
<div style="float:left">
<img src="images/Logo.gif" alt="Company Logo" width="345px" height="117px">
</div>
<div style="float: right;">
<h2>Company slogan.™</h2>
</div>
<div style="clear: both;">
</div>
</div>
<div class="pageBreak">
</div>
<div class="subHeader">
<div style="float: left; width: 400px; text-align: left;">
</div>
<div class="form" style="float: right; width: 300px;">
<form id='login' action='login.php' method='post' accept-charset='UTF-8'>
<input type='hidden' name='submitted' id='submitted' value='1'/>
<div>
<label style="float: left;" for='username'>School Email</label>
<input style="float: right;" type='text' name='username' id='username' maxlength="50"/></br></br>
</div>
<div style="clear: both;">
<div>
<label style="float: left;" for='password'>Password</label>
<input style="float: right;" type='password' name='password' id='password' maxlength="50"/>
</div>
<div style="clear: both;">
</div>
<p style="font-size: 70%; text-align: right; line-height: 8px;">
Forgot your password?
</p>
<p style="font-size: 70%; text-align: right; line-height: 8px;">
Want to register?
</p>
<div>
<input type='submit' name='Submit' value='Log In' style="float: right;"/>
</div>
</div> <!-- HERE -->
</form>
</div>
<div style="clear: both;">
</div>
</div>
<div class="pageBreak" style="top: 400px;">
</div>
</div> <!-- HERE -->

You have line-height: 8px in your code. increase the line-height of the paragraphs and decrease your divisions widths and omit some float properties.
see jsfiddle

Below markup will solve issues in you layout.
<!-- CONTAINER -->
<div class="container">
<!-- HEADER -->
<div class="header">
<div style="float:left"><img src="images/Logo.gif" alt="Company Logo" width="345px" height="117px"></div>
<div style="float: right;"><h2>Company slogan.™</h2></div>
<div style="clear: both;"> </div>
</div>
<!-- / HEADER -->
<!-- 1ST PAGE BREAK -->
<div class="pageBreak"> </div>
<!-- / 1ST PAGE BREAK -->
<!-- SUBHEADER -->
<div class="subHeader">
<div class="form" style="float: right; width: 300px;">
<!-- FORM -->
<form id='login' action='login.php' method='post' accept-charset='UTF-8'>
<input type='hidden' name='submitted' id='submitted' value='1'/>
<div>
<label style="float: left;" for='username' >School Email</label>
<input style="float: right;" type='text' name='username' id='username' maxlength="50" /></br></br>
</div>
<div style="clear: both;"> </div>
<div>
<label style="float: left;" for='password' >Password</label>
<input style="float: right;" type='password' name='password' id='password' maxlength="50" />
</div>
<div style="clear: both;"> </div>
<p style="font-size: 70%; text-align: right; line-height: 8px;">Forgot your password?</p>
<p style="font-size: 70%; text-align: right; line-height: 8px;">Want to register?</p>
<div><input type='submit' name='Submit' value='Log In' style="float: right;"/></div>
</form>
<!-- /FORM -->
</div>
<div style="clear: both;"> </div>
</div>
<!-- / SUBHEADER -->
<!-- 2ND PAGE BREAK -->
<div class="pageBreak"> </div>
<!-- / 2ND PAGE BREAK -->
</div>
<!-- / CONTAINER -->

Related

Z-index not working on div on fixed position header

I have a page using a masterpage in asp.net 4.0. My masterpage has header which has a search box. Header has css position fixed and have z-index 10.
I am trying to create a search instruction which will open when user types anything. my instruction box do not show as floatig over header instead it opens inside header and expands it. Here are my css and html
header {
width:100%;
display:inline-block;
background-color:#ef4023;
position:fixed;
z-index:10;
}
header #Guide {
width: 100%;
z-index: 5;
margin-right: -1px;
position:relative;
background: #eee;
border: 1px solid #ccc;
}
<header>
<div class="col-lg-4 col-md-4 col-sm-2 col-xs-4">
<div class="logo">
<img src="images/logo.png" alt="logo" class="img-responsive" />
</div>
</div>
<div class="col-lg-8 col-md-8 col-sm-10 col-xs-8">
<div class="col-md-6">
<!--SearchBarStart-->
<div ng-controller="MyCtrl">
<form>
<h3>Search Here </h3>
<input type="text" class="form-control" id="SearchKeyword" ng-model="searchText" required="required" />
<div class="list-group" id="Guide" ng-show="showLinks">
<a class="list-group-item" href="" ng-click="SearchType(0,true,'KeyWord', 1)">
<div class="input-group">
<span class="fa fa-suitcase"></span><span style="padding-left: 20px">instruction goes here</span>
</div>
</a>
</div>
</form>
</div>
</div>
</div>
</header>
You have to use position: fixed also on the instruction box, with according position settings. (relative will put it into the document flow, thereby taking up space, and absolute won't work since you don't have a relative parent for it.)
header {
width: 100%;
display: inline-block;
background-color: #ef4023;
position: fixed;
z-index: 10;
}
header #Guide {
width: 100%;
z-index: 15;
margin-right: -1px;
position: fixed;
top: 110px;
left: 0px;
background: #eee;
border: 1px solid #ccc;
}
<header>
<div class="col-lg-4 col-md-4 col-sm-2 col-xs-4">
<div class="logo">
<img src="images/logo.png" alt="logo" class="img-responsive" />
</div>
</div>
<div class="col-lg-8 col-md-8 col-sm-10 col-xs-8">
<div class="col-md-6">
<!--SearchBarStart-->
<div ng-controller="MyCtrl">
<form>
<h3>Search Here </h3>
<input type="text" class="form-control" id="SearchKeyword" ng-model="searchText" required="required" />
<div class="list-group" id="Guide" ng-show="showLinks">
<a class="list-group-item" href="" ng-click="SearchType(0,true,'KeyWord', 1)">
<div class="input-group">
<span class="fa fa-suitcase"></span><span style="padding-left: 20px">instruction goes here</span>
</div>
</a>
</div>
</form>
</div>
</div>
</div>
</header>`

div will not scroll under another div

I have a need to get the TextBoxesGroup scrolling under the image on the top if the visitors scroll up or under the Add to basket in the footer if the visitors scroll down.
My footer add-to-wrap is pretty much fixed but the problem is that the div will not scroll undless it goes well under the footer and then when I scroll the add-to-wrap div also scrolls.
What am I doing wrong?
<style>
.wrong_email{
display:none;
color:red;
}
.add-to-wrap {
width: 100%;
display: block;
position: fixed;
bottom: 0;
margin: 0 auto;
text-align: center;
background-color: rgba(0,0,0,0.6);
padding: 10px 0 10px 0;
z-index: 3;
}
</style>
<div class="container">
<div class="row">
<div class="col-md-4" style="padding-left:0px; padding-right:0px;">
<img src="/brand/nvite.png" class="img-responsive"/>
</div>
<div>
<form method="POST" id="login_form">
<div id='TextBoxesGroup' class="textboxes-area">
<div id="TextBoxDiv1">
<input type='text' id='textbox1' name='textbox_1' class="form-control" placeholder="Enter email address here"/>
</div>
<div class="wrong_email" id="err_1">Wrong email address</div>
<div class="divider"><img src="/mobileimages/brand_takeovers/divider_invite.png" class="img-responsive"/></div>
<div id="TextBoxDiv2">
<input type='text' id='textbox2' name='textbox_2' class="form-control" placeholder="Enter email address here"/>
</div>
<div class="wrong_email" id="err_2">Wrong email address</div>
<div class="divider"><img src="/mobileimages/brand_takeovers/divider_invite.png" class="img-responsive"/></div>
<div id="TextBoxDiv3">
<input type='text' id='textbox3' name='textbox_3' class="form-control" placeholder="Enter email address here"/>
</div>
<div class="wrong_email" id="err_3" >Wrong email address</div>
</div>
<span id='addButton' class="send-invite-more-boxes "/><img src="invitemore.png" class="img-responsive"/></span>
</div>
</div>
</div> <!-- /container -->
<div class="add-to-wrap">
<button type="submit" class="send-invite-button">Add To Basket</button>
</div>
</form>

How to avoid overlapping when window is resized

I have 3 divs in total. One is a container for the other left and right divs. There will be so many containers. Everything is okay now, but when the window is resized the CSS should avoid overlapping the divs. Instead, it should wrap to the next line. Please provide me your suggestion. Below is my code.
Css Code
.divmain
{
width: 100%;
padding: 15px;
height: auto;
}
.divmain .divleft
{
float: left;
width: 16%;
}
.divmain .divright
{
float: left;
width: 84%;
}
View Code
<div style="width: 100%;">
<div class="divmain">
<div class="divleft">
<label class="label">Date</label>
</div>
<div class="divright">
<input type="text"/>
</div>
</div>
<div class="divmain">
<div class="divleft">
<label class="label">Status</label><span class="mand">*</span>
</div>
<div class="divright">
<label class="label">Pending</label>
</div>
</div>
<div class="divmain">
<div class="divleft">
<label class="label">Reference No</label>
</div>
<div class="divright">
<input type="text"/>
</div>
</div>
</div>
Demo

Arranging Div's with Headers

I a trying to stack 3 div's side by side. Here's a sample div
<!-- This is first div -->
<div id="divone" style="text-align: center;">
<span style="font-size: 11pt;"><strong>Some Message Here</strong></span>
<div style="text-align: center;">
<form action="https://www.somesomesomesome.com" method="post">
</form>
</div>
</div>
<!-- Similarly I need two more divs to be aligned sidebyside with div one -->
How can I do it using inline CSS? The width of each div can be 200px with no limit on height.
OUTPUT Required
-------------------- -------------------- --------------------
DIV ONE DIV TWO DIV THREE
-------------------- -------------------- --------------------
FORM ELEMENT FORM ELEMENT FORM ELEMENT
-------------------- -------------------- --------------------
Just because you can't change the stylesheet, doesn't mean you have to use ugly inline styles.
Add this to your <head>:
<style>
.three-columns{
width: 100%; /* or any width you like */
}
.three-columns .column{
float: left;
width: 33%; /* or less if you're using margins, padding, borders, etc */
}
</style>
Then in the page,
<div class="three-columns">
<div class="column"></div>
<div class="column"></div>
<div class="column"></div>
</div>
You can do all your additional css inside a style tag in the head. (Technically, I think you can use it outside the header, but try not to)
Try this:
<ul style="list-style: none;">
<li>
<div id="divone" style="">
<span style="font-size: 11pt;"><strong>Some Message Here</strong></span>
<div style="text-align: center;">
<form action="https://www.somesomesomesome.com" method="post">
</form>
</div>
</div>
</li>
<li>
<div id="divtwo" style="">
<span style="font-size: 11pt;"><strong>Some Message Here</strong></span>
<div style="text-align: center;">
<form action="https://www.somesomesomesome.com" method="post">
</form>
</div>
</div>
</li>
<li>
<div id="divthree" style="t">
<span style="font-size: 11pt;"><strong>Some Message Here</strong></span>
<div style="text-align: center;">
<form action="https://www.somesomesomesome.com" method="post">
</form>
</div>
</div>
</li>
Demo here:
http://jsfiddle.net/7MZqN/
Set display: inline-block; to have the divs side-by-side, as follows:
<div id="divone" style="text-align: center; display: inline-block; width: 200px;">
<span style="font-size: 11pt;"><strong>Some Message Here</strong></span>
<div style="text-align: center;">
<form action="https://www.somesomesomesome.com" method="post">
</form>
</div>
</div>
<div id="divtwo" style="text-align: center; display: inline-block; width: 200px;">
<span style="font-size: 11pt;"><strong>Some Message Here</strong></span>
<div style="text-align: center;">
<form action="https://www.somesomesomesome.com" method="post">
</form>
</div>
</div>
<div id="divthree" style="text-align: center; display: inline-block; width: 200px;">
<span style="font-size: 11pt;"><strong>Some Message Here</strong></span>
<div style="text-align: center;">
<form action="https://www.somesomesomesome.com" method="post">
</form>
</div>
</div>
<div id="divone" style="text-align: center; width:33.33333%; float:left;">
<span style="font-size: 11pt;"><strong>Some Message Here</strong></span></div>
<div style="text-align: center;">
<form action="https://www.somesomesomesome.com" method="post">
</form>
</div>
<div id="divtwo" style="text-align: center; width:33.33333%; float:left;">
<span style="font-size: 11pt;"><strong>Some Message Here</strong></span></div>
<div style="text-align: center;">
<form action="https://www.somesomesomesome.com" method="post">
</form>
</div>
<div id="divthree" style="text-align: center; width:33.33333%; float:left;">
<span style="font-size: 11pt;"><strong>Some Message Here</strong></span></div>
<div style="text-align: center;">
<form action="https://www.somesomesomesome.com" method="post">
</form>
</div>
<div style="clear:both;"></div><!-- this is a clearfix div -->
DEMO: http://jsfiddle.net/EnkP5/
UPDATE: i just saw where you wanted the width to be 200px; Change the width from 33.33333% to 200px;
Make sure that the div that all three of these other divs sit in, are more than 600px wide.
​

Boxes and Labels Not Aligned CSS

Based on this answer StackOverflow #Nikita Rybak I have created a set of labels and textboxes following his solution which shows to be working on JSFiddle.
I have copied this and added a few more categories to my ASP project but when loaded into chrome the boxes and text are all out of align.
This is my html file
<div id="User">
<div>
<div class="left">
<asp:Label ID="lbl_UserName" runat="server" Text="User Name"></asp:Label>
</div>
<div class="right">
<asp:TextBox ID="txtbx_UserName" runat="server"></asp:TextBox>
<br />
</div>
</div>
<div>
<div class="left">
<asp:Label ID="lbl_FirstName" runat="server" Text="First Name"></asp:Label>
</div>
<div class="right">
<asp:TextBox ID="txtbx_FirstName" runat="server"></asp:TextBox>
</div>
</div>
<div>
<div class="left">
<asp:Label ID="lbl_Password" runat="server" Text="Password"></asp:Label>
</div>
<div class="right">
<asp:TextBox ID="txtbx_Password" runat="server"></asp:TextBox>
</div>
</div>
<div>
<div class="left">
<asp:Label ID="lbl_ConfPassword" runat="server" Text="Confirm Password"></asp:Label>
</div>
<div class="right">
<asp:TextBox ID="txtbx_ConfPassword" runat="server"></asp:TextBox>
</div>
</div>
</div>
and my CSS file
#Content
{
position: relative;
float:none;
border: 1px solid #000000;
float: left;
padding: 80px 40px 60px 40px;
text-align:center;
background-color: #F8F8F8;
left: 0px; right: 0px;
text-align: center;
}
#User .left {
width: 30%;
float: left;
text-align: right;}
#User .right {
width: 65%;
margin-left: 10px;
float:left;}
Is there a reason why mine does not work?
It should work okay, though you have a few too many divs in there unnecessarily, and you also have a line break that may be screwing things up. Check out this fiddle
HTML
<div id="User">
<div class="left">
<label>User name</label>
</div>
<div class="right">
<input type="text" />
</div>
<div class="left">
<label>First name</label>
</div>
<div class="right">
<input type="text" />
</div>
<div class="left">
<label>Password</label>
</div>
<div class="right">
<input type="text" />
</div>
<div class="left">
<label>Confirm password</label>
</div>
<div class="right">
<input type="text" />
</div>
</div>​​​​​​​​​​​​
CSS
#User .left {
width: 30%;
float: left;
text-align: right;}
#User .right {
width: 65%;
margin-left: 10px;
float:left;}​
Also, you have a #Content element defined in your CSS nut it is not in the HTML, so that could be causing the problem.
EDIT
The only other thing I can think of is that the label control wraps the text in a - maybe try a literal control? The fiddle works fine, so it must be something with webforms controls.
Float sHould be used very carefully. Instead yo can use position attribute to position your div's accordingly.

Resources