Aligning fonts in label - html

Is there any way to alter the text property inside label so that it touches the baseline? In the example, both State and City are above the baseline.
http://jsfiddle.net/6VzLR/
HTML:
<div id="leftContent">
<div id="state">
<label for="state">State:</label>
<select name="state">
<option>State - Karnataka</option>
</select>
</div>
<div id="city">
<label for="city">City:</label>
<select name="city">
<option>City - Bangalore</option>
</select>
</div>
</div><!--leftContent-->
CSS:
#state label, #city label{
width:40%;
display:inline-block;
margin: 3px 0 3px 6px;
}

If you specify a height for the label you can use line-height to adjust where the text will be:
#state label, #city label{
width:40%;
display:inline-block;
border:1px solid #000000;
margin: 3px 0 3px 6px;
line-height: 28px;
height: 20px;
vertical-align: bottom;
}
Here's the JSFiddle.
EDIT: You can add
#state select, #city select {
margin-bottom: 4px;
}
So the select boxes are positioned the same as well.
Here's the updated JSFiddle.

The order of margins in CSS margin property is top-right-bottom-left.
So it looks like you are setting 0px for right margin, not for bottom one.
Try this:
margin: 3px 3px 0px 6px;
Or:
margin-bottom: 0px;
I would persionally better explore padding css option though.

I applied the following CSS to your HTML snippet:
label, select {
font-family: arial;
font-size: 2.0em;
vertical-align: baseline; /* default value */
}
label {
border: 1px solid gray;
width:40%;
display:inline-block;
margin: 3px 0 3px 6px;
text-align: right;
}
and got the following result: http://jsfiddle.net/audetwebdesign/3CQbq/
The text in the label and the select elements align along a common baseline, which is more obvious if you increase the font size.
However, you need to make sure that the same font family and font size are used in both the label and the select fields to get the same alignment. (In your example, this does not seem to be an issue even though the fonts differ.)
In your example, the text align along the same baseline and the bottom of the two boxes also align along a common horizontal line.
However, the box around the label is taller than the box for the select group, so that may be what you are trying to fix.

Related

How to put space to text in <input>

