I am trying to learn table-less design and having a difficult time with something that should be easy
I am trying to make a save or cancel button at the bottom right of the screen in the designer it looks good but in the browser (IE and Chrome) the buttons move into the the right part of the form
I have tried height auto and leaving it out all together. If I fix the height of the main div then it works, but I don't always know that height. Is there anyway to make the buttons "flow" at the bottom of the main div?
Thank You
The Code
<%# Page Title="" Language="C#" AutoEventWireup="true" MasterPageFile="~/Site.Master" CodeBehind="NewAccount.aspx.cs" Inherits="BudgetApplicationCSharp.NewAccount" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<style type="text/css" media="screen">
#container
{
width:500px;
margin: 5px;
}
#main
{
width:500px;
height:auto;
margin:1px;
}
#left
{
float:left;
width:50%;
padding-left:0px;
margin:0px;
}
#right
{
float:right;
width:50%
}
ol
{
list-style:none;
}
input[type=button]
{
float:right;
clear:right;
}
input[type=Text]
{
font:15px "MS Sans Serif";
}
label
{
font:15px "MS Sans Serif";
}
fieldset
{
padding:0px;
margin:0px;
border:0px none;
}
ol
{
padding:0px;
margin:0px;
border:0px none;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div id="container">
<div id="main">
<div id="left">
<fieldset>
<ol>
<li>
<label for="AccountName">
Account Name</label>
<input id="AccountName" runat="server" />
</li>
<li>
<label for="Description">
Description</label>
<input id="Description" runat="server" />
</li>
<li>
<label for="InstituteName">
Institute Name</label>
<input id="InstituteName" runat="server" />
</li>
<li>
<label for="AccountType">
Institute Name</label>
<select id="cboAccountType" runat="server">
</select>
</li>
</ol>
</fieldset>
</div>
<div id="right">
<fieldset>
<ol>
<li>
<label for="AccountNumber">
Account Number</label>
<input id="AccountNumber" runat="server" />
</li>
<li>
<label for="RoutingNumber">
Routing Number</label>
<input id="RoutingNumber" runat="server" />
</li>
</ol>
</fieldset>
</div>
</div>
<div id="buttons">
<input id="btnSave" type="button" value="Save" runat="server" />
<input id="btnCancel" type="button" value="Cancel" runat="server" />
</div>
</div>
</asp:Content>
Adding the style rule #buttons { clear: both; } should cause the button div to go below the floated divs.
this is a floating-problem. you need some kind of "clearfix". in your case i would add an overflow:hidden; to #main... this will create a new box model context, which will solve your issue. here you got a jsfiddle to demonstrate this behaviour (just remove the overflow:hidden there to see the difference) -> http://jsfiddle.net/3k3yd/
Add
overflow: auto
to the #main definition.
This solves what others have said without the need for additional markup (ie adding an empty div)
Here's a fiddle with the result.
Your experiencing an issue common across browsers that occurs when you float two divs within a container. The issue is that the container's height does not expand to the height of the floated divs within it. The fix to this issue is commonly referred to as the clearfix.
I have applied the clearfix to your markup in this example: http://jsfiddle.net/3D7hz/
It adds this styling to your stylesheet:
/* float clearing for IE6 */
* html .clearfix{
height: 1%;
overflow: visible;
}
/* float clearing for IE7 */
*+html .clearfix{
min-height: 1%;
}
/* float clearing for everyone else */
.clearfix:after{
clear: both;
content: ".";
display: block;
height: 0;
visibility: hidden;
font-size: 0;
}
And adds the clearfix class to your main element in the markup:
<div id="main" class="clearfix">
This link describes the clearfix problem in detail:
http://www.positioniseverything.net/easyclearing.html
Related
#header {
background: black;
color: white;
font-family: Arial;
height: 10%;
text-align: center;
}
#footer {
clear: left;
width: 100%;
height: 10%;
background: black;
color: white;
font-family: Arial;
text-align: center;
}
<html>
<head>
<title>This is a page used by admins to change the content.</title>
</head>
<link REL="STYLESHEET" TYPE="text/css" HREF="../includes/style.css">
<div id="header">
<h2> <strong> Admin page. </strong> </h2>
</div>
<body style="background-color:cyan;">
<div id="contentwrapper">
<div id="contentcolumn">
<div class="innertext">
<h3>
<p> Insert your credentials here: Note that if you log in, you will be redirected to the main page.</p>
</h3>
<form action="index.php" method="post" autocomplete="off">
<input type="text" name="username" placeholder="Username" />
<input type="password" name="password" placeholder="Password" />
<input type="submit" value="Submit" />
</form>
</div>
<?php if (isset($error)) { ?>
<strong> <small style="color:aa0000;">
<?php echo $error; ?>
</small></strong>
<?php } ?>
</div>
</div>
<br> <br> <br> <br>
<div id="footer">
Main Page
</div>
</body>
</hmtl>
I have a small site, and for some reason, this appears:
Page with issue. The issue is that a cyan line appears above the black header, when it shouldn't appear.
And the CSS code for the header, where the issue appears:
#header {
background: black;
color:white;
font-family:Arial;
height:10%;
text-align:center;
}
Now, what I've tried (all of these failed):
a) Change the header id on the first div to footer, which has this code:
#footer {
clear:left;
width:100%;
height:10%;
background:black;
color:white;
font-family:Arial;
text-align:center;
}
b) Change the code of header to be the same as footer.
The only thing that works, although I don't know why, is if I write something before the <h2> tag of the first div, like so:
<div id="header">
a<h2> <strong> Admin page. </strong> </h2>
</div>
Which results to this
I honestly don't know why the issue is present only here, because I have other sites where this issue isn't present. Could someone please explain?
Also, this HTML code is under some PHP code, which is essentially a login form.
The collapsing margin is cousing the problem. Remove top margin on h2 or add a padding or a boarder (1px) to a header element
The top and bottom margins of blocks are sometimes combined (collapsed) into a single margin whose size is the largest of the individual margins (or just one of them, if they are equal), a behavior known as margin collapsing.
If there is no border, padding, inline part, block formatting context created, or clearance to separate the margin-top of a block from the margin-top of one or more of its descendant blocks; or no border, padding, inline content, height, or min-height to separate the margin-bottom of a block from the margin-bottom of one or more of its descendant blocks, then those margins collapse. The collapsed margin ends up outside the parent.
More on mdn
Add This Line at the top of your CSS file:
* { box-sizing: border-box; margin: 0; padding: 0; }
Working Code:
* { box-sizing: border-box; margin: 0; padding: 0; }
#header {
background: black;
color:white;
font-family:Arial;
height:10%;
text-align:center;
}
#footer {
clear:left;
width:100%;
height:10%;
background:black;
color:white;
font-family:Arial;
text-align:center;
position: absolute;
bottom: 0;
left: 0;
}
<html>
<head>
<title>This is a page used by admins to change the content.</title>
<link REL="STYLESHEET" TYPE="text/css" HREF="../includes/style.css">
</head>
<body style="background-color:cyan;">
<div id="header">
<h2> <strong> Admin page. </strong> </h2>
</div>
<div id="contentwrapper">
<div id="contentcolumn">
<div class="innertext">
<h3>
Insert your credentials here: Note that if you log in, you will be redirected to the main page.
</h3>
<form action="index.php" method="post" autocomplete="off">
<input type="text" name="username" placeholder="Username" />
<input type="password" name="password" placeholder="Password" />
<input type="submit" value="Submit" />
</form>
</div>
<?php if (isset($error)) { ?>
<strong> <small style="color:aa0000;">
<?php echo $error; ?>
</small></strong>
<?php } ?>
</div>
</div>
<br> <br> <br> <br>
<div id="footer">
Main Page
</div>
</body>
</html>
And for god's Sake please learn some basics of HTML
I'm was just passing my time by working on random code of HTML and CSS where I have a div which has class .box and has an Image, Text and a Form in it with input boxes.
I found that when I provide text-align: center; to my parent, all elements comes in the center.
I can't understand what's happening here and why Image and Input boxes react text on text-align: center;
here is the codepen link to my code http://codepen.io/rhulkashyap/pen/MKvzzZ
#import url(https://fonts.googleapis.com/css?family=Roboto);
body{
margin:0;
font-family: 'Roboto', sans-serif;
}
.box{
width:500px;
border:1px solid #ccc;
margin:40px auto;
text-align:center;
padding:20px;
border-radius:5px;
}
<div class="box">
<img src="http://minions-2015.gloryone.pl/it/gfx/images/delivery/minion_1.png" alt="" width="200"/>
<h1>Hello Universe</h1>
<form>
<input type="text" placeholder="Username"/> <br />
<input type="text" placeholder="Password"/> <br />
<input type="submit" value="Login"/>
</form>
</div>
From the CSS specification:
This property describes how inline-level content of a block container is aligned. https://www.w3.org/TR/CSS2/text.html#alignment-prop
All inline and inline-block elements (input, img) are affected of text-align!
You can avoid this by using display:block; for the inner elements (like form, h1, div).
#import url(https://fonts.googleapis.com/css?family=Roboto);
body{
margin:0;
font-family: 'Roboto', sans-serif;
}
.box{
width:500px;
border:1px solid #ccc;
margin:40px auto;
text-align:center;
padding:20px;
border-radius:5px;
}
input {
display:block;
}
<div class="box">
<img src="http://minions-2015.gloryone.pl/it/gfx/images/delivery/minion_1.png" alt="" width="200"/>
<h1>Hello Universe</h1>
<form>
<input type="text" placeholder="Username"/>
<input type="text" placeholder="Password"/>
<input type="submit" value="Login"/>
</form>
</div>
A Test Case
div {
border:1px dashed #000;
text-align:center;
width:500px;
}
.block {
display:block;
}
.inline {
display:inline;
}
<div>
<input type="text" value="standard: inline-block">
<input type="text" class="block" value="with display:block">
<input type="text" class="inline" value="with display:inline">
</div>
When you pass text-align: center, it means that the data inside particular div will be placed center according to a rule. Data can be anything, it can be image, text or input box. Your elements are coming in center because all the inline elements are effected by "text-align: center". Please have a look on the following url https://www.w3.org/Style/Examples/007/center.en.html
<!DOCTYPE html>
<html>
<body>
<p>This is a paragraph. This text has no alignment specified.</p>
<div style="text-align:center;border:1px solid red">
This is some text in a div element!
</div>
<p>This is a paragraph. This text has no alignment specified.</p>
</body>
</html>
I'm trying to put 2 divs beneath each other like this:
div 1
div 2
This is how far i've gotten in the HTML-file:
<div width="100%" z-index:"1">
<div id="username-full">
<div id="username-form">
<input type="text" name="username" id="username-input" placeholder="Username" />
</div>
<div id="username-text">
<p>Username:</p>
</div>
</div>
</div>
<div width="100%" z-index:"1">
<div id="passwd-full">
<div id="passwd-form">
<input type="text" name="passwd" id="passwd-input" placeholder="passwd" />
</div>
<div id="passwd-text">
<p>Password:</p>
</div>
</div>
</div>
And this is my CSS-file:
#username-full{
text-align:right;
float:right;
clear:right;
}
#username-text{
float:right;
margin-right:5px;
}
#username-form{
float:right;
margin-top:13px;
}
#passwd-full{
text-align:right;
float:right;
}
#passwd-text{
float:right;
margin-right:5px;
}
#passwd-form{
float:right;
margin-top:13px;
}
Fiddle
As you see, i've tried using the z-index, i've tried to give the 2 divs a width of 100% and i tried using float. Also, I've tried using positioning, but that also didn't work. I'm out of guesses :(.
Greetings,
Luuk
Based on your code, try adding this line:
#passwd-full{
clear: both;
}
I'm guessing, but have a look at this:
#passwd-full {
...
clear: right;
}
Demo
If you want two divs 100% with each and one above the other, you should try:
<div id="One">My first content</div>
<div id="Two">My second content</div>
#One, #Two {width: 100%; clear: both;}
I'm trying to get 'ADD' and the search box to sit next to each other, side by side and align them right.
I've checked out other answers and I have implemented an inline-block solution, they sit side by side (but for some reason it's not working on the fiddle). How can I align the elements to the right of their parent?
<div class="span6">
<h2 class="pull-left">TITLE</h2>
</div>
<nav class="span6">
<form action="/gateway" method="get">
<input name="search" size="10" type="search" placeholder="Search" results=5>
</form>
<a class="btn" href="/add">ADD</a>
</nav>
Fiddle
JSFiddle does not use SCSS by default. Expand the Languages menu on the left and choose "SCSS" instead of "CSS". This should result in the elements aligning side-by-side.
To align the nav to the right, make both span6's 50% width and float/text-align the nav right.
.span6{
float: left;
width: 50%;
}
nav{
float: right;
text-align: right;
...
}
Fiddle
Erik Gillepsie is right. Here is your Fiddle in CSS structure and with the correct HTML input tag: http://jsfiddle.net/6MY8g/
<input name="search" size="10" type="search" placeholder="Search" results=5 />
Edit: to align right (only the second div), add a class "right" to your div and make it float right.
Try This : just replace your code with this
<div class="span6">
<h2 class="pull-left">ARTICLE MANAGER</h2>
</div>
<nav class="span6">
<form action="/gateway" method="get">
<input name="search" size="10" type="search" placeholder="Search" results=5>
<a class="btn" href="/add">ADD</a>
</form>
</nav>
So, if i'm understanding you correctly you want the title "Article Manager" and the search box and the ADD link to all be on the same line. AND, you want the "Article Manager" to be on the left, and the search and add group aligned to the right, correct?
Create a container for your row, and put everything in it, and give it 100% width so it spans the entire width of the page. Then float the title to the left, and float the search box group to the right. Done and done.
<div class="header-container">
<div class="span6 title">
<h2 class="pull-left">ARTICLE MANAGER</h2>
</div>
<nav class="span6 search">
<form action="/gateway" method="get">
<input name="search" size="10" type="search" placeholder="Search" results=5>
</form>
<a class="btn" href="/add">ADD</a>
</nav>
</div>
http://jsfiddle.net/9p2VM/7/
Your CSS is not well-formed in the fiddle. Without changing a line of code in the fiddle ie. by just indenting the CSS properly, your code works fine.
This is how your CSS is:
.span6{
float: left;
}
nav{
white-space: nowrap;
.btn{
display: inline-block;
}
form{
margin: 0;
padding: 0;
display: inline-block;
input[type=search] {
margin: 15px 0 0 0;
}
}
}
Change it to:
.span6 {
float: left;
}
nav.span6 {
white-space: nowrap;
float:right;
}
.btn {
display: inline-block;
}
form {
margin: 0;
padding: 0;
display: inline-block;
}
input[type=search] {
margin: 15px 0 0 0;
}
And it works fine. See here->http://jsfiddle.net/9p2VM/8/
Hope this helps!!!
Hello everyone my div area height is displayed different with these browsers: Firefox and Internet Explorer. In Chrome and Safari my div area looks fine could you help me please.
Here is my div area
.openmeclis
{
position:relative;
margin-left:4px;
background:#66B3E3;
width:90px;
height:370px;
display:inline-block;
overflow:hidden;
}
Here is a caps what I mean
This is from Firefox
Here is from Chrome
<div id="subMenu">
<div class="openbaskan" style="float:left">
Başkandan <br />
Özgeçmişi <br />
Haberler <br />
Videolar <br />
Fotoğraf Galerisi
</div>
<div class="openmeclis" style="float:left">
Meclis Üyeleri <br />
Meclis Gündemi <br />
Meclis Kararları <br />
</div>
</div>
CSS:
#subMenu
{
width:964px;
margin-left:auto;
margin-right:auto;
display:none;
font-size:14px;
font-style:normal;
height:336px;
font-family: 'Museo300Regular';
}
Just use line-height to your css. Because every browser renders different line-height,that's why your div is showing problem with different browsers.
Here is the link for the same problem that you have asked
FireFox 3 line-height
CSS line-height issue across browsers
Check this edited answer
Edited Demo
Note the edited CSS below:
.openmeclis
{
position:relative;
margin-left:4px;
background:#66B3E3;
width:90px;
height:370px;
overflow:hidden;
float: left;
list-style: none;
}
#subMenu {
width:964px;
margin-left:auto;
margin-right:auto;
font-size:14px;
font-style:normal;
height:336px;
}
HTML:
----------
<div id="subMenu">
<div class="openmeclis">
<ul>
<li>Başkandan</li>
<li>Özgeçmişi</li>
<li>Haberler</li>
<li>Videolar</li>
<li>Fotoğraf Galerisi</li>
</ul>
</div>
<div class="openmeclis">
<ul>
<li>Meclis Üyeleri</li>
<li>Meclis Gündemi</li>
<li>Gündemi</li>
<li>Meclis Kararları</li>
</ul>
</div>
</div>
Do not add unnecessarily <br/> tag. Instead of that you can use the <ul> methods. You do not need to add style tags in your html when you have the CSS. I don't know what you add in the #sub menu... I just edited the HTML and CSS for openmeclis