HTML Input right padding on 100% width - html

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;
}

Related

Styling Input and button - height issue

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;
}

input height:23px makes <p> height:28px :(

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

Header CSS breaking

I'm pretty terrible at CSS/design so I'm struggling with some CSS here.
The page looks fine when loaded in a full screen browser at 1920x1080, however, as soon as you minimise or load the page on a mobile device the header content completely loses its placing but the body is fine.
Here's the CSS elements in question:
#header {
background: url(assets/header_bckg.gif) repeat-x ; height:120px;
}
#logo { display:inline-block; float:mid-left; padding:50px 0 0 570px; }
#logo { color:#FFFFFF; text-decoration:none; font-weight:bold; height:12px; font-size:20px; text-transform:uppercase;}
#login { display:inline-block; float:mid-right; padding-left:400px; padding-bottom: 7px; vertical-align:middle;}
#login{ color:#FFFFFF; text-decoration:none; font-weight:bold; height:12px; font-size:12px; text-transform:uppercase;}
#avatar { display:inline-block; position:absolute; margin-top:28px; float:mid-right; padding-left: 505px; padding-bottom: 15px; vertical-align:middle; }
#avatar_online {
background: linear-gradient(to bottom, #7BAFD6 5%, #506D92 95%) repeat scroll 0 0 transparent;
filter: none;
height: 50px;
width: 50px;
padding: 3px;
background-color: #545454;
border-radius: 3px 3px 3px 3px;
}
#avatar_offline {
background: linear-gradient(to bottom, #706C6B 5%, #4E4D4D 95%) repeat scroll 0 0 transparent;
filter: none;
height: 50px;
width: 50px;
padding: 3px;
border: 1px solid #545454;
border-radius: 3px 3px 3px 3px;
}
#avatar_playing {
background: linear-gradient(to bottom, #9BC861 5%, #789E4C 95%) repeat scroll 0 0 transparent;
filter: none;
height: 50px;
width: 50px;
padding: 3px;
border: 1px solid #545454;
border-radius: 3px 3px 3px 3px;
}
#menu {position: absolute; margin-left:550px; top:88px; color:#fff; text-align:center; margin-top:0px;}
#menu ul{ width:800px; margin:0 auto;list-style:none; padding:0; text-align:left;}
#menu ul li{display:inline}
#menu ul a { float:left; font-weight:bold; font-size:13px; text-decoration:none; color:#fff; padding:8px 10px; width:118px; text-align:center; text-transform:uppercase; background:url(assets/menu_active.gif) no-repeat bottom center; color:#232323; }
#menu ul a:hover {
color: #85B0DF;
cursor: pointer;
text-decoration: none;
}
As always, help is greatly appreciated.
Make sure your CSS and HTML are valid. As others have pointed out, there is no such thing as float:mid-left. Also, if your jsfiddle is indicative of your HTML, you're probably throwing browsers into quirksmode, because your HTML isn't structured properly (your first three tags need to be wrapped in a <head> tag, everything needs to be wrapped in an <html> tag, and the very first line should be <!DOCTYPE html>). Use the W3C's HTML validator and CSS validator to ensure your code is correct. Only then can you begin to fix other issues.
Learn what the various CSS declarations do. While your CSS may be valid, it doesn't mean it's right. This: #avatar { display:inline-block; position:absolute; margin-top:28px; float:mid-right; padding-left: 505px; padding-bottom: 15px; vertical-align:middle; } will technically validate once the float part is fixed. However, position: absolute and float are mutually exclusive -- float doesn't work when position is absolute or fixed. It will also help to learn how padding and margin affect the positioning of the element, and how they differ from one another. Finally, vertical-align doesn't work at all unless the element is a table cell, or display is set to table-cell (and the table-related set of display properties has its own quirks, so you can't necessarily just throw display: table-cell on an element and expect it to work a certain way).
Learn how elements naturally behave, so that you can work with them, instead of against them. Make sure you know how block, inline, and inline-block elements behave, and then work with them to get the layout you want, instead of throwing display: inline-block on everything and hoping for the best. The same goes for things like links (which will naturally have cursor: pointer on hover, unless you've disabled it elsewhere). Doing this will substantially clean up your CSS, making it easier to maintain. It may also clean up your HTML, as you find out what wrapper elements you truly need or can do without.
It's a little difficult to tell what the intended result should be at smaller or "mobile" widths, even with the screenshots that you included above.
It looks like there are a number of issues with your HTML, too. Be careful with things like the <font> tag (it's deprecated as of HTML4).
That said, fixing things in your CSS such as float: mid-right and float: mid-left, which are both invalid, should help a bit. Additionally, you might want to investigate CSS positioning - specifically, you'll likely want to use position: relative on your #header div.
Take a look at this slightly cleaned up version of your example - with background colors added to see where the header ends and what space the navigation occupies.
It looks like you have multiple issues but it is hard to tell without seeing your HTML as well. For starters, #menu { margin-left:550px; } is going to be part of the problem if you are trying to align on the left edge.. You should also know that float:mid-right; is not valid CSS. Check out http://www.w3schools.com/cssref/pr_class_float.asp for more information on float.
EDIT AFTER JSFIDDLE
Put your <div id='header'> inside of your <div id='main'> and change your #menu css to be:
`
#menu { margin: 0px auto; top:88px; color:#fff; text-align:center; width:800px;}
#menu ul{list-style:none; padding:0; text-align:left;}
`
Since you already have a width defined on your menu, you can use margin: 0 auto; to keep it centered based on window size. This will allow you to remove your margin-left and keep it from being pushed to the right.

How would you use HTML/CSS to order a list "backwards" so the list fills from right-left, bottom up?

Say you specify some div with height 500px. In this div, you have a list - maybe ol or ul - and instead of filling it up left-right, top-bottom (this can be done with display:inline-block on the li element), you want to fill it up right to left, bottom to top.
I think right to left can be done with something like float:right in the li element, but I wonder about going bottom to top?
Example result (elem1 is filled before elem2, etc.):
-----------------------------------
[elem10][elem9][elem8][elem7][elem6]
[elem5][elem4][elem3][elem2][elem1]
-----------------------------------
(So it's kind of like putting blocks on top of each other and sliding to the right.)
I hope I'm overthinking and there's actually an easy way to do this.
Thoughts appreciated.
PS. I've seen ol's new 'reversed' attribute in HTML5 and even if that helps I would prefer avoiding something that has very little browser support right now.
Only supported by WebKit, but -webkit-writing-mode: horizontal-bt; seems to work:
http://jsfiddle.net/zzXhp/
There may be other prefixed properties for it. Obviously it's not very well supported though.
Just rotate the list and then counter-rotate the li's
the HTML is
<ul class="container">
<li class="inner">one</li>
....
</ul>
the CSS is
.container {
left: 46px;
top: 100px;
width: 400px;
height: 400px;
position: absolute;
border: 1px solid black;
background-color: lemonchiffon;
}
.inner {
background-color: lightsalmon;
font-size: 20px;
margin: 20px;
width: 80px;
float: left;
}
.container:hover,
.container:hover li {
-webkit-transform: rotate(180deg);
-webkit-transition: all 3s;
}
In the DEMO I have done the effect in the hover, just to make it prettier. the real code would be without transitions :-)
To show something from right to left (usually pages in Arabic), you should use the dir tag.
dir="rtl" : RIGHT to LEFT
<ul id="myList" dir="rtl">
<li>1st</li>
<li>2nd</li>
<li>3rd</li>
</ul>
Here's a JSFIDDLE
A Simple JavaScript to do the whole work, no rtl required.
var list = document.getElementById("myList");
var i = list.childNodes.length;
while (i--)
list.appendChild(list.childNodes[i]);
Here's a JSFIDDLE
I made a shorter, unformatted version of #vals answer, credit goes to him.
The HTML:
<ul class="reverse">
<li>one</li>
...
</ul>
The CSS:
.reverse {
position: absolute;
list-style: none;
}
.reverse li {
margin: 5px;
float: left;
}
.reverse,
.reverse li {
-webkit-transform: rotate(180deg);
}
JSFIDDLE
Here's a solution for filling up from bottom to top and aligned right:
#mylist {
position:absolute;
top:58px;
right:4%;
height:40px;// height of max rows you might need - this allows two rows for me
line-height:1;
font-size:14px;
margin:0;
border: 1px dashed #38e800;
}
#mylist ul {
position:absolute;
bottom:0;
right:0;
overflow: hidden;
vertical-align:bottom;
list-style: none;
text-align:right;
margin:0 0 2px 0;
}
#mylist li {
display:inline-block;
padding:0 0 0 18px;
}
Use the below CSS for reversing from bottom to up:
ul {
display: flex;
flex-direction: column-reverse;
}
or use the below CSS for reversing from right to left:
ul {
display: flex;
flex-direction: row-reverse;
}