I want to put left and right space to text inside of as you can see on image.
I was able to put left space with text-indent but it doesn't seem to work for right space.
Can anyone help me?
sample image
Here inputs can have left right padding to act for indent.
input {padding: 0 5px}
So above inputs will carry 5px of space inside to both left and right.
if you want it in one text box then add class like below and use it in the css
<input type='text' name='firstname' class='space'>
.space
{
padding-left : 10px;
padding-right: 10px;
}
If you want both side you can use padding only.If you use like this it will work when you have appropriate space in the window.If you want to keep the space in at any screen size you can use border-box.
.space
{
padding-left : 10px;
padding-right: 10px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
Well one option would be to combine text-indent with a padding if your markup allows it:
text-indent: 10px;
padding-right: 20px;
Another method I guess could be the "direction" attribute with a value of "rtl" in combination with "text-align:left".
please try following code
input{
border: none;
padding: 10px;
margin: 10px;
height: 20px;
width: 500px;
border:1px solid #eaeaea;
outline:none;
}
input:hover{
border-color: #a0a0a0 #b9b9b9 #b9b9b9 #b9b9b9;
}
input:focus{
border-color:#4d90fe;
}
<div class="mainDiv">
<input type="text" />
</div>
You can set some padding to your input text :
input {
padding: 0 5px /* 0 is for top and bottom | 5px is for left and right */
}
Here the doc on the CSS padding property : https://www.w3schools.com/css/css_padding.asp

CSS: Styling an input element's text (as opposed to the input element itself)?

EDIT: I've added the relevant code below at the bottom of this question. As you'll see there, the button is wrapped within a div. Also, this problem only occurs in one browser, that being Firefox, and I'll be using a hack to target that browser only.
I have an input element of type submit (i.e., basically a submit button). The text displayed in this element, as defined in the element's value attribute, appears too low (i.e., too close to the bottom of the button instead of vertically centered). The button has a fixed height.
Naturally, I want to move the button's text, as defined in the value attribute, one or two pixels upwards.
I've tried a few things with the button's padding (top and bottom), but that didn't change anything. [Is that to be expected, BTW?] Therefore, I would like to use relative positioning to move the text upwards a bit.
The thing is, however, that I need to target the text itself, NOT the input/button element. And that's of course because the button itself should stay at its current location, I only want to move the TEXT displayed on the button.
Thus my question: Is there a way, in CSS, to target not the button but only its displayed text (as defined in the value attribute) ?
Of course, other solutions (preferably CSS only) are welcome as well.
Code:
HTML:
<form id="zoekform">
<input type="text" class="" id="search-text" name="search-text" placeholder="Search">
<div class="erom" id="erom2">
<input id="zoekknop" style="float: right" type="submit" method="GET" value="Search!" />
</div>
</form>
CSS:
#zoekform {
height: 29px;
box-sizing: border-box;
margin-top: 6px;
margin-bottom: 9px;
}
.erom {
height: 100%;
display: inline-block;
box-sizing: border-box;
}
#erom2 {
border: solid 1px #452F5D;
width: 27%;
display: inline-block;
box-sizing: border-box;
}
#zoekknop {
float: right;
height: 100%;
color: white;
font-size: 19px;
box-sizing: border-box;
background-color: #446666;
color: white;
letter-spacing: 2px;
border: solid 1px white;
width: 100%;
}
And finally the part where I'm targeting Firefox only, and where I can't get the padding working (and to be sure, the "media query" (it's not really a media query) does work, and in any case I've also tried this without the media query, i.e. as part of the regular CSS):
#-moz-document url-prefix() {
#zoekknop {
padding-top: -1px !important;
padding-bottom: 9px !important; // I set it to 9px for now, so that I could clearly see if it worked
}
}
For some reason form elements are particular and quirky about font.
Assign a font to the <submit>'s parent, then use font: inherit on the <submit> button.
On the <submit> assign line-height of 1.4 to 2 (notice there's no unit like px or em.) I actually have the line-height assigned by inheriting the font from <form> 1.4.
Set width using the ex unit of measurement. One ex is as wide as ax character, making it a great way of gauging how much space you are using in relation to your text. I used 9ex for a 6 character word (i.e. Submit).
This ruleset may help you for Firefox:
input::-moz-focus-inner {
border: 0;
padding: 0;
/* Some users have said these last two are
unnecessary or should be -2px */
margin-top:0;
margin-bottom: 0;
}
Here's some changes I did to your button and search field:
#zoekknop {....
....
border: 2px double white;
line-height: 1.65;
vertical-align: baseline;
}
#search-text {
line-height: 1.75;
vertical-align: baseline;
padding: 4px 3px 0;
}
Review the Snippet below:
#form {
font: 400 16px/1.4'Verdana';
}
#form .sub {
font: inherit;
width: 9ex;
color: blue;
border-radius: 5px;
}
#form .sub:hover {
color: cyan;
background: #888;
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#zoekform {
height: 29px;
box-sizing: border-box;
margin-top: 6px;
margin-bottom: 9px;
font: 400 16px/1.4 'Verdana';
}
#zoekform #zoekknop {
color: white;
font-size: 18px;
box-sizing: border-box;
background-color: #446666;
color: white;
border: 2px double white;
line-height: 1.65;
vertical-align: baseline;
}
#search-text {
line-height: 1.75;
vertical-align: baseline;
padding: 4px 3px 0
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
input::-moz-focus-inner {
border: 0;
padding: 0;
margin-top: 0;
margin-bottom: 0;
}
<form id="form" name="form">
<input type="submit" class="sub" value="Submit" />
</form>
<form id="zoekform">
<input type="text" class="" id="search-text" name="search-text" placeholder="Search">
<input id="zoekknop" type="submit" method="GET" value="Search!" />
</form>
This should work
#buttonID{
width: 500px;
height: 500px;
padding-bottom: 100px;//pushes text up inside the button
}
Make sure you define the height, width, line-height, font-size, and padding of the button. Then you should be able to manipulate the padding and line-height to get the result you want. It sounds like the button may be inheriting a line height that is causing the issue.
Targeting the text itself isn't the way to go about this. Would be helpful to see the CSS and HTML of the button, and note which browser the issue appears in.

CSS aligning text boxes with labels

