ResposiveNess of div with multiple content - html

I am using Bootstrap 4. My HTML code is like below.
<div class="font-weight-bold col-12">
<span>Filter :</span>
<input type="text" class="form-control" />
</div>
Before decrease the browser size my output is like below
After decrease the browser size my output is like below
How can I keep both elements in the same line after I decrease the browser size?

Try like that:
<div class="font-weight-bold col-lg-12 col-md-12 col-sm-12"> // use fullwidth for large, medium and small devices
<span>Filter :</span>
<input type="text" class="form-control" />
</div>
You can read more about bootstrap grid system here.

You can do a few things here:
1) get rid of the "form-control", add a class of your own and set its width using CSS
HTML
<input type="text" class="my-input" />
CSS
.my-input {
width: 100px; // or the width you desire
}
2) Overwrite the CSS of the element inside the media query.
Somewhere in bootstrap CSS you have a selector (of "form-control") inside a media query which gives the input a smaller width. You can create your own media query and selector and overwrite it.
3) Sort of a combination of both. You can just add a class to the input
<input type="text" class="form-control my-input" />
and then add CSS according to the screen width.
It might not be that elegant - but you can also use !important on the width and then it won't be overwritten when the screen size changes.
Like:
.my-input {
width: 100px !important; //again - not elegant, but will do the work
}

Write the CSS for input as:
input {
width: calc(100% - 55px)
}
HTML
<div class="font-weight-bold">
<span>Filter :</span>
<input type="text" class="form-control" />
</div>
55px is the width allotted for the label. The input will adjust itself as per the screen and the label width without using any bootstrap also.

Related

Change the height of form input box

I would like to adjust the height of the form input box and make the text almost touch the top and the bottom borders of the box. I tried adding some css, but had no luck. I'm looking for a bootstrap css solution.
.form-group {
height: 10px;
width: 30%;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<div class="form-group">
<label for="input">First Name</label>
<input class="form-control" type="text" name="input" placeholder="Enter text">
</div>
In other words (or pictures), I want to change this
to this:
Using Bootstrap only, your best bet would be:
Bootstrap v3
https://getbootstrap.com/docs/3.4/css/#forms-control-sizes
Bootstrap v4
https://getbootstrap.com/docs/4.5/components/forms/#sizing
From there you can adjust the padding manually to reduce the gap between the top/bottom of the letters with the border of the input box.
Bootstrap v4: https://getbootstrap.com/docs/4.5/utilities/spacing/
Bootstrap v3: You'll have to use CSS padding on the <input> element to adjust.
I'd use the recommended bootstrap solution and override $input-height variable in my custom.scss,
like so:
$input-height: 1rem;
(overriding bootstrap variables: https://getbootstrap.com/docs/4.0/getting-started/theming/)

Can CSS over-rule HTML input size declarations

I have inherited a website that has many inputs on various pages, such as:
<input name="name" type="text" id="name" size="40" maxlength="64">
and
<textarea name="descr" cols="40" rows="2" id="descr">
I have been improving the CSS of the site to make it flexible layout for mobile devices, etc. But the size/cols rules of the HTML persists in setting the fixed size, regardless of outside factors.
I have tried using CSS such as:
CSS:
input, textarea, select {
max-width:100%;
}
(And with also appending !important) but this doesn't effect the elements.
It's been converted into an HTML5 template, and the inputs are in a table (but the table is flexible and is not the issue).
Is there a way that CSS can overwrite the HTML size/cols declaration in the inputs?
The large number of inputs over multiple pages wanted me to find a CSS simple way of overwriting them all in one fell swoop. As far as I can see this doesn't seem directly possible and I will have to go through and edit the size values for each input elements :-/.
EDIT
Full Code:
HTML:
<table id='centralTable'>
<tr>
<td colspan="2">Update Category</td>
</tr>
<tr>
<td width="28%"><strong><label for='name'>Category Name</label></strong></td>
<td width="70%"><input name="name" type="text" id="name" value="catname" size="40" maxlength="40" required></td>
</tr>
<tr>
<td><input name="id" type="hidden" id="id" value="12" >
</td>
<td><input type="submit" value="Update" ></td>
</tr>
</table>
CSS:
#centralTable {
width:90%;
max-width:780px;
min-width:300px;
margin:1rem auto;
}
input, textarea, select {
max-width:100%;
}
If I adjust the sizing of the size value, the other elements on the page fit the screen as intended, but the size value offsets this. Firebug shows that max-width is applied to the element but the element size does not accord to this.
EDIT TWO:
Setting the td element max-width to a px value rather than a percentage works, but obviously doesn't adapt to viewport size.
td {
max-width:200px; /* This works in containing the input size */
}
CSS can override the size attribute using width. There's a good explanation about it here.
Here, we have a typical input, size 10:
<input type="text" size="10">
And here is that same input, adjusted with CSS
input {
width: 20px;
}
<input type="text" size="10">
max-width is also a viable option, depending on the circumstance
div {
width: 20px;
}
input {
max-width: 100%;
}
<div>
<input type="text" size="10">
</div>
OK, I think I've got it:
The table elements are set to take a percentage size but the nature of tables is that they expand to fit their contents, and the contents is set to take a maximum of 100% of the table size, so:
Size sets input elements size:
Table cell expands to encase input element
CSS input sets the input to fill table cell
So; Using a Viewport Width as a value gives a more absolute container for the size to sit into.
#centralTable input, #centralTable textarea, #centralTable select {
max-width:65vw;
}
This limiter, rather than a percentage limiter, then correctly resizes the child input size value.
Viewport width units should be used in preference to percentage sizes.

How to vertically align long label in Bootstrap 3

I have got a long label next to my input and it is not vertically aligned.
Is there some option to solve it like it was in Bootstrap 2, please?
<form class="form-horizontal" role="form">
<div class="form-group">
<label for="input1" class="col-lg-2 control-label">Labdas kjas kljas dlkjasd lksjd el1</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="input1" placeholder="Input1">
</div>
</div>
<div class="form-group">
<label for="input2" class="col-lg-2 control-label">Label2</label>
<div class="col-lg-10">
<input type="password" class="form-control" id="input2" placeholder="Input2">
</div>
</div>
</form>
not very cleanly... you would need to add an override class to the long label, such as multiline and then add a definition for that class like so
.control-label.multiline
{
padding-top:0;
}
Here's another option, that may or may not work based on your implementation.
I've used it to handle some cases where I needed the 'col' classes to take up full height of their rows. Essentially it's telling the browser to interpret it as a table. That should allow you to vertically align the label to the middle.
I put it in a media query because smaller than that it stacks for me.
/* addition for displaying bits as tables to gain cell features */
#media (min-width: 769px) {
.table-display{display:table; margin:0 -15px; width:100%; }
.table-display .row, .table-display .form-group{display:table-row;}
.table-display [class*="col"]{float:none; display:table-cell; vertical-align:middle; padding-left:15px; padding-right:15px;}
}
You would add the table-display class to your form:
<form class="form-horizontal table-display" role="form">
HTH,
-Ted
Edited to add: heres a fiddle- http://jsfiddle.net/eAaa3/
Of course you will need to stretch the frame to unstack it
I had the same problem, and i used a table instead.
and if you implement it with a table, you can also use .table and .table-responsive classes of bootstrap.
This is what I do with mine. I'm actually working with Bootstrap today
.control-label{
float:left;
vertical-align:middle;
}

Show input right after label

I need to show (within a div tag) a label and right next to the label an input. I am using bootstrap css and my code is as follows:
<div class="row">
<div class="span3">
<div class="control-group">
<label class="control-label" for="txtInput">Enter Text:</label>
<div class="controls">
<input id="txtId" class="input-medium" name="txtInput" />
</div>
</div>
</div>
</div>
No matter what I do there is a space between the label ("Enter Text:") and the left margin of Input.
How do I change the HTML or CSS to accomplish this? TIA
To adjust the position of only your input field you should be able to just apply the "position" CSS property of that element. Once you set that "position" property as relative you can move the element's position relative to its initial starting location using top,bottom,left, and right.
In the below example I moved your input field 5 pixels to the left of where it normally would be.
<style>
.controls{
position:relative;
left:-5px;
}
</style>
Try removing any whitespace between the elements. For example:
<label class="control-label" for="txtInput">Enter Text:</label><div class="controls"><input id="txtId" class="input-medium" name="txtInput" /></div>
Then, just remove the margin or padding of the div or input, if you want them to be placed right next to each other. The whitespace between them is rendered, so you'll have to remove it. Another approach I've seen is (but never used) is to put an HTML comment between the elements instead, like this:
<label class="control-label" for="txtInput">Enter Text:</label><!--
--><div class="controls"><!--
--><input id="txtId" class="input-medium" name="txtInput" />
</div>
See if either of those help. I recently ran into this problem where I was getting unexpected whitespace between my labels and inputs, and I couldn't remove it without using negative margin, which I didn't like. The solution I found was to remove the whitespace as in the first example. It doesn't look too pretty in the code, but it works.
Good luck!
You could put a negative margin on input-medium to force it to be closer to the label:
div.controls {
display:inline;
}
.input-medium {
margin-left:-4px;
}

CSS layout to force horizontal scroll for form elements

The Problem
I've got a problem where I'm trying to create rows of form inputs. This works OK, however, once the width of the total inputs gets too large, everything starts to wrap. What I would like is for a horizontal scroll-bar to appear inside the field-set and for all form elements for a single service-item div to remain on a single line.
<div style="display: inline-block;" class="horizontal-fields service-item">
<button class="horizontal-fields remove-service-item" style="float: left; margin-right: 5px;">-</button>
<label for="service_name">Name:</label>
<input name="service_name[]" id="service_name" value="" type="text">
<label for="service_description">Description:</label>
<input id="service_description" name="service_description[]" value="" type="text">
<!-- Additional form fields are dynamically inserted here. -->
<div class="service-additional-fields">
<!-- Additional fields for DSL Tails -->
<label for="service_dsl_fnn[]">FNN:</label>
<input id="service_dsl_fnn" name="service_dsl_fnn[]" size="10" value="" type="text">
<button class="horizontal-fields new-service-item" style="display: inline-block;">+</button>
</div>
<br>
</div>
Current Results
Here is a JSFiddle showing the form in it's current state, I've included all the bare-bones CSS/HTML that I think are relevant: http://jsfiddle.net/FjxqG/3/
You will see that I've managed to get what I want by specifying width: 300% in the horizontal-fields class. However, this is of course not optimal because the width is essentially fixed and not automatically fitting the width of the service-item div.
Of course, this leaves the width much larger than it needs to be, but also always showing a horizontal-scroll, even when it isn't needed.
What I've tried
I've tried using display: inline-block; and whitespace: no-wrap;. However, the former did not seem to do much for me, and the latter only worked for the first few form items, not those inside the service-additional-fields div.
Unfortunately, I've got those latter items in the service-additional-fields div as they are dynamically inserted using jQuery, so although it's possible to take them out, I'd rather leave them in there, as it keeps the JavaScript simpler.
I've tried adapting the solution found here, with little success: http://www.css-lab.com/demos/image-display/side-scroll-gallery.html
Ended up with a similar situation in which the latter form elements were still wrapping.
I've also considered doing something like the jQuery solution found here: Horizontal scroll in DIV with many small DIV's inside (no text)
I guess this would work for me, because I already know that setting the width on horizontal-fields works OK, so using jQuery to find out what that width should be would probably work. However, it feels like I shouldn't need jQuery and it would be kind of a hack. So I'd like to avoid it if reasonably possible.
Thanks!
For some reason the other answer has been deleted and I can't get it back so having to answer again.
Previous answer was -
How about removing the floats and having inline-blocks with auto widths, And then for the .service-additional-fields as inline-block too?
Edited for a fuller answer.
HTML
<fieldset>
<legend>Fourth: Add Services</legend>
<div id="slide-wrap">
<div id="inner-wrap">
<div class="horizontal-fields service-item">
<button class="addField">+</button>
<label>Text Box:</label>
<input type="text">
<label>Text Box:</label>
<input type="text">
<!-- Additional form fields are dynamically inserted here. -->
<div class="service-additional-fields">
<!-- Additional fields for DSL Tails -->
<label>Text Box:</label>
<input type="text">
<label>Text Box:</label>
<input type="text">
</div>
</div>
<div class="horizontal-fields service-item">
<button class="addField">+</button>
<label>Text Box:</label>
<input type="text">
<label>Text Box:</label>
<input type="text">
<!-- Additional form fields are dynamically inserted here. -->
<div class="service-additional-fields">
<!-- Additional fields for DSL Tails -->
<label>Text Box:</label>
<input type="text">
<label>Text Box:</label>
<input type="text">
<label>Text Box:</label>
<input type="text">
</div>
</div>
</div>
</div>
</fieldset>
CSS
#slide-wrap {
margin:0 auto;
overflow: auto;
background:#BCC5E1;
border:1px solid #000;
}
#inner-wrap {
float:left;
margin-right:-30000px;/*Be safe with Opera's limited negative margin of 32695px (-999em could cause problems with large font sizes)*/
padding-left:20px;
width: auto;
}
div.horizontal-fields input,
div.horizontal-fields textarea,
div.horizontal-fields select,
div.horizontal-fields label {
width: auto;
}
/* Horizontal fields is the class which is not re-sizing it's with correctly */
.horizontal-fields {
display: block;
}
.service-additional-fields {
display:inline-block;
}​
DEMO
http://jsfiddle.net/aLKHJ/1/
Try this approach:
HTML:
<div id="slide-wrap">
<!-- + First row -->
<div class="row">
<!-- All elements here -->
</div>
<!-- - First row -->
<!-- + Second row -->
<div class="row">
<!-- All elements here -->
</div>
<!-- - Second row -->
</div>
CSS:
#slide-wrap {
margin:0 auto;
overflow: auto;
background:#BCC5E1;
border:1px solid #000;
width: 400px; /* for example */
padding-left:20px;
}
div.row {
float:left;
white-space: nowrap;
}
Take it easy, I was really getting confused of inner styles, so I removed them.
JsBin demo