Responsive table-like design - html

In a form four properties have to be set by the user. I chose a table like layout:
This layout, however, makes problems on smaller screens. In this case, I would like to have:
and on very small screens:
Any idea? I am using HTML5, CSS3, jQuery 3.3.1 and bootstrap 2.

If I understand it right, you intend use table to make your form stay in a good layout.
it's not recommended this way because you can't rearrange the cell in a table freely. Or should I say, don't use table to make a responsive layout.
Bootstrap grid system is responsive by default so you should make use of it.
https://www.w3schools.com/bootstrap/bootstrap_grid_system.asp
In your case, you can put your element in four div tag like this
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-6 col-lg-3">
<!-- your first element -->
</div>
<div class="col-xs-12 col-sm-6 col-lg-3">
<!-- your second element -->
</div>
<div class="col-xs-12 col-sm-6 col-lg-3">
<!-- your third element -->
</div>
<div class="col-xs-12 col-sm-6 col-lg-3">
<!-- your fourth element -->
</div>
</div>
</div>

I solved my problem with flexbox:
Here my CSS:
.flex-container {
display: flex;
flex-wrap: wrap;
align-items: center;
}
.flex-container > div {
margin: 1px;
}
.flex-container > .label {
padding-left: 8px;
width: 20%;
min-width: 100px;
}
.flex-container > .value {
vertical-align: middle;
}
.line-break {
width: 100%;
}
.cond-line-break {
width: 100%;
display: none;
}
#media screen and (max-width: 720px) {
.cond-line-break {
display: inline;
}
}
#media screen and (max-width: 360px) {
.cond-line-break {
display: inline;
}
.flex-container > .label {
width: 100%;
}
}
and my HTML:
<div class="flex-container">
<div class="label">Property 1:</div>
<div class="value">
<select>
<option selected="selected">Value 1</option>
<option>Value 2</option>
<option>Value 3</option>
<option>Value 4</option>
</select>
</div>
<div class="cond-line-break"></div>
<div class="label">Enter Property 2 here:</div>
<div class="value">
<select>
<option>Value 1</option>
<option selected="selected">Value 2</option>
<option>Value 3</option>
<option>Value 4</option>
</select>
</div>
<div class="line-break"></div>
<div class="label">Property 3:</div>
<div class="value">
<select>
<option>Value 1</option>
<option>Value 2</option>
<option selected="selected">Value 3</option>
<option>Value 4</option>
</select>
</div>
<div class="cond-line-break"></div>
<div class="label">Property 4:</div>
<div class="value">
<select>
<option>Value 1</option>
<option>Value 2</option>
<option>Value 3</option>
<option selected="selected">Value 4</option>
</select>
</div>
</div>
It works as intended, even with labels of different length.

Related

Bootstrap columns acting oddly