My fiddle pretty much shows the problem. Trying to get the labels to be on the left side of each text box if anyone could help. http://jsfiddle.net/HC64Y/
<div id="boxalign2" class="boxalign2" >
<label>Hospital*:</label><input class="rounded2" required title="Hospital is required!" name="MainHospital" type="text" />
<label>Title*:</label><input class="rounded2" name="MainTitle" type="text"/>
<label>Department*:</label> <input class="rounded2" name="MainDept" type="text"/>
</div>
css
input.rounded2 {
border: 1px solid #ccc;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;
-moz-box-shadow: 2px 2px 3px #666;
-webkit-box-shadow: 2px 2px 3px #666;
box-shadow: 2px 2px 3px #666;
font-size: 20px;
padding: 4px 7px;
outline: 0;
-webkit-appearance: none;
float: left;
display: inline-block;
clear: left;
width: 150px;
text-align: right;
}
You are making your inputs inline-block, but you are also floating them to the left.
If you remove the float: left and add <br> after each input, you will get the correct behavior.
http://jsfiddle.net/A8es3/
To align the boxes, add a div wrapper around each label/input, make your label inline-block with a fixed width. There are other ways to do this as well, but this is one way.
http://jsfiddle.net/A8es3/1/
As stolli mentioned, you can also simply use the label element as the wrapper:
http://jsfiddle.net/A8es3/2/
You can give to your div .boxalign2 and label fixed widths.
View the demo http://jsfiddle.net/HC64Y/11/
.boxalign2 {
width:400px;
}
label {
text-align:right;
padding-right:20px;
display:inline-block;
min-width:150px;
}
To ammend Jeff B's answer to get your result, simply give the elements a width in your css
label {width: 100px} where '100' is whatever value looks best for your layout.
Also, remember that the primary purpose of labels (as opposed to just div's or span's for labeling) is that labels act as a secondary click target for the control they are associated with. Therefore, you can wrap your elements in the label tag (<label><input /></label>) or associate them by id (<label for="foo"><input id="foo"/>) and give the user much more to click, simply by clicking the label, they can toggle the control, focus the text input, whatever. A big boon in usability for touch devices.
<!DOCTYPE html>
<html>
<head>
<title>Centering a form</title>
</head>
<body>
<div class="form">
<label>Name</label>
<input type="text" name="name">
<label>Email</label>
<input type="text" name="email">
<label>Phone</label>
<input type="text" name="phone">
</div>
</body>
</html>
<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/

CSS : Trying to reproduce input with div+input but having a bad top padding

I will make a jQuery plugin for one of my projects, and I am trying to simulate an input with divs and spans to make it "richer".
Instead of having [ input ], I will have [ span (containing a A for removing) + input] so the user will not see the difference because he will be typing on a real input without borders, and the result (when accepted) will appear in a small rectangular box at the left of the field.
But I have one problem: there's always a gap between the top of the div and the span containing the left text. Same for the input, the two do not have the same margin for the top and bottom.
I am trying to remove that incorrect top margin (or padding), it looks like 3px from the top and 2px for the bottom. I seem to have tried everything and I always end up to have too much pixels on the top of the span & input.
I have reproduced my problem here (only a few lines of css code):
http://jsfiddle.net/JB9Uq/1/
<div class="input-reference"><span>Content in span <i class="icon-remove">x</i></span><input type="text"></div>
I'd need some assistance on that, I tried margins, paddings, line height, display:inline-block... but it still does not seem to work.
Thank you for your help.
I think that is what you looking for
1. add a float left
2. add height and line height
<div class="input-reference"><span>Content in span <i class="icon-remove">x</i></span><input type="text"></div>
input, textarea, span {
font-family:sans-serif;
font-size:12px;
outline: none;
margin: 0;
border: 1px solid transparent;
}
.input-reference{
display: inline-block;
border: 1px solid #DDDDDD;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.input-reference:after{
content: "";
display: block;
clear: both;
}
.input-reference span,
.input-reference input{
display: inline-block;
float: left;
padding: 0 5px;
/*adjust your height here*/
line-height: 20px;
height: 20px;
}
.input-reference span{
background-color: #53A9FF;
color: #fff;
}
UPDATE
check jsfidle
http://jsfiddle.net/c5q7hauv/

aligning image next to textbox

I am having difficulty in aligning an image next to a text box. I was wondering if there is an easy way to do it other than setting padding and margin. because those measures can vary in each browsers. I have made a fiddle http://jsfiddle.net/wD5T9/
<div id='searchWrapper'>
<input id='searchBox' style='width:250px; border:1px solid #cccccc; border-radius:7px 7px 7px 7px; padding:5px 28px 5px 10px; margin-top:14px; margin-left:50px;height:18px;' type='text' placeholder='Search'/><img src='http://www.q-park.ie/Portals/8/images/search-icon.png'/>
</div>
Just add to the CSS:
#searchWrapper img {
vertical-align: middle;
}
Whenever I try to position something very delicately, I chose to use this sort of method:
position:relative;
and then I define by using top, left, right and buttom.
http://jsfiddle.net/wD5T9/5/
Hope this helps