My code (full version):
<div class="modal-body">
<div class="container">
<div class="row">
<div class="col-8 p-0">
<form class="form-group">
<form>
<input type="text" class="form-control w-100 pr-0 mr-0" id="quick-add-task-control-text-area" placeholder="Task name">
</form>
</form>
</div>
<div class="col-4 p-0">
<button type="button" class="btn btn-secondary w-100 h-100 ml-0" id="schedule-button">Schedule</button>
</div>
</div>
</div>
<div class="modal-footer d-flex flex-row justify-content-start pl-0">
<button type="button" class="btn btn-primary btn-sm" id="add-task-modal-save">Save changes</button>
<div class="input-group mb-0 w-50">
<div class="input-group-prepend">
<label class="input-group-text" for="inputGroupSelectPriority">Priority</label>
</div>
<select class="custom-select" id="inputGroupSelectPriority">
<option selected>Choose...</option>
<option value="Low">Low</option>
<option value="Medium">Medium</option>
<option value="High">High</option>
</select>
</div>
</div>
</div>
</div>
</div>
After opening my modal on the navbar ("+" icon), I wanted the height of my input-group to be the same height as my "save changes" button on the left. After inspecting its styles (of the 'save button' I could not understand how it's height was calculated. I did not find any em or rem, or any reference to the parent element like the bootstrap class "h-100". So I had to do it using the height property and pixels, which I know is a terrible way of doing it.
So my question is, how do I set the height of my input-group element in the proper responsive-friendly way?
(For the modal footer I didn't set a container and a row and columns as I did in the modal body, is that terrible?)
The button's height is not explicitly set by Bootstrap, it's automatically calculated from the size of the content plus its margin, padding and border. The custom select's height, however, is explicitly set, so there is not a way to make it smaller without explicitly overriding that, as well as the properties on the label, unfortunately.
The way you're doing it is not really that bad, just indicative of what, in my opinion, is Bootstrap's biggest drawback: that if you need to even moderately customize your styles, you'll end up fighting and overriding its CSS for much longer than you save by making use of its grid system, though some of the components are quite useful. You may just want to use a custom input element you style yourself, that way you can use flexbox to have it size up automatically.
Otherwise if you add h-100 to the select element it should be what you're looking for. Note that if you do shrink the select's height, you will also need to override its padding and/or font size to prevent the text from being cut off.
In projects using Bootstrap, any element with d-flex is a flexbox container, making the immediate child elements flex items.
Flexbox can drastically change the height of items when flex-direction equals row, which is the default. The items will naturally take up the height of the flexbox container.
Applying a fixed height to items might help but in this circumstance it might just be easier to add a wrapper div around elements like <select> and <button> that are being effected in this way by a flexbox container. That way the wrapper you added can have its height changed by the flexbox container, but the <select> inside keeps its natural height.
Awesome resource about how flexbox works.
Related
I have a problem with making my input field good looking and not too big.
The problem is that when I add to input the w-25 class thats width 25% the input width changes according to its original width and not the parent container and it leaves blank space inside the container , I can fix the problem by passing the width in pixels but I am supposed to use only bootstrap and no css styling.Maybe there could be a different approach to making it.
<div class="container my-5">
<h1 class="fw-normal">Fibonacci Calculator</h1>
<div id="calculatorContainer" class="d-flex align-items-center">
<span>The Fibonacci Of</span>
<small>
<input
type="number"
class="mx-2 d-inline-block w-25"
placeholder="#"
/>
<button type="button" class="btn btn-primary">ls</button>
</small>
</div>
</div>
Here is a codepen with the front end
https://codepen.io/amirovalex-the-animator/pen/OJjgbpo
You can use col-md-1 col-12 on the input class.
This works fine, makes the button size 4
<div class="col-xs-4">
<button class="btn btn-block btn-primary">Like</button>
</div>
But the following doesn't work:
<div>
<button class="col-xs-4 btn btn-block btn-primary">Like</button>
</div>
Which doesn't make sense to me, since I thought the div was just a container and its styles/ classes are passed down to its elements.
col-xs-4 sets the current element's width to approximately 33% and btn-block sets the current element's width to 100%.
In this code parent element's width (div) is 33% (because of col-xs-4) and child element's width is 100% (because of btn-block).
<div class="col-xs-4">
<button class="btn btn-block btn-primary">Like</button>
</div>
In the next code, parent div's display is block and its width changes according to what is inside of it. And in child element (Button) it has both col-xs-4 and btn-block classes, but btn-block sets width:100% and disables col-xs-4 (width:33%) effect.
<div>
<button class="col-xs-4 btn btn-block btn-primary">Like</button>
</div>
If you remove btn-block you'll see col-xs-4 just works fine and sets width:33%
<div>
<button class="col-xs-4 btn btn-primary">Like</button>
</div>
I've created a fiddle for you.
In your first example, the div is given class "col-xs-4" and will therefore not change in size depending on what is inside the div.
In your second example, the div is not given any class and will therefore change in size, depending on what is inside the div.
The reason your second example doesn't work is because of your other classes also changes the button size. By reading the "col-xs-4" class first, the size is overruled by one of the other classes.
you can not apply col-xs-* or any with buttons but if you want to adjust the size of your button the refer this ->
https://www.w3schools.com/bootstrap/bootstrap_buttons.asp
I am new to web development, particularly CSS and Bootstrap. I am struggling to center the set of 5 items in a Bootstrap row. Here is what I have:
<div class="container-fluid">
<div class="row text-center" style="border:2px solid green">
<div style="display:inline-block;float:none;vertical-align:top;margin-top:8px">My Label</div>
<div class="col-xs-2 col-sm-2 col-md-1"style="display:inline-block;float:none">
<input class="form-control" type="number"></input>
</div>
<div style="width:2%;display:inline-block;float:none"></div>
<div class="col-xs-2 col-sm-2 col-md-2 col-lg-1"style="display:inline-block;float:none">
<button class="btn btn-default btn-block" role="button">Button1</button>
</div>
<div class="col-xs-3 col-sm-3 col-md-2"style="display:inline-block;float:none">
<input class="form-control" type="number"></input>
</div>
<div style="width:2%;display:inline-block;float:none"></div>
<div class="col-xs-2 col-sm-2 col-md-2 col-lg-1"style="display:inline-block;float:none">
<button class="btn btn-default btn-block" role="button">Button2</button>
</div>
</div>
</div>
For the most part, it gives me the result I want in Firefox and Chrome. The controls are spaced a little and it is responsive -- the white space shrinks while the controls grow (in % of screen) as the screen gets smaller. Control widths are controlled via Bootstrap col-*-# classes. Though, IE seems to align the buttons at the bottom of the row for some reason. I'm not sure why.
Aside from defining custom CSS classes instead of style attributes, is this the correct/best way to achieve the result that I want? Or, is there a better way to do this in CSS or Bootstrap? It seems hackish to have to use vertical-align and margin to get the label to line up. Also, I started out using form elements and classes. But, that kept making things worse. What is the benefit of using the form element or downside to not using it?
I read numerous similar posts. But they all seemed to have something different enough that the solutions seemed to not fit what I am doing. I have a set of controls that I want centered as a unit. I do not want to simply snap them to the 12-column Bootstrap grid.
JSFiddle
You still can use a custom class when you need it :
.classname {
display: inline-block;
vertical-align: middle;
float: none;
}
How do i set width of input in this case in bootstrap 3.0
Here is the example http://jsfiddle.net/6eBFz/
code
<div class="submit">
<div class="col-md-8 col-sm-8">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
<div class="col-md-4 col-sm-4">
<div class="input-group">
<input type="text" class="form-control ">
<span class="input-group-btn">
<button class="btn btn-default" type="button">Add </button>
</span>
</div>
</div>
</div>
i am looking at the bootstrap way and not custom css
Bootstrap inputs take on the width of their container.
From the Bootstrap docs (http://getbootstrap.com/css/#forms-inline)..
"Inputs, selects, and textareas are 100% wide by default in Bootstrap.
To use the inline form, you'll have to set a width on the form
controls used within."
CSS: .set-width{ width: 50%; }
HTML: <div class="input-group set-width">
You can add a set-width method (call it whatever you want) on any div and then manually size it in your CSS. I wouldn't recommend adding style="width: 50%;" to code because it makes it less readable and makes it much harder to edit later on. Plus with making a CSS class you can reuse it on several input fields (or anything else that you want to be set to that width really! Width can be set in pixels, or in em.
Here is a helpful resource to understand CSS classes and ID's
I have a form with an input and a button, styled with bootstrap.
I am using grid colums to give the input and the button their own width.
But it seems to change the input's width, I have to assign the col-* class to the div surrounding the input, whereas the button can receive the class on itself.
This ends up with the input not using the width I was hoping to give it.
<div class="container">
<div class="row">
<form name="search" role="search">
<div class="form-group col-sm-10 col-xs-12">
<input type="text" class="form-control input-lg" placeholder="Hey"/>
</div>
<div class="form-group">
<button class="btn btn-primary btn-lg col-sm-2 col-xs-12" type="submit">
Search
</button>
</div>
</form>
</div>
</div>
Here is a jsfiddle where I added a line on the page as a reference to show up to where the input should go on the left. As you make the fiddle window smaller, the button goes under the input and reaches a full lenght, but the input still has a gap on both sides.
It is because the column classes are meant to wrap the elements and give them structure. If you give your button those classes, it will give that element the full width instead of the typical padding.
I moved the column classes onto the form-group instead and made a simple class called .btn-full that sets the width: 100%; and it achieves what you want.
http://jsfiddle.net/SXus5/
If you want the button to be the full width of the container, just add the class 'btn-block' to it. Any inputs inside of a form group will automatically expand to fill their container. Instead of adding the .col classes to the form group, add it to a div the form is contained in.
Here's a modified version of your jsfiddle with the input, button and line all the same width.
<button type="submit" class="btn btn-primary btn-lg btn-block">Search</button>