align textbox and text/labels in html? - html

I cant figure it out. How do i align the textbox? I thought using float: left on the labels on the left (then doing it on the input when i notice the input was now on the left without that) but that was completely wrong.
How do i get the textbox align along with the labels on the left of them next to the textbox instead of the far left?
The picture is an example of what i'd like it to look like.

You have two boxes, left and right, for each label/input pair. Both boxes are in one row and have fixed width. Now, you just have to make label text float to the right with text-align: right;
Here's a simple example:
http://jsfiddle.net/qP46X/

Using a table would be one (and easy) option.
Other options are all about setting fixed width on the and making it text-aligned to the right:
label {
width: 200px;
display: inline-block;
text-align: right;
}
or, as was pointed out, make them all float instead of inline.

you can do a multi div layout like this
<div class="fieldcontainer">
<div class="label"></div>
<div class="field"></div>
</div>
where
.fieldcontainer { clear: both; }
.label { float: left; width: ___ }
.field { float: left; }
Or, I actually prefer tables for forms like this. This is very much tabular data and it comes out very clean. Both will work though.

I like to set the 'line-height' in the css for the divs to get them to line up properly. Here is an example of how I do it using asp and css:
ASP:
<div id="profileRow1">
<div id="profileRow1Col1" class="righty">
<asp:Label ID="lblCreatedDateLabel" runat="server" Text="Date Created:"></asp:Label><br />
<asp:Label ID="lblLastLoginDateLabel" runat="server" Text="Last Login Date:"></asp:Label><br />
<asp:Label ID="lblUserIdLabel" runat="server" Text="User ID:"></asp:Label><br />
<asp:Label ID="lblUserNameLabel" runat="server" Text="Username:"></asp:Label><br />
<asp:Label ID="lblFirstNameLabel" runat="server" Text="First Name:"></asp:Label><br />
<asp:Label ID="lblLastNameLabel" runat="server" Text="Last Name:"></asp:Label><br />
</div>
<div id="profileRow1Col2">
<asp:Label ID="lblCreatedDate" runat="server" Text="00/00/00 00:00:00"></asp:Label><br />
<asp:Label ID="lblLastLoginDate" runat="server" Text="00/00/00 00:00:00"></asp:Label><br />
<asp:Label ID="lblUserId" runat="server" Text="UserId"></asp:Label><br />
<asp:TextBox ID="txtUserName" runat="server"></asp:TextBox><br />
<asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox><br />
<asp:TextBox ID="txtLastName" runat="server"></asp:TextBox><br />
</div>
</div>
And here is the code in the CSS file to make all of the above fields look nice and neat:
#profileRow1{width:100%;line-height:40px;}
#profileRow1Col1{float:left; width:25%; margin-right:20px;}
#profileRow1Col2{float:left; width:25%;}
.righty{text-align:right;}
you can basically pull everything but the DIV tags and replace with your own content.
Trust me when I say it looks aligned the way the image in the original post does!
I would post a screenshot but Stack wont let me:
Oops! Your edit couldn't be submitted because:
We're sorry, but as a spam prevention mechanism, new users aren't allowed to post images. Earn more than 10 reputation to post images.
:)

I have found better option,
<style type="text/css">
.form {
margin: 0 auto;
width: 210px;
}
.form label{
display: inline-block;
text-align: right;
float: left;
}
.form input{
display: inline-block;
text-align: left;
float: right;
}
</style>
Demo here: https://jsfiddle.net/durtpwvx/

Related

Buttons to be aligned side by side

I have this code:
<asp:Panel ID="Panel4" runat="server">
<div style="position:absolute; bottom:578px; left:4%; width: 6%;" >
<asp:linkButton id="cmdBackHour" runat="server" CssClass="configurebuttons" Text="< 1 hr" ToolTip="Go back one hour"/>
<asp:linkButton id="cmdBackDay" runat="server" CssClass="configurebuttons" Text="< Day" ToolTip="Go back one day" />
<asp:linkButton id="cmdForwardDay" runat="server" CssClass="configurebuttons" Text="Day >" ToolTip="Go forward one day" />
<asp:linkButton id="cmdForwardHour" runat="server" CssClass="configurebuttons" Text="1 hr >" ToolTip="Go forward one hour" />
</div>
</asp:Panel>
This displays my buttons one below the other. I want these buttons to be displayed side by side.
Add below css property to your buttons.
float:left;
display:inline-block;
This will help.
Use one common class to all buttons to apply this.
Eg.
.btn {
float:left;
display:inline-block;
}

asp textbox required field validator message positioning