CSS Overridden: Why Doesn't Search Box Float right?

I'm at a total loss on why I can't align the Search box to the left
The Search and RSS feed align on the test page:
http://scottjaxon.com/devsite/testnivo48.html
As it is on the home page (with a pic instead of nivo slider)
http://scottjaxon.com/devsite/index.html
I don't get it. I gotta be missing the smallest thing!
#wrapper #user1 #feahome #searchhome {
float: right;
color: #FFFFFF;
height: 22px;
margin-top: 8px;
padding: 0px 20px 0px 20px;
Or is it something with the NivoSlider CSS?
.nivoSlider {
position:relative;
width:100%;
height:auto;
overflow: hidden;
}
.nivoSlider img {
position:absolute;
top:0px;
left:0px;
}
.nivo-main-image {
display: block !important;
position: relative !important;
width: 100% !important;
}
Your index.html and testnivo48.html have different dom structures.
In index.html, the feahome div tag is the parent of rsshome and searchhome div tags; but in the testnivo48.html, they are all on the same level.
That's why the following css rule (in http://scottjaxon.com/devsite/css/style.css) gets applied on index.html, but ignored in testnivo48.html
#wrapper #user1 #feahome #searchhome {
...
}
After you fix the html, your problem might get solved.
I was looking at the CSS for both and the only thing I saw that was different in your
CSS compared to the CSS for http://scottjaxon.com/devsite/index.html is this:
#wrapper #user1 #feahome #searchhome {
float: LEFT; // the working version has it floated left as well
color: #FFFFFF;
height: 22px;
margin-top: 8px;
padding: 0px 20px 0px 20px;
Give it a shot and see if that works.
It may be a prioritizing problem. Using div#searchhome will give it a higher priority.