<div id="divL">
<input name="email" type="text" placeholder="input text">
<div class="divInput">divInput</div>
<div class="divtxt">divtxt</div>
<input name="sname" type="text" placeholder="input text">
<select name="srodstvo">
<option value="1">select</option>
<option value="2">323</option>
</select>
<div class="divtxt">divtxt</div>
</div>
CSS
*{
margin:0;
padding:0;
}
#divL{
width:45%;
margin:5vh 0 0 5vw;
border:thin solid blue;
}
input[type="text"], .divtxt, .divInput, select{
width:100%;
margin:4px 0;
padding:4px;
border:thin solid #999;
border-radius:3px;
}
All elements have the same margins, padding and width. But the distance between second end the third element is different and select is shorter !?
fiddle is here
To fix the width, add this CSS rule:
input, select
{
box-sizing: content-box;
-moz-box-sizing: content-box;
-webkit-box-sizing: content-box;
}
To fix the margins: add display: inline-block to...
input[type="text"], .divtxt, .divInput, select
{
width:100%;
margin:4px 0;
padding:4px;
border:thin solid #999;
border-radius:3px;
display: inline-block;
}
Here's it working: http://jsfiddle.net/leniel/Y5aVB/4/embedded/result/
Try adding a second value to padding
padding:4px 0;
Fiddle
Tested in Firefox 23
UPDATE:
To fix the margin between elements 2 and 3, set all 4 sides in padding
margin:4px 0 0 0;
To keep the spacing at the bottom, set a padding in the outer div
padding:0 0 4px 0;
Updated fiddle
It is due to Box-Sizing.
Input has box-sizing is content-box whereas select is by default has border-box as box-sizing. So you can change the box-sizing property for the select by adding this to your markup
select
{
box-sizing:content-box;
}
Without setting this property select has less height than the other elements (In Chrome).
One more thing is after setting this your elements are still outside the parent container. It is because you have put their width=100% along with padding : 4px which make them bigger than 100% of parent. So just set 0 padding from left and right.
Padding:4px 0;
And for the uneven margin in third element add
display:inline-block;
Update Js Fiddle
Related
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
I'm trying to setup a clean CSS to style a button to visually looks merged with the near input field.
I'm using this CSS currently:
button {
position: relative;
left: -4px;
box-sizing: border-box;
padding: 0 10px;
margin: 0;
font-size: 17px;
border: 1px solid gray;
border-radius: 0 3px 3px 0;
}
http://jsfiddle.net/GRwqL/
The main problem is the usage of the left property, I don't think it's a good practice, mostly because it's not handled correctly on all browsers.
The other problem is that this code in Internet Explorer and Firefox makes the button not high as the input field.
So I was looking for some help to write a better code cross-browser and cleaner.
Personally I don't care if is needed a wrapper element or any other HTML element, I just need a clean code, cross browser and that works well.
<span class="inputWithButton">
<input type="text"><button>Submit</button>
</span>
input, button{outline: none;}
.inputWithButton{
display:inline-block;
overflow:hidden;
border:1px solid gray;
border-radius: 3px;
}
.inputWithButton > *{
vertical-align:top;
border:0;
margin:0;
padding: 3px 10px;
}
.inputWithButton > input[type=text]{
width:150px;
}
.inputWithButton > button{
border-left:1px solid gray;
background:#eee;
cursor:pointer;
width:70px;
}
.inputWithButton > button::-moz-focus-inner {
border: 0;
}
DEMO with higher paddings and different borders colors : http://jsbin.com/OPiroyib/4/edit
(Just remove border from the span and add border to both input and button) That easy.
You need to override the default margin on the input element too.
jsFiddle example
input, button {
margin:0;
}
In doing so, there will no longer be space between the elements, assuming there is also no space between them in the markup. Note, that inline elements respect the whitespace in the markup.
For instance, even after resetting the default margin there is space between the elements, if there is space between them in the markup (example)
For your second problem (making the elements the same height), do the following:
input, button {
box-sizing: border-box;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
padding:0;
margin:0;
vertical-align:top;
line-height:30px;
height:30px;
}
Basically, use box-sizing to change the box model, again reset the margin/padding, use vertical-align:top for alignment issues, and then set an equal line-height/height on both elements.
jsFiddle example
Take a look at css-reset or normalize.css to set the defaults in all browsers to "null".
Also css frameworks like bootstrap are very cool!
Have you thought about using a simple span tag instead of a button and then attach an onclick event to it?
The following seems to work ok for me - though you might need to use a reset / modenizer style sheet to make it more predictable on different browsers.
http://jsfiddle.net/GRwqL/13/
<input class="nospace"></input><span class="nospace">Submit</span>
.nospace {
margin: 0;
padding: 0;
}
span.nospace {
height: 1em;
margin: 0;
padding: 1px;
border: 1px solid black;
}
HTML:
<p>
<input type="radio" id="SQL:79" name="SQL" value="79" maxlength="300">
<label for="SQL:79">Microsoft SQL Server 2012 Express - 64 bit</label>
</p>
relevant CSS:
p {
line-height:23px;
vertical-align:top;
margin:0 0 8px 0;
padding:0;
clear:both
}
input {
margin:0 5px 0 0;
padding:0;
height:23px;
}
input[type="radio"] {
border:none;
background:none;
vertical-align:text-bottom
}
label {
vertical-align:top
}
My input and label are exact 23px high, however the <p> is 28px :(
When I remove vertical-align from the input, the <p> reduces to 25px; but still not the desired 23px!
I have changed the vertical-align on the input[type=radio] from text-bottom to plain bottom/top; this makes the parent p exactly 23px :)
PS: this line of code comes from the HTML5 boilerplate reset, so be aware!
Drop the line-height of p to 19px or add a margin-bottom: -2px to the input.
http://jsfiddle.net/EWfyM/
p {
line-height:23px;
vertical-align:top;
margin:0 0 8px 0;
padding:0;
clear:both
}
input {
margin:0 5px 0 0;
padding:0;
height:23px;
margin-bottom: -2px;
}
input[type="radio"] {
border: none;
background:none;
vertical-align:text-bottom
}
label {
vertical-align:top
}
I know this does not answer your question of "Why?", but using firebug I was able to get your paragraph height to display as 23px by changing the height of your radio button.
This is the CSS I changed:
input[type="radio"], input[type="checkbox"] {
box-shadow: 0 0 0;
height: 18px;
margin: 0 5px 0 0 !important;
padding: 0 !important;
}
Notice I changed your height: 23px; to height: 18px. I could not find an answer online, but perhaps the radio button itself has some default height.
Using display inline works:
(I've used inline css here)
<p style="display:inline;margin:0 0 0px 0;padding:0;clear:both;">
<input type="radio" value="79" id="SQL:79" name="SQL" maxlength="300" style="display:inline;margin:0 0px 0 0; padding:0; height:19px;border:none; background:none;vertical-align:middle;position:relative;top:-2px;">
<label for="SQL:79" style="display:inline;">Microsoft SQL Server 2012 Express - 64 bit</label>
</p>
Hope that helps.
The p tag will get expanded as per the content size.
We have to specify the height for the p tag if we need.
Here is modifed css (simplify :)):
p {
line-height:23px;
vertical-align:top;
margin:0 0 8px 0;
padding:0;
clear:both
}
input {
margin:0;
padding:0;
}
input[type="radio"] {
border: none;
background:none;
}
label {
vertical-align:baseline;
}
Setting the height of input[type=radio] cannot enlarge its visual
shape. So I delete the height.
When the display of child element (input) is inline or inline-block,
setting the line-height of parent element can align the child
element center vertically. But you can also align the child element
top or bottom vertically with vertical-align.
I have changed the vertical-align on the input[type=radio] from text-bottom to plain bottom/top
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.
This is a problem I am always having.
The following HTML:
<form id="sy_login">
<ul class="form_column">
<li>
<input id="sy_login_username" name="sy_login_username" placeholder="Username"></input>
</li>
<li>
<input id="sy_login_passowrd" name="sy_login_password" placeholder="Password"></input>
</li>
</ul>
</form>
Followed by the following CSS:
#CHARSET "ISO-8859-1";
body {
background: #DDDDDD;
padding:0px;
margin:0px;
}
input[placeholder], [placeholder], *[placeholder] {
font-style:italic;
}
.form_column {
list-style-type: none;
padding: 0px;
margin: 10px 10px 10px 10px;
width:100%;
}
.form_column input, .form_column textarea, .form_column select {
width: 100%;
}
Yields the following result:
This is a firebug inspect of one of the input fields.
From what I can tell, ul is clipping out of the parent form due to the margin.
I need the ul to consist of a margin whilst having a width of 100% and for the inputs to also be 100% in width.
Updates:
I attempted replacing the margin with padding as that would have had the same intended desired effect, but it looked exactly the same. I really want to avoid a case of having to use static widths on the inputs themselves.
Another note that might prove useful for answering is that this only needs to work in HTML5, a cross standards solution would be good, but there is technically no need.
After removal of width:100%
It is now looking much better. However I have highlighted the problem with the input, the input needs padding for the text, yet the width of the ul must be dynamic to the parent form, with itself must have a dynamic width to the window.
Remove the margin from UL.
Give padding to FORM. (that gives auto margins to ul).
Also do remember, When you set the width to 100% for any element then it will take the full width of its parent element, now adding some margin or padding to this element exceeds the full width of parent and may break the UI.
i.e Margin(=10px)+Width(=100%) > Width of Parent element.
Visit this link to get an idea of css box model.
http://www.addedbytes.com/articles/for-beginners/the-box-model-for-beginners/
thank you.
Let's see another full version: The red border is belong to a form, a blue border belongs to a UL. Remove it if you want.
body {
background: #DDDDDD;
padding:0px;
margin:0px;
}
input[placeholder], [placeholder], *[placeholder] {
font-style:italic;
}
#sy_login{
border:solid 1px red;
}
.form_column {
border:solid 1px blue;
margin: 0px;
padding:5px;
}
.form_column ul,li{
list-style-type: none;
margin:0px;
padding:0px;
width:auto;
}
.form_column input, .form_column textarea, .form_column select {
width:100%;
}
Try commenting width:100% on form_column
.form_column {
list-style-type: none;
padding: 0px;
margin: 10px 10px 10px 10px;
'width:100%;
}
Refer LIVE DEMO
.form_column {
list-style-type: none;
padding: 0px;
margin:10px;
}
Try something like this:
.form_column {
list-style-type: none;
padding: 10px;
margin: 0;
width:100%;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}