I have used a asp:RequiredFieldValidator to validate a textbox. It works fine. But i need to change the position of the error message.
<div class="form-group">
<label for="txtGarageName" class="col-sm-2 control-label">Garage Name</label>
<asp:TextBox runat="server" placeholder="Garage Name" CssClass="form-control" Width="50%" ID="txtGarageName"></asp:TextBox>
<asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server"
ControlToValidate="txtGarageName"
ErrorMessage="Garage name is a required field."
ForeColor="Red">
</asp:RequiredFieldValidator>
</div>
When i use this error message display starting from directly under the label.
What i need to do is get the error message to display either in front of the text box or align it with the TextBox start point which means to alighn it more to right. I have tried using a css code as well as putting
margin-left=""
which i saw as solutions in the internet. Neither worked properly.
Using the col-md-6 or span6 CSS class for your TextBoxes will work for you
<asp:TextBox runat="server" placeholder="Garage Name" CssClass="form-control span6" ID="txtGarageName"></asp:TextBox>
<asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server"
ControlToValidate="txtGarageName"
ErrorMessage="Garage name is a required field."
ForeColor="Red">
</asp:RequiredFieldValidator>
Use the grid system
http://getbootstrap.com/css/#grid-example-basic
If you prefer a simple (non bootstrap) solution you should still use some placeholders for better formatting. An example that i found (not mine)
http://jsfiddle.net/dqC8t/1/
#wrapper {
width: 500px;
border: 1px solid black;
overflow: auto;
}
#first {
float: left;
width: 300px;
border: 1px solid red;
}
#second {
border: 1px solid green;
margin: 0 0 0 302px;
}

How can I make a responsive scrollbox with seperate text fields?

I'm trying to make a scrollbox for my webpage with two separate text fields. I implemented a solution and tested it on my local machine. Later I looked at it from another computer, and the web page was not looking as expected - it placed the right text field under the left one.
What should i do, so that my web page works and looks as expected on every computer? Can you point me to the right direction.
My HTML so far:
<style="text/css">
.scroll {
padding: 10px;
height: 280px;
width: 566px;
overflow: auto;
</style>
<div class="scroll">
<p style="margin: 10; float: left;">
etc <br />
etc <br />
etc <br />
</p>
<p style="margin-left: 25px; float: left;">
etc <br />
etc <br />
etc <br />
</p>
Are you using floats so they don't stack one on top of the other? Of course if your text fields are too wide then you'll need to reduce the size so they have room to appear side by side. As you can see it works in this example. Added new example with scrolling here
HTML
<div id="righttext">
<input type="text">
</div>
</div>
<div style="float:none;"></div>
CSS
#lefttext, #righttext {
float: left;
}
#container {
height: 100px;
overflow:scroll;
}

Fixed header and window resize