So I'm creating an exercise for schools so a teacher can fill in a form which makes an exercise for their students. Now I'm trying to use a bootstrap columns to make things look better and more understandable where I'm going for this format:
SELECT1 - QUESTION
SELECT2
Now I thought I could achieve this by giving SELECT1 a col-md-3, QUESTION a col-md-7 and SELECT2 a col-md-10 which also gives them appropriate lengths for what they show. Now for some reason this stacks them vertically while giving them the appropiate length for their given cols. To make it even weirder if I shorten SELECT2 to for example col-md-3 like SELECT1 it will put QUESTION and SELECT2 on the same line. I tried putting them in a form with the class form-inline but that somehow made it like this:
QUESTION - SELECT1
SELECT2
which makes even less sense to me. I should note this is all inside a row which is inside a class with the styling for 10px padding left and right which is inside a panel panel-body which is inside a container.
Here is the relevant HTML code at the point where they're all just stacked vertically:
<span id="spanid">
<div class="form-group input-group col-md-3">
<select class="form-control">
<option disabled="" selected="">Choose</option>
<option>Option 1</option>
<option>Option 2</option>
</select>
</div>
<div class="well well-sm col-md-7">
<h5 id="eQuestion">A question</h5>
</div>
<div class="form-group input-group col-md-10">
<select class="form-control">
<option disabled="" selected="">Choose the correct answer</option>
<option>Option 1</option>
<option>Option 2</option>
</span>
TL;DR: To get to the point as suggested how do I fix my code to get my page to look like this:
SELECT1 - QUESTION
SELECT2
EDIT for new code:
<span id="vqaspan" class="row">
<div class="form-group col-md-3">
<select class="form-control">
<option disabled="" selected="">Choose</option>
</select>
</div>
<div class="well well-sm col-md-7">
<h5 id="eQuestion">Question</h5>
</div><div class="form-group col-md-10">
<select class="form-control">
<option disabled="" selected="">Choose</option>
</span>
This gives me:
SELECT2
SELECT1 - QUESTION
I don't understand why SELECT2 is now being placed above the rest
All the element are coming in stack due to properties of class input-group. You can remove that to make it works as per your design requirement.
<span id="spanid">
<div class="form-group col-md-3">
<select class="form-control">
<option disabled="" selected="">Choose</option>
<option>Option 1</option>
<option>Option 2</option>
</select>
</div>
<div class="well well-sm col-md-7">
<h5 id="eQuestion">A question</h5>
</div>
<div class="form-group col-md-10">
<select class="form-control">
<option disabled="" selected="">Choose the correct answer</option>
<option>Option 1</option>
<option>Option 2</option>
</select>
</div>
</span>
Since you are using col-md-3 column grid will works only at or above medium level devices
As per your modification in code.This works well at my end.
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css">
<span id="vqaspan" class="row">
<div class="form-group col-md-3">
<select class="form-control">
<option disabled="" selected="">Choose1</option>
</select>
</div>
<div class="well well-sm col-md-7">
<h5 id="eQuestion">Question</h5>
</div>
<div class="form-group col-md-10">
<select class="form-control">
<option disabled="" selected="">Choose2</option>
</select>
</div>
</span>
It is giving unexpected behavior cause you might have missed to close select and div at the end.
I know that you are asking about bootstrap here specifically, but if I may indulge in a little "you should use this instead", how about just using pure HTML capabilities (flexbox)? This type of scenario is what it's for (indeed, bootstrap 4 is now built with flexbox), and as you can see it's actually much simpler than bootstrap's infuriatingly hard to get right and darn near unreadable "col-md-x" css approach.
In this example, pared down for readability, we put flex-grow:2 on the select in the first row and flex-grow:1 on the h5, which achieves, more or less, the 2/3 and 1/3 ratios that you appear to want:
.row {
display: flex;
align-items: center;
}
#row1 select {
flex-grow: 2;
}
#row1 h5 {
flex-grow: 1;
}
#row2 select {
flex-grow: 1;
}
<div class="row" id="row1">
<select>
<option>Choose</option>
<option>Option 1</option>
<option>Option 2</option>
</select>
<h5>A question</h5>
</div>
<div class="row" id="row2">
<select>
<option>Choose the correct answer</option>
<option>Option 1</option>
<option>Option 2</option>
</select>
</div>

The div wrapped multi select drop down not working in IE

