I am trying to setup a form such that:
All inputs will be horizontally aligned, even when they have no label.
Inputs will be vertically aligned within their row for when the label wraps.
The inputs will stretch to fill the remaining space (or squished)
The submit button will fill an entire row.
I have achieved the first and fourth requirements but I am having trouble with making the inputs fill the row and be vertically aligned.
Here's my progress so far:
http://jsbin.com/kozozabo/3/edit?html,css,output
The LESS:
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
#narrow-form {
width: 300px;
overflow: hidden;
padding-right: 0.5em;
}
#wide-form {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
margin-left: 300px;
}
.row {
#label-width: 100px;
width: 100%;
overflow: hidden;
label {
width: #label-width;
float: left;
display: inline-block;
}
.no-label {
margin-left: #label-width;
}
input, select {
/* Trying to make these aligned to the right of
* their respective labels filling any remaining
* width.
*/
display: inline-block;
}
button {
width: 100%;
}
}
I tried giving the inputs absolute positioning with a left margin of the same width of the label but that didn't work.
Okay I have come up with a solution that I am happy with. It does involve some table abuse unfortunately.
I have only tested this in Chromium.
http://jsbin.com/kozozabo/5/edit?output
I set the form to display: table, each .row to display: table-row and the labels, inputs, selects and buttons to display: table-cell.
This made everything line up and fill all available space.
I then added two new classes intended to be affixes to the .row class, this is where the real table abuse begins.
.no-label - With the intent of "skipping" the first psuedo-cell. To accomplish this I defined it as such:
.no-label:before {
content: "";
display: table-cell;
}
Essentially inserting a hidden cell, forcing the subsequent inputs to be in the second column.
.full-width - With the intent of making it's contents the full width of the "table". To accomplish this I defined it as such:
.full-width {
display: table-caption;
caption-side: bottom;
}
A table caption spans the entire width of the table. I know I am only going to do this to the button so I forced it to be at the bottom with caption-side.
It would have been better to just define the DOM as a table but I didn't want to reprogram the javascript that was setting up this form. I always wouldn't get to of played with css, all be it in a menacing manner.
Related
I need to align some buttons no matter how the content of previous elements changes. This is the markup that I currently have.
I currently have the buttons at the bottom not aligned as shown in the following image:
Notice that the buttons REQUEST DEMO are not properly aligned, so what I want is no matter the content in the previous p element is, they are aligned as shown in the following image:
Notice that here I used the same text to make it look aligned, but I want the buttons to be aligned no matter what the content of the text is.
I also need this functionality to be responsive since I am using bootstrap and for smaller screens, it shows two elements or one element per line.
I was thinking to add a min-height or max-height in the CSS, but this hasn't solved my problem.
Add this to your code and see if this is what you are looking for.
Documentation for flexbox
.row {
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
overflow: hidden;
}
.col-md-6 {
flex: 1;
margin-right: 10px;
padding: 50px;
}
.btn {
position: absolute;
left: 50%;
bottom: 0;
transform: translateX(-50%);
}
There's a few ways to do this. The easiest way would be using flexbox, here's a snippet example https://codepen.io/imohkay/pen/gpard
.parent {
display: flex;
justify-content: space-between;
}
Another way you could do it is having a fixed height for every column, and absolute position the button to the bottom and maybe add some padding to the content so the text never overlaps the button.
Add this class .btn-boxto the buttons and and this class .padbot to the box
CSS
.btn-box{
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%)
}
.padbot{
padding-bottom: 80px; // Adjust as your needs
}
DEMO HERE
Look at my html + css code: http://jsfiddle.net/nP39E/1/
I'll explain if don't understand what I want to achieve:
I want a page with a div which floating right and takes 250px width and a div that takes width of the rest of the document.
In the left div, you can see that I have some other floating elements, and their heights are effected from the right div. You can see the first (red) row with height that align with the right bar's height and has nothing to do with the real content of its content.
I use group class in order to handle the common floating problem: .group:after { content: ""; display: table; clear: both; }
Can you tell me why it happens?
I just changed CSS for the content div from the last answer:
.content {
background: #888;
padding: 10px;
position: absolute;
right: 270px;
left: 0;
}
http://jsfiddle.net/nP39E/4/
What you think?
display: table isn't meant to be used for layouts like this, it's more useful for specific equal-height situations.
Properly floating the divs and not using the margin-right to push the left div will work:
.content {
background: #888;
padding: 10px;
float: left;
width: 250px;
}
Fiddle
You are giving margin-right:270px which is wider than the available space,So just remove that. Also you should make content float:left.
.content {
background: #888;
padding: 10px;
float:left;
}
JSFiddle : http://jsfiddle.net/ankur1990/nP39E/3/
I am using CSS tables to setup a basic grid for a page. The center cell of each row will contain content whereas the first and third "columns" will just be a background color.
The problem I am having has to do with table-cell height. Here is a jsfiddle showing the issue: http://jsfiddle.net/UQUA9/
/*** The essential CSS for the layout ***/
html, body {
height: 100%;
margin: 0pt;
}
.Frame {
display: table;
width: 100%;
}
html>/**/body .Frame {
height: 100%;
}
.Row {
display: table-row;
height: 1px;
overflow: hidden; /* commenting this out has no effect. */
}
html>body .Row.Expand {
height: auto; /* commenting this out has no effect. */
}
.Row div {
display: table-cell;
}
Note that in the HeaderRow, the ContentColumn has a large gap beneath the end of the text between it and the MenuRow. I don't understand why the table-cell is padding it out like that. As far as I can see, I don't have any padding or margin set that would account for this empty space. I went with CSS table specifically because it will autofit cell height to content and now it isn't working!
Here's a screen shot to illustrate. The extra grey is the problem. The cell should end on the line after the text but there is a bunch of empty grey. The pink MenuRow should be displayed right after the text in the HeaderRow.
I know I am missing something simple or obvious. Any hints are appreciated.
I am trying to achieve a layout in which input fields appear in a column. When the column exceeds the height of its container, it must wrap horizontally.
I have achieved this layout using flexbox, but flexbox (and more specifically the flex-wrap property) isn't widely enough supported. In my case, I need to support modern web browsers and at least IE9+
Additionally, the form content is generated by Ember.js along the lines of this method. The model that is bound to the form changes, which means the number of input fields is dynamic.
How can I achieve this layout more compatibly?
Just updated your Fiddle a little: http://jsfiddle.net/43k5s/6/
.menu-form {
background-color: lightgray;
padding: 1em 1.5em;
}
.menu-form:before, .menu-form:after {
content: "\0020";
display: block;
height: 0;
visibility: hidden;
}
.menu-form:after {
clear: both;
}
.menu-form {
zoom: 1;
}
.menu-form div {
width: 33%;
float: left;
}
.menu-form div label {
display: block;
}
Using floats and clearfix this should work in all major browsers (even older IE). You might also work with fixed widths or media queries to change the number of columns.
I'm trying to create an unordered list spanning over multiple rows that is always centered and where I can set which child breaks into a second row, for example -
link | link | link | link
link | link | link | link | link
(where I set the list to clear for a second row on the fifth child element)
Going for an inline display solution to center the elements, I couldn't find a way of clearing them so I switched back to having a float based list. While this easily handles clearing, I find it difficult to center multiple rows -
.container {
width: 100%;
overflow: hidden;
}
ul {
list-style: none;
position: relative;
float: left;
display: block;
left: 50%;
}
li {
position: relative;
float: left;
display: block;
right: 50%;
}
li:nth-child(5) {
clear: left;
}
With this style, the list loses center alignment as soon as a second row is made.
Ideas?
Solved using inline approach and nth-child / after pseudo attributes - http://jsfiddle.net/2LULR/
To center multiple floats rows you have to center them manually. So I think the best solution is using display: inline and center them by setting the parent element to have a text-align: center.
And to clear or make a new row, I would do something like this:
li:nth-child(5):after {
content: "";
display: block;
}