I have a fixed header with navigation menu on the site:
#header_wrapper
{
height: 75px;
background-color: #FD735B;
z-index: 999;
position: fixed;
width: 100%;
}
#header_wrapper .control_wrapper
{
position: absolute;
right: 0px;
}
#header_wrapper .control_wrapper .control
{
float: left;
padding-left: 35px;
padding-top: 25px;
font-weight: bold;
}
.inner_content
{
height: 100%;
margin: 0px auto;
width: 85%;
position: relative;
z-index: 1;
}
Here is the HTML of the header:
<div id="header_wrapper">
<div class="inner_content">
<div class="control_wrapper">
<div class="control local">
<a class="white_font" id="link_user_experience">USER EXPERIENCE</a>
</div>
<div class="control local">
<a class="white_font" id="link_restocking">RESTOCKING EXPERIENCE</a>
</div>
<div class="control local">
<a class="white_font" id="link_analytics">ANALYTICS</a>
</div>
<div class="control">
<a class="white_font" id="link_team" href="team">TEAM</a>
</div>
</div>
</div>
The problem is that when you resize window and make it narrow part on navigation menu is cut off. And if you trying to scroll horizontally it remains cut off.
Here is an image of the cut off header:
I'm trying to scroll to the right side - the content is scrolled, but the header remains the same:
How I can make the header look good after resizing?
UPDATE:
I tried to recreate my problem on jsfiddle. I set big width to page and header in order to imitate narrow window (my problem appears only when user resize window and make it narrow).
I put 3 titles in header. When you load fiddle you will see only 2 of them. The third one is out of viewable area. I thought that you should just scroll horizontally and fixed header will scroll with the rest of the page. But fixed header is not scrolled and you can not see title #3.
In other words, I need fixed header to scroll horizontally like any other element.
Looks like your navigation content is position:absolute; right:0px; which would cause your navigation to go as far right as possible even when the browser is resized.
If you create a li and float:right, display:inline-block it should give you the functionality that you're looking for.
<nav>
<ul>
<li>ABOUT</li>
<li>BLOG</li>
<li>CONTACT</li>
</ul>
</nav>
nav{width:100%;position:absolute;background-color:red;}
nav li{float:right;display:inline-block; padding-right:10px;}
Here's a JSFiddle:
http://jsfiddle.net/gBYZ4/3/
edit: cleaned up my html and fiddle. Had the header floated right by accident.
Maybe you could try the solution I wrote on Fixed top bar that scrolls horizontally with the rest of the page which seems to be also what you want.
There is a AJAX Control which helps to overcome this problem. You can use "AlwaysVisibleControlExtender". I have used it in my page and it works perfectly fine.
The below is the asp code.
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<style type="text/css">
.header{width:100%;height:100px;position:fixed;z-index:1000;}
.content{padding-top:160px;}
</style>
</head>
<body>
<form id="form1" runat="server">
<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" ScriptMode="Release">
</ajaxToolkit:ToolkitScriptManager>
<ajaxToolkit:AlwaysVisibleControlExtender ID="AlwaysVisibleControlExtender1" runat="server" TargetControlID="lnkHome" HorizontalOffset="70" VerticalOffset="60" HorizontalSide="Right" VerticalSide="Top">
</ajaxToolkit:AlwaysVisibleControlExtender>
<ajaxToolkit:AlwaysVisibleControlExtender ID="AlwaysVisibleControlExtender2" runat="server" TargetControlID="lnkLogout" HorizontalOffset="20" VerticalOffset="60" HorizontalSide="Right" VerticalSide="Top">
</ajaxToolkit:AlwaysVisibleControlExtender>
<ajaxToolkit:AlwaysVisibleControlExtender ID="AlwaysVisibleControlExtender3" runat="server" TargetControlID="lblName" HorizontalOffset="110" VerticalOffset="60" HorizontalSide="Right" VerticalSide="Top">
</ajaxToolkit:AlwaysVisibleControlExtender>
<ajaxToolkit:AlwaysVisibleControlExtender ID="AlwaysVisibleControlExtender5" runat="server" TargetControlID="Image1" HorizontalSide="Center" VerticalSide="Top">
</ajaxToolkit:AlwaysVisibleControlExtender>
<asp:Image ID="Image1" runat="server" Height="150px" ImageUrl="~/Image/ABC.jpg" Width="1594px" />
<p style="margin-left: 1240px; width: 187px;">
<asp:Label ID="lblName" runat="server" Font-Size="Small" Font-Names="Arial" ForeColor="White">
</asp:Label>
<asp:LinkButton ID="lnkHome" runat="server" Font-Size="Small" ForeColor="White" Font-Names="Arial">Home</asp:LinkButton>
<asp:LinkButton ID="lnkLogout" runat="server" Font-Size="Small" ForeColor="White" Font-Names="Arial">Logout</asp:LinkButton>
</p>
You need to drag and drop Alwaysvisible extender control and give the target control id as above. Hope this helps.

Making a Input Text Field Be On The Right Side Of a Image

I have a 50x50 image and an <input type="text" /> field that I want to be on the right side of the image. I've tried this:
<img src="missing-image.png" />
<div name="image_input">
<input type="text" />
</div>
And with this CSS:
#image_input {
position: absolute;
top: 10px;
}
But the text input won't go to the right side of the image. Also as you can see I want it to be centralized with the height of the image and as I can see it won't work too. How I can correct this?
PS: All that is inside a <form>
Position absolute gives you more control:
HTML
<div name="image_input">
<img src="missing-image.png" />
<input type="text" />
</div>
CSS
div {
position:relative;
}
input{
position:absolute;
right:10px;
bottom:20px;
}
Try this:
<div id="image_input">
<img src="missing-image.png" />
<input type="text" />
</div>
and the CSS:
#image_input img {
float: left;
clear: none;
}
Note that I changed the div's "name" attribute to an "id" attribute.
there are a couple of ways to center align text next to an image. you can put it in a list and make the image the list style type. The other thing you can do it properly pad the element to center align it.
Try changing to this:
<div name="image_input">
<img src="missing-image.png" />
<input type="text" />
</div>
And the CSS:
.img {
display: inline-block;
}
To center the height, you might want to use one of the vertical-align options on the input tag.
such as:
input {
vertical-align: middle;
}
I don't use vertical-align very much, so you might have to tweak it a little to get it to work, but see here: http://www.w3schools.com/css/pr_pos_vertical-align.asp