I am trying to build a UI add-remove items component using two multi-select drop downs. fiddle here.
div {
float: left;
border: 1px solid #ccc;
padding: 10px;
margin-bottom: 30px;
background-color: #e4eaec;
}
div select {
width: 100%;
height: 400px;
overflow: scroll;
background-color: #fff;
}
div h4 {
text-align: center;
}
div.section-two-arrows {
border: none;
padding-top: 150px;
background-color: #fff;
text-align: center;
.fa {
font-size: 2.8em;
display: block;
padding-bottom: 5px;
}
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="add-remove-items-component">
<div class="col-xs-5 col-sm-5 col-md-5 col-lg-5 section-one">
<h4>Available Functions</h4>
<select id="avail-functions" class="select-box-style" name="availFunc" multiple>
<option>Value 1</option>
<option>Value 2</option>
<option>Value 3</option>
</select>
</div>
<div class="col-xs-1 col-sm-1 col-md-1 col-lg-1 section-two-arrows">
<span class="fa fa-angle-double-right" title="Add All items from Left to Right"></span>
<span class="fa fa-angle-right" title="Add selected items from Left to Right"></span>
<span class="fa fa-angle-left" title="Add All items from Right to Left"></span>
<span class="fa fa-angle-double-left" title="Add selected items from Right to Left"></span>
</div>
<div class="col-xs-5 col-sm-5 col-md-5 col-lg-5 section-three">
<h4>Selected Functions</h4>
<select id="sel-functions" class="select-box-style" name="selFunc" multiple>
<option>Value 1</option>
<option>Value 2</option>
<option>Value 3</option>
</select>
</div>
</div>
This component works well in chrome, but not in IE.
The problem with IE is that the first select box does not work, but the second one works just fine.
If I remove the div wrapped to the select box, it works fine. But I cannot make it responsive and the alignment of the page will be disturbed.

div is not responding to display:block;

I have this set up where I'm switching the display to be responsive, I have two set of nav menus one is displayed and the other is hidden on page load, once the screen is 480px or below the main site nav menu acts as expected and is hidden, but the mobile nav wont show up.
here is my code below and thanks in advance.
#media screen and (max-width: 480px) {
.mn-nav {
display: block;
}
.main-site-nav {
display: none;
}
}
<div class="container">
<div class="mn-nav" style="display:none;">
<div class="col-md-12">
<select width="100%" name="m-nav">
<option value="select">Profile Menu</option>
<option value="social">Social</option>
<option value="profile">My Profile</option>
<option value="media">My Media</option>
</select>
</div>
</div>
<div class="main-site-nav">
<div class="col-md-3">
<button id="social-button" style="width:100%;" class="btn btn-primary">Social</button>
</div>
<div class="col-md-3">
<button id="profile-button" style="width:100%;" class="btn btn-primary">My Profile</button>
</div>
<div class="col-md-3">
<button id="media-button" style="width:100%;" class="btn btn-primary">My Media</button>
</div>
<div class="col-md-3">
<a href="/logout">
<button style="width:100%;" class="btn btn-danger">Logout</button>
</a>
</div>
</div>
</div>
The style is applied, but your inline display style takes precedence over the one in the style sheet, making it redundant. Remove the inline style and add it in the stylesheet before your media query:
HTML
<div class="mn-nav" style=""><!-- Inline style removed -->
<div class="col-md-12">
<select width="100%" name="m-nav">
<option value="select">Profile Menu</option>
<option value="social">Social</option>
<option value="profile">My Profile</option>
<option value="media">My Media</option>
</select>
</div>
</div>
CSS
.mn-nav{
display: none;
}
#media screen and (max-width:480px) {
.mn-nav {
display:block;
}
.main-site-nav {
display:none;
}
}
Bootply
This happens because you set display: none; as inline style.
html:
<div class="mn-nav">
<div class="col-md-12">
<select width="100%" name="m-nav">
<option value="select">Profile Menu</option>
<option value="social">Social</option>
<option value="profile">My Profile</option>
<option value="media">My Media</option>
</select>
</div>
</div>
css:
.mn-nav {
display: none;
}
#media screen and (max-width:480px) {
.mn-nav {
display: block;
}
.main-site-nav {
display: none;
}
}
Your inline style has priority over the styles you set in your css file. Therefore display: block is not being applied.
The problem is that in <div class="mn-nav" style="display:none;">, the style has a higher priority than a style in a CSS style sheet.
Move it to
.mn-nav{
display:none;
}
and you are good.
Reference: CSS which takes precedence, inlne or the class?

Align divs to right with vertical align middle

Here's my code:
<div class="row">
<div class="col-md-12 table">
<div class="middle">Title XPTO</div>
<div class="middle">Display:</div>
<select class="form-control">
<option label="10" selected="selected" value="10">10</option>
<option label="25" value="25">25</option>
<option label="50" value="50">50</option>
</select>
</div>
</div>
CSS:
.table {
display: table !important;
}
.middle {
display: table-cell !important;
vertical-align: middle;
}
DEMO: https://jsfiddle.net/jkf2L49e/
I want to put the text "Display:" nearest to the select element. And the select must be right (position) as possible. What is the best way to do this and make it responsive?
You should also make the <select> part of the table layout too, so just wrap it with another <div>. The markup would be like this:
<div class="col-md-12 table">
<div class="left">Title XPTO</div>
<div class="middle">Display:</div>
<div class="right">
<select class="form-control">
<option label="10" selected="selected" value="10">10</option>
<option label="25" value="25">25</option>
<option label="50" value="50">50</option>
</select>
</div>
</div>
To align the text to the right, you can simply use text-align:right in the middle cell. The CSS would be like this (with tweaks that asked in the comments below).
.table {
display: table;
}
.table > div {
display: table-cell;
vertical-align: middle;
white-space: nowrap;
}
.table .middle {
text-align: right;
width: 100%;
}
.table select {
width: auto;
}
Updated demo - https://jsfiddle.net/jkf2L49e/4/
Try this complete code:
.table {
display: table !important;
}
.middle {
display: table-cell !important;
vertical-align: middle;
}
.text-right{
text-align:right;
}
Now add this class to the div that contains the text "Display"
<div class="row">
<div class="col-md-12 table">
<div class="middle">Title XPTO</div>
<div class="middle text-right">Display:</div>
<select class="form-control">
<option label="10" selected="selected" value="10">10</option>
<option label="25" value="25">25</option>
<option label="50" value="50">50</option>
</select>
</div>
Try following complete code. It would be best solutions.
<html>
.wrapper
{
width:100%;
}
.leftdiv{
width: 90%;
float:left;
}
.rightdiv{
width:8%;
float:right;
}
Title XPTO
<div class="rightdiv">Display:
<select>
<option label="10" selected="selected" value="10">10</option>
<option label="25" value="25">25</option>
<option label="50" value="50">50</option>
</select>
</div>
</div>
Mark answer as right answer if helpful to you.

Bootstrap 3: how to create an inline form with selects and labels?

My labels keep appearing above the selects. I want them all on the same line. Pls see the jsfiddle: http://jsfiddle.net/jjgelinas77/9nL9x/
<div class="well well-sm">
<form name="myForm" role="form" novalidate="novalidate" class="form-inline">
<div class="form-group">
<label>C-Band</label>
<select id="cband" class="form-control">
<option value="C15+">C15+</option>
<option value="C12-14">C12-14</option>
<option value="Other">Other</option>
</select>
</div>
<div class="form-group">
<label>C-Band</label>
<select ng-model="form.cband2" id="cband2" class="form-control">
<option value="C15+">C15+</option>
<option value="C12-14">C12-14</option>
<option value="Other">Other</option>
</select>
</div>
<button class="btn btn-primary">Filter</button>
</form>
</div>
There's a CSS rule in bootstrap that sets the width of .form-control to 100% on small screen sizes. So even when it's floated, it will take the whole width and therefore start on a new line. Good news is you only need a couple lines of CSS to override it:
.form-control {
width:auto;
display:inline-block;
}
Hope this simplifies the problem for anyone still facing the issue! http://jsfiddle.net/c3m77ah6/2/
You have to wrap your label around the select. Like this:
<div class="form-group">
<label>C-Band
<select id="cband" class="form-control">
<option value="C15+">C15+</option>
<option value="C12-14">C12-14</option>
<option value="Other">Other</option>
</select>
</label>
</div>
And then add the following CSS:
.form-group label {
float: left;
text-align: left;
font-weight: normal;
}
.form-group select {
display: inline-block;
width: auto;
vertical-align: middle;
}
Here is your updated fiddle: Updated Fiddle
form-inline class with form-group will do the job like
<div class="form-group form-inline">
<label for="sel1">My InlineSelect: </label>
<select class="form-control" id="rotit">
<option value="1">Value 1</option>
<option value="2">Value 2</option>
<option value="3">Value 3</option>
</select>
</div>
demo : http://jsfiddle.net/9arahevn/2/
This problem is so recorrent that there is a Github project solving it
https://fk.github.io/select2-bootstrap-css/
Place their CSS file right after the CSS from Select2
<link rel="stylesheet" href="css/select2.min.css">
<link rel="stylesheet" href="css/select2-bootstrap.css">
Then you can use the label along with the select
<div class="form-group">
<label for="sName">Select Title</label>
<select class="js-example-basic-single form-control" id="sName">
</select>
</div>
It does work if you use the latest bootstrap:
#import url('http://netdna.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css');
And please DON'T FORGET to make the column with result more than 768px. Form-inline works only if screen with more than 768px. (Just drag the column with a mouse a bit)
The issue was with css for
#media (min-width: 768px)
.form-inline .form-control {
//old bootstrap
display: inline-block;
// new bootstrap
display: inline-block;
width: auto;
vertical-align: middle;
}