I am using Bootstrap 4. I am facing an odd issue. I am adding the html using the jquery. The div has call .col-md-9 d-flex. When the other div's are appened to main div (under parent col-md-9) one it overflows and takes whole page (width) and over ride the other div (col-md-3). The code is given as
<div class="container-fluid">
<div class="row">
<div class="col-md-9 filters-div d-flex"><!-- the dynamic code will append to this div-->
<div class="col-md-2 col-xs-6">
<div class="form-group">
<label>Date and time range:</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="far fa-clock"></i></span>
</div>
<input type="text" id="reservationdate" class="form-control float-right datetimepicker-input" data-toggle="datetimepicker" data-target="#reservationdate">
</div>
<!-- /.input group -->
</div>
<!-- /.form group -->
</div>
</div>
<div class="col-md-3 d-flex">
<div class="my-div">
<a href="javascript:void(0)" data-toggle="modal" data-target="#modal-default">
<i class="fas fa-filter"></i>Add Filters
</a>
Cancel
Submit
</div>
</div>
</div>
</div>
The jquery which produces the dom element is as follows
$(document).delegate(".add-filter","click",function(){
$val=$("#filter-add").val();
$text=$('#filter-add option:selected').text();
$new_text=$text.replace(/ /g, "-");
$html="<div class='col-md-2 col-xs-6 delete-all' id='"+$new_text+"'><div class='form-group'>";
$html+="<label>"+$text+":</label>";
$html+="<div class='input-group'>";
$html+="<input type='text' class='form-control float-right'><div class='input-group-prepend'><span class='input-group-text delete-filter' data-text='"+$text+"' data-value='"+$val+"'><i class='fas fa-trash'></i></span> </div></div>";
$html+="</div></div>";
$(".filters-div").append($html);
$("#filter-add option:selected").remove();
$('#filter-add').prop('selectedIndex',0);
});
Do let me know whats the issue. The example is here
UPDATE:
The screenshot is attached as follows
You can use flex-wrap to your div:
<div class="col-md-9 filters-div d-flex flex-wrap"><!-- the dynamic code will append to this div-->
Instead, if you don't want to wrap you can reduce the max-width of col-md-2:
.col-md-2 {
max-width: 12% !important;
}
Your issue is up to col-md-2: when you have much of them you get the problem.
Related
I want to center following divs in the middle of the screen HORIZONTALLY AND VERTICALLY (2 SITES). What should I add to my HTML code to make it works? I managed to center div from first site vertically by adding justify-content-center class to 2nd div, but the same is not working for second site.
first site
<div class="container">
<div class="row justify-content-center">
<div class="form-group col-md-4">
<form method="post" th:object="${redirectionDto}">
<div class="form-group">
<label for="urlinput">URL</label>
<input type="text" id="urlinput" class="form-control" th:field="*{url}" name="urlinput"
maxlength="255"/>
</div>
<div class="form-group">
<label for="date">Date:</label>
<div class="input-group date" id="datetimepicker1" data-target-input="nearest">
<input type="text" class="form-control datetimepicker-input" data-target="#datetimepicker1"
th:field="*{expireDate}" id="date" placeholder="Date"/>
<div class="input-group-append" data-target="#datetimepicker1" data-toggle="datetimepicker">
<div class="input-group-text"><i class="fa fa-calendar-alt"></i></div>
</div>
</div>
</div>
<button class="btn btn-primary" type="submit">Submit form</button>
</form>
</div>
</div>
</div>
second site
<div class="container">
<label>Short link: </label>
<p th:text="${redirectionDto.alias}"></p>
<label>Expire date: </label>
<p th:text="${#dates.format(redirectionDto.expireDate, 'dd/MM/yyyy h:mm a')}"></p>
<a th:href="#{/}" class="btn btn-primary">Return</a>
</div>
Wrap it like so:
<div class="container">
<div class="row justify-content-center">
<!-- START THE DIV -->
<label>Short link: </label>
<p th:text="${redirectionDto.alias}"></p>
<label>Expire date: </label>
<p th:text="${#dates.format(redirectionDto.expireDate, 'dd/MM/yyyy h:mm a')}"></p>
<a th:href="#{/}" class="btn btn-primary">Return</a>
</div>
<!-- /END THE DIV -->
</div>
how i normally align <div>s to the centre is by using margins, so using some maths, you would do:
full width of page (say, 100%) - div width, then half this, that's your left margin. then do the same for height, that's your top margin.
this has mostly worked in my experience. hope i am of help!
Can you please check the below code? Hope it will work for you.
If you want to place your content in middle both horizontally and vertically then flex utility classes are very helpful.
In your First site code, you have used justify-content-center with class="row" which centers the content horizontally, if you will use align-items-center class along with it then the content will be centered vertically. In this case, if you will give a particular height to your .row class then you can see the content div in the center.
<div class="row justify-content-center align-items-center">
</div>
.container .row {
height: 100vh;
}
In your Second site, you need to wrap your content in a div and need to give the same classes "row justify-content-center align-items-center" to its parent div similarly as you give it in your first site code.
Please refer to this link:
1st Site:
https://jsfiddle.net/yudizsolutions/schgm9xk/
2nd Site:
https://jsfiddle.net/yudizsolutions/tk2eqdsx/
i want to make one div right align , but not able keep it in right side in row. how to make the value 172.21 at right side in the row.
screenshot
HTML:
<div class="row">
<div class="col-md-6">
<h4>Status</h4>
<input type="checkbox" disabled checked data-toggle="toggle" data-onstyle="outline-success" data-offstyle="outline-danger">
</div>
<div class="col-md-3">
<h4>Max Demand </h4>
</div>
<div class="col-md-3">
<h4>172.21</h4>
</div>
</div>
If there is text, just "align-right"
If there is block, in BS3:
Add "pull-right" to the element container
In BS4:
"float-right"
E.g. in BS4:
<div class="row">
<div class="col-md-6">
<h4>Status</h4>
<input type="checkbox" disabled checked data-toggle="toggle" data-onstyle="outline-success" data-offstyle="outline-danger">
</div>
<div class="col-md-3">
<h4>Max Demand </h4>
</div>
<div class="col-md-3 float-right">
<h4>172.21</h4>
</div>
</div>
You just need add class in last column like: text-left text-md-right.
I hope below snippet will help you.
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.5.3/dist/css/bootstrap.min.css">
<div class="container border">
<div class="row">
<div class="col-md-6">
<h4>Status</h4>
<input type="checkbox" disabled checked data-toggle="toggle" data-onstyle="outline-success" data-offstyle="outline-danger">
</div>
<div class="col-md-3">
<h4>Max Demand </h4>
</div>
<div class="col-md-3 text-left text-md-right">
<h4 class="btn btn-warning">545</h4>
</div>
</div>
</div>
Just for the text, add text-right class after col-md-3
and for the entire column, add pull-right class after col-md-3 if you're using bootstrap-3
and for bootstrap-4 add float-right instead of pull-right class.
I'm trying to use flexbox to align vertically a section.
So this is what I'm trying to align vertically:
HTML:
<!--Top Hero Section -->
<div class="d-flex hm-hero justify-content-center">
<div class="container">
<div class="row align-items-end">
<div class="col-12">
<h1 class="text-center">Fix Your Problem Today!</h1>
<p class="text-center">Start searching for a contractor or company around your area and get your problem fixed in a matter of hours!</p>
</div>
<!--Form Section -->
<div class="col-12">
<div class="form-group row justify-content-center">
<div class="col-12 col-md-6">
<input class="form-control" type="text" value="e.g. plumbing, carpentry" id="example-text-input">
</div>
<div class="col-12 col-md-4">
<input class="form-control" type="text" value="e.g. city name, postcode" id="example-text-input">
</div>
<div class="col-12 col-md-2">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</div>
</div>
</div>
</div>
Regarding CSS, I've only applied this:
.hm-hero {
background: url("../img/main_pic.png") no-repeat;
background-size: fill;
min-height: 600px;
}
I can't figure out why flexbox is not working. I've tried two classes, align-content/items-center in whatever div possible and still can't get it to work.
So since I have that full width div with the background image, inside it is a container div, which I'm trying to get it to stay vertically. I really want to avoid putting a 200px margin top to this. Is this is a Bootstrap 4 bug?
I added the align-items-center class to the flex div parent and it worked. As long as you have a height on the .hm-hero the content will be centered. Hope this helps. JSFiddle
.hm-hero {
background: url("https://placehold.it/960x600") no-repeat;
background-size: fill;
min-height: 600px;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet"/>
<!--Top Hero Section -->
<div class="d-flex hm-hero justify-content-center align-items-center">
<div class="container">
<div class="row align-items-end">
<div class="col-12">
<h1 class="text-center">Fix Your Problem Today!</h1>
<p class="text-center">Start searching for a contractor or company around your area and get your problem fixed in a matter of hours!</p>
</div>
<!--Form Section -->
<div class="col-12">
<div class="form-group row justify-content-center">
<div class="col-12 col-md-6">
<input class="form-control" type="text" value="e.g. plumbing, carpentry" id="example-text-input">
</div>
<div class="col-12 col-md-4">
<input class="form-control" type="text" value="e.g. city name, postcode" id="example-text-input">
</div>
<div class="col-12 col-md-2">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</div>
</div>
</div>
</div>
I have a website that displays many real-time graphs and gauges, all hidden within drawers initially. The graphs are made with the plotly.js library. The gauges are done with JustGage. The code for the containers is as such:
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-5 statistics">
<div class="centered-text">
<div class="container-fluid">
<div class="panel panel-info">
<div class="panel-heading">
<h3 class="panel-heading">Statistics Panel</h3>
</div>
<ul class="list-group">
<!-- Base Station Panel -->
<li class="list-group-item">
<div class="row toggle" id="dropdown-detail-1" data-toggle="detail-1">
<div class="col-lg-10 text-left">
Base Station
</div>
<div class="col-lg-2"><i class="fa fa-chevron-down pull-right"></i></div>
</div>
<div id="detail-1">
<hr></hr>
<div class="container-fluid">
<div class="fluid-row">
<div class="col-lg-6">
<div id="happygraph1"></div>
<input id="happybutton1" type="button" value="View History"
onclick="happygraph1.changeMode();"/>
</div>
<div class="col-lg-6">
<div id="happygraph2"></div>
<input id="happybutton2" type="button" value="View History"
onclick="happygraph2.changeMode();"/>
</div>
</div>
<div class="fluid-row">
<div class="col-lg-6">
<div id="happygraph3"></div>
<input id="happybutton3" type="button"
value="View History" onclick="happygraph3.changeMode();"/>
</div>
</div>
<div class="container-fluid">
<div class="fluid-row">
<div class="col-sm-6">
<div id="happygauge1 style="height: 250px; width: 300px;"></div>
</div>
</div>
<div class="col-sm-6">
<div id="happygauge2" style="height: 250px; width: 300px;"></div>
</div>
</div>
</div>
</div>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
The issue is that when the page loads, if the data begins appearing on the graphs before the hidden element is expanded, the graphs' containers extend out of the newly expanded element. However, if the element is expanded first, and then the data comes in, it acts exactly how it should. There is no issue with the gauges.
Here is a screenshot of when it's working:
graph containers stay within element
Here is a screenshot of when the element is expanded after the data has started being drawn: graph containers expand out of element
The drawers (and the layout in general) is done up by bootstrap. What is causing the containers to break? I have tried playing with the fluid row and container properties, however to no avail. Thanks in advance.
It seems the issue was not with Bootstrap at all but with some of the layout options set in Plotly. Plotly was sizing the graphs to be much larger than the container only when loaded hidden.
I have a bootstrap input that requires another div to the right of it but it won't seem to align with the code I'm using.
HTML (With bootstrap & fontawesome)
<div class="row">
<div id="mobNum" class="input-group margin-bottom-sm col-xs-6">
<span class="input-group-addon" style="width:20px"><i class="fa fa-phone-square" aria-hidden="true"></i></span><input id="mobile" class="form-control requiredClass" type="text" placeholder="Mobile Number.."/></div>
<div id="showDivMobile" class="showDivClass needData" style="col-xs-6">
<i class="fa fa-asterisk showCSS " aria-hidden="true"></i>vv<br/></div>
</div>
And my fiddle: http://jsfiddle.net/JLjjK/1350/
When using Bootstrap, it is a good practice to put your layout related classes (cols and rows) in separate divs elements; These classes should not be present in other elements like input-groups.
In your case, when you combine input-group with col-xs-6, it overrides the float attribute and breaks your layout, placing the divs on two separate lines.
Try separating them like this:
<div class="row">
<div class="col-xs-6">
<div id="mobNum" class="input-group margin-bottom-sm">...</div>
</div>
<div class="col-xs-6">
<div id="showDivMobile" class="showDivClass needData">...</div>
</div>
</div>
Hope this helps!
<div style="display:flex;">
<div id="mobNum" class="input-group margin-bottom-sm col-xs-6">
<span class="input-group-addon" style="width:20px">
<i class="fa fa-phone-square" aria-hidden="true"></i>
</span>
<input id="mobile" class="form-control requiredClass" type="text" placeholder="Mobile Number.."/>
</div>
<div id="showDivMobile" class="showDivClass needData col-xs-6">
<i class="fa fa-asterisk showCSS " aria-hidden="true"></i>vv<br/>
</div>
</div>
The issue is with this code from bootstrap
<div id="mobNum" class="input-group margin-bottom-sm col-xs-6">
CSS rule for input-group
.input-group[class*=col-] {
float: none; // this is the problem
padding-right: 0;
padding-left: 0;
}
It should be float:left So write a inline style to make it float left and it should be fine.
Also another issue is with style="col-xs-6" it must go in to class
Here is a working fiddle.
Changes done
<div id="mobNum" class="input-group margin-bottom-sm col-xs-6" style="float:left">
and
<div id="showDivMobile" class="showDivClass needData col-xs-6" style="">