How to arrange forms horizontally in the HTML page? - html

I have two forms, and by default, they will appear in the HTML page vertically. However, due to the limitation of the page's space, it is better to arrange them in a horizontal way, with the help of CSS.
The forms are as follows:
<form>Form A</form>
<form>Form B</form>
Any help in CSS?

use float:left on the forms.
HTML:
<form>Form A</form>
<form>Form B</form>
CSS:
form
{
float:left;
}

Float the forms left inside their parent control. You may also need to set a suitable width to get the layout right on different browsers, depending on margins and padding etc.
HTML:
<form class="colform">Form A</form>
<form class="colform">Form B</form>
CSS:
.colform { float:left; width:50%;}

You can place each form within a div. Once you have the 2 divs, use css to make narrow and float them to the left to place them one beside each other. You can also add these classes to the form instead of the div. ie:
<div class="form_wrapper">
<form></form>
</div>
<div class="form_wrapper">
<form></form>
</div>
OR:
<form class="form_wrapper"></form>
<form class="form_wrapper"></form>
Your CSS:
<style>
.form_wrapper {
width: 200px; /* the width of half of your space or 50% */
float: left;
}
</style>
Voila that should do it.

There are a number of lightweight CSS frameworks that take the pain out of horizontal styling of page elements like you desire. These frameworks will take care of handling different browser nuances and let you focus on coding instead of layout:
Bootstrap, from Twitter
Blueprint CSS
Normalize.css

form {
width:50%;
float:left;
}

Or, maybe like this(for proper spacing, on any screen size):
form {
width:35%;
float:left;
padding-left:5%;
padding-right:10%;
}

Related

right padding overwrites the margin

looking at this live demo:http://jsfiddle.net/5AUMA/25/
How do I make the left sidebar text be right justified but about 1% away from the right margin.
When I do the padding-right: 1%; it starts overwriting the margin
Also how do I make the circle be above the text?
EDIT - just edited the link
You could use on the .left class:
direction:rtl;
text-indent: 1%;
Another option would be:
Create a div inside .left and call it .inner-left, then add this CSS to your code:
// HTML
<div class="left">
<div class="inner-left">
LEFT
</div>
</div>
// CSS
.inner-left {
text-align: right;
width: 95%; /* change this value if you need */
}
ps: don't forget to run the jsfiddle to test the changes
Hope it helps.
I think that your best bet is to use the box model to set margins/paddings and use text-align properties and margin auto along with setting how the object should display( block,inline,etc). I played a little with the fiddle example you gave and used the box model to set the element properly inside the parent. Sorry that I used inline CSS but it is just an example that you can extract and transfer to your main CSS file.
Here is the new fiddle test: http://jsfiddle.net/5AUMA/26/
and the box model reference is here: http://www.w3schools.com/css/css_boxmodel.asp
the code example just in case (but the fiddle has it all complete):
<div class="left">
<div style="padding-right:5%; display:block; text-align:right;" >
<img style="margin:auto; margin-right:0; max-width:50%; max-height:50%; display:block;" src="http://img.photobucket.com/albums/v436/passion4architecture/LOGO_ROUND%20and%20CIRCLE/Logo_The-Circle-of-Reason_wwwcircleofreasonorg_dian-hasan-branding_US-2_zpsf675b4a5.png" />
hello
</div>
LEFT
This should help with all your current needs.
Ps: for any element (including images) is better to use css to adjust the widths/heights and alignments.
Cheers :)

How to leave white space on both sides of page?

My client wants the background to have white spaces on sides(weird?), but I couldn't find the solution.
Basically I want to have a background and white on sides for wide screens.
NOTE AND IMPORTANT: I need this on body.
How can I do this?
Try something like this CSS on your body
body { width: 974px; margin: 0 auto; }
The margin statement means that you give your body a top- and bottom-margin of 0. The auto-value means that however much horizontal space remains after you've used up 974px, will be evenly split to add the whitespace on each side of the body.
If you don't have a wrapping container like <header>, <section> that you can apply this width to, you might find yourself a little restricted when it comes to placing content like background-images and such that should display on the sides of the body. You will be left with only the html-element as a parent to the body so that doesn't offer a lot of layers or hooks where you can add advanced styling for decoration and such... just a word of caution :)
You give your container a width (say, 1000px), and then use margin: auto on it.
Demo
HTML
<body class="outerwrapper">
<div id="innerwrapeer" class="innerwrapeer">
</div>
</body>
CSS
body {
width:1024px;
height:auto;
background-color:white;
}
.innerwrapeer {
width:800px;
height:auto;
background-color:red;
}

Right-aligning text under images (without javascript)

I need some advice in creating a caption underneath an image, that is aligned to the right hand side. The image will change, so I can't use fixed value margins or anything like that - is this possible without javascript?
This is the basic layout, 'text-align: right' would work if I could somehow force the wrapper div to constrain to the image width, but currently it breaks past this. Any advice?
<style>
#section{height: 74%; padding-left:5%;}
#photowrapper{position:relative;}
#photo{height:100%; width:auto;}
#detailsdiv{position:relative; text-align:right;}
</style>
<div id='section'>
<div id='photowrapper'>
<img id='photo' src=../imgs/banan.jpg></img>
<div id= 'detailsdiv'>banan</div>
</div>
</div>
Maybe an obvious question but it hasn't been asked that I can see.
Just add display: inline-block; to the #photowrapper CSS
#photowrapper{
position:relative;
display:inline-block;
}
Fiddle: http://jsfiddle.net/DyrS9/
You can add display:table-cell (or table,inline-block) to #photowrapper :
#photowrapper{
position:relative;
display:table;
}
Example

Some doubts about how make an image clickable using CSS

I am studying on a tutorial how to create a tabless web template using HTML + CSS and I have a little doubt related to the following thing:
I have an header that contains a div having id=logo, something like this:
<div id="header"> <!-- HEADER -->
<div id="logo"> <!-- My Logo -->
<h1>My web site is cool</h1>
<p id="slogan">
My web site is finally online
</p>
</div>
......
OTHER HEADER STUFF
......
</div> <!-- Close header -->
And related to this #header div (and its content) I have the following CSS code:
/* For the image replacement of the logo */
h1 {
background: url(../images/logo.jpg) no-repeat;
text-indent: -9999px;
width: 224px;
height: 71px;
}
h1 a {
display: block;
width: 258px;
height: 64px;
text-decoration: none;
}
So this code put an image instead of the My web site is cool text that is in the tag.
I have some problem to understand the h1 a CSS settings, on the tutorial say that this CSS settings for h1 a:
Turns to block (from inline) the display mode of the link in the header, so I can set the width and height, and the image of the logo is now clickable
This thing is not very clear for me and I have the following doubts:
Have I to convert the a element (that is inline) into a block element to give it the same dimension of the underlying image (logo.jpg)?
Tnx
Andrea
Take this example,
an a element is inline by default, so if you were to do something like
CSS
a {background:red; height:210px; width:200px;}
HTML
test
You will notice that the width and height properties aren't working. Now for this element to be sized at that width, you need to set the element's display property to be either display:block or display:inline-block
JSFiddle Demo Example
HTML:
Without display:inline block, width and height set.
<br><br>
With display:inline block, width and height set.
<br><br>
With display:block, width and height set.
CSS:
a {background:#ccc; height:210px; width:200px;}
.inline-block { display:inline-block; }
.block { display:block; }
If you're linking an image, you don't need to give the a height/width or even a display:block. However, you really shouldn't be putting an image inside an h1 like that. You'd be better off making the a inside the h1 a block (using display:block) and setting the background to the image, then hiding the text. To the user of the site, there's not going to be much difference, but it removes images from your HTML code, makes it easier for screen readers, and is more semantically correct. So your code would be:
a { display: block; font-size:0; background-image:url("logo.png"); height:100; width:100 }

Simple html/css layout? (two column)

I'm having a very hard time trying to come up with html/css for a layout to suite the following:
Where the left area is a static menu. The right area is dynamic content, generated using a call to ASP.Net's RenderBody method. You may not believe it, but I have been trying to figure this out for hours. I keep getting either the right section ending up underneath the left section taking 100% of the width or not displaying at all, with Chrome's object inspector saying its 0 pixels wide.
I feel like a complete idiot as this seems as if it should be easy as pie. Could I please get some help?
There's several ways to go about this. Here's one not particularly fancy but straight-up way to go about it:
<body>
<div id="menu">MENU</div>
<div id="content"> content <br /> content <br /> content </div>
</body>
CSS:
div { border: 2px solid black; } /* demo purposes */
#menu {
float: left;
width: 150px;
}
#content {
margin-left: 154px; /* menu width + (2 x menu.border-width) */
}
See this jsfiddle for a working sample.
This solution has the added benefit that your content region will take up exactly 100% of the remaining width of its parent:
<div class="parent">
<div class="content">blah...</div>
<div class="left-menu">blah...</div>
</div>
CSS:
.parent { padding-left:200px;width:100%; }
.content { position:relative;float:left;width:100%; }
.left-menu { position:relative;float:left;width:200px;right:200px;margin-left:-100%; }
Excellent tutorial on fluid layouts: http://www.alistapart.com/articles/holygrail
Works in IE7 and newer, Safari/Chrome/Opera/Firefox...
The best way to do this is by using the already considered safe to use box-sizing property.
Take a look at the tinkerbin -> http://tinkerbin.com/AcJjYk0r
It works as you want it to. Fixed width for the menu, percentage based width for the content area.
Then...
...if you want the background-colors to expand to the highest of the heights between the two boxes (remember, one times the menu can be higher than the content box, and vice-versa), then the only way to go about it (no javascript) is to use a background image and place it below the two boxes. With css3 gradients (safe to use too) it's pretty easy. Take a look:
http://tinkerbin.com/3ETH28Oq