How to add 3 elements in Bootstrap's modal header? - html

I need my modal to have 3 elements in it:
To the left: a button
In the center: a title
To the right: the close button
When you look at my modal it seems like I achieved what I need, but in reality, my title is not centered. Here's my code:
.modal-dialog {
max-width: 90%;
}
.modal-header {
border: none;
}
.modal-title-filter {
color: #2D2D2D;
font-size: 1.2em;
text-align: center;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<!-- Header -->
<div class="modal-header">
<button class="btn btn-primary">Limpiar filtros</button>
<h5 class="modal-title modal-title-filter w-100 text-center" id="exampleModalLabel">Filtros</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<!-- /Header -->

the title is centered, centered with respect to its container h5, no to the modal-header, but if you want the title looks centered with respect to modal-header you can edit the margin-left of your title for that, try with this:
.modal-header .modal-title{
margin-left: -20px;
}
The higher the negative value the title will be moved to the left or more centered according to your taste.
I hope i was help you. Regards

You can achieve something like this by setting the display of the modal header to flex, and justifying the content by the space between the items.
Note: I had to add a thing of margin-left:0 to the close button as it has a declaration of margin-left:auto.
.modal-dialog {
max-width: 90%;
}
.modal-header {
border: none;
}
.modal-title-filter {
color: #2D2D2D;
font-size: 1.2em;
text-align: center;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<!-- Header -->
<div class="modal-header d-flex justify-content-between align-items-center">
<button class="btn btn-primary">Limpiar filtros</button>
<h5 class="modal-title modal-title-filter" id="exampleModalLabel">Filtros</h5>
<button type="button" class="close" style="margin-left:0;" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<!-- /Header -->

Related

How do I make an image take up 100% of a Bootstrap modal container?

I have some bootstrap modals with images in them. Some of them are long vertically which makes a scrollbar appear. I tried to fix this by setting a max-height to the modal-content and having modal-body, where the image is inside of to be 100% of that. Now the backdrop is the height I set it to, but the image still extends past the container.
jsfiddle: https://jsfiddle.net/cLn52tqg/
.modal-content {
max-height: 85vh;
}
.modal-content>.modal-body {
max-height: 100%;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<div class="modal fade show" id="modalImage2" tabindex="-1" aria-labelledby="allImage2" aria-hidden="true" style="display: block;">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header text-center">
<h2 class="modal-title w-100 text-dark" id="allImage2">image title</h2>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<img class="img-fluid" src="https://images.unsplash.com/photo-1564754943164-e83c08469116?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8NXx8dmVydGljYWx8ZW58MHx8MHx8&w=1000&q=80" alt="">
<p class="modalText text-dark text-center mt-2">image description</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
Seems like setting a max height is preventing the image to scale down inside the container. Setting height fixed the issue you can add a calc() function if you want to add some extra height into consideration.
.modal-content>.modal-body{
height: 70vh;
overflow: auto;
position: relative;
}
.modal-content>.modal-body > img{
object-fit: contain;
width: 100%;
height: 100%;
}
I setup a custom class for the modal content which will use display: grid for this -- it doesn't work in the tiny little snippet preview but if you run the snippet and view full page you will see it working nicely
.modal-content.grid-content {
display: grid;
grid-template-rows: auto 1fr auto;
height: calc( 100vh - 1.75rem - 1.75rem ); /* Account for vertical margin on parent */
}
.modal-content.grid-content .modal-body {
min-height: 0;
display: grid;
grid-template-rows: 1fr auto;
}
.modal-content.grid-content .modal-body > * {
min-height: 0;
}
.modal-content.grid-content .modal-body img {
display: block;
margin: auto;
max-height: 100%;
/* REMOVE THESE 2 LINES IF YOU WANT IMAGE TO CCENTER INSTEAD OF CROP */
object-fit: cover;
width: 100%;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<div class="modal fade show" id="modalImage2" tabindex="-1" aria-labelledby="allImage2" aria-hidden="true" style="display: block;">
<div class="modal-dialog modal-lg">
<div class="modal-content grid-content">
<div class="modal-header text-center">
<h2 class="modal-title w-100 text-dark" id="allImage2">image title</h2>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<img class="img-fluid" src="https://images.unsplash.com/photo-1564754943164-e83c08469116?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8NXx8dmVydGljYWx8ZW58MHx8MHx8&w=1000&q=80" alt="">
<p class="modalText text-dark text-center mt-2">image description</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>

Add Spacing Between Two Inline-Block Elements

I have a modal button next to my header and both elements have display: inline-block;. I am trying to make spacing and have the button go further to the right and keep the header element centered.
I tried adjusting the padding of the item container and that still did not work?
.btn.btn-info.btn-md {
background: #104723;
border-color: #104723;
border-radius: 3px;
float: right;
display: inline-block;
position: absolute;
}
.btn.btn-info.btn-md:active {
background: #104723;
border-color: #104723;
border-radius: 3px;
float: right;
display: inline-block;
position: absolute;
margin-right: -40px;
}
.pageheadh {
font-size: 30px;
font-weight: bolder;
color: black;
text-align: center;
display: inline-block;
}
.pageheadp {
text-align: center;
color: black;
font-weight: bold;
}
.center {
align-items: baseline;
justify-content: center;
text-align: center;
padding-right: 10px;
}
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css">
<!-- Datatables -->
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.13/css/dataTables.bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://nightly.datatables.net/js/jquery.dataTables.js"></script>
<script src="https://nightly.datatables.net/js/dataTables.bootstrap.js"></script>
<!-- Trigger the modal with a button -->
<div class="center">
<h3 class="pageheadh">Fitness Tracker</h3>
<button type="button" class="btn btn-info btn-md" data-toggle="modal" data-target="#myModal" >Prize Plaza</button>
</div>
<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog modal-lg">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title"></h4>
</div>
<div class="modal-body">
<embed src="https://ak.picdn.net/shutterstock/videos/3998236/thumb/3.jpg" frameborder="0" width="100%" height="100%">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<p class="pageheadp">Click on any of the tabs to track your progress in that category. </p>
<!--<input type="text" class="global_filter" id="global_filter">-->
<div class="clearfix"></div>
<ul class="nav nav-tabs">
<li class="active"> Weekly Weight Δ
</li>
<li>Total Weight Δ
</li>
<li>Weekly Steps
</li>
<li>Total Steps
</li>
<li>Weekly Minutes
</li>
<li>Total Minutes
</li>
<li>Step Points
</li>
<li>Exercise Points
</li>
<li>Weekly Winners
</li>
</ul>
First add position: relative to .center to correctly position the button with absolute positioning.
And add this ruleset for .btn.btn-info.btn-md selector:
top: 0;
bottom: 0;
height: 40px;
margin: auto auto auto 50px;
.btn.btn-info.btn-md {
background: #104723;
border-color: #104723;
border-radius: 3px;
float: right;
display: inline-block;
position: absolute;
top: 0;
bottom: 0;
height: 40px;
margin: auto auto auto 50px;
}
.btn.btn-info.btn-md:active {
background: #104723;
border-color: #104723;
border-radius: 3px;
float: right;
display: inline-block;
position: absolute;
margin-right: -40px;
}
.pageheadh {
font-size: 30px;
font-weight: bolder;
color: black;
text-align: center;
display: inline-block;
}
.pageheadp {
text-align: center;
color: black;
font-weight: bold;
}
.center {
align-items: baseline;
justify-content: center;
text-align: center;
padding-right: 10px;
position: relative;
}
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" />
<!-- Datatables -->
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.13/css/dataTables.bootstrap.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://nightly.datatables.net/js/jquery.dataTables.js"></script>
<script src="https://nightly.datatables.net/js/dataTables.bootstrap.js"></script>
<!-- Trigger the modal with a button -->
<div class="center">
<h3 class="pageheadh">Fitness Tracker</h3>
<button type="button" class="btn btn-info btn-md" data-toggle="modal" data-target="#myModal">Prize Plaza</button>
</div>
<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog modal-lg">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title"></h4>
</div>
<div class="modal-body">
<embed src="https://ak.picdn.net/shutterstock/videos/3998236/thumb/3.jpg" frameborder="0" width="100%" height="100%" />
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<p class="pageheadp">Click on any of the tabs to track your progress in that category.</p>
<!--<input type="text" class="global_filter" id="global_filter">-->
<div class="clearfix"></div>
<ul class="nav nav-tabs">
<li class="active">Weekly Weight Δ</li>
<li>Total Weight Δ</li>
<li>Weekly Steps</li>
<li>Total Steps</li>
<li>Weekly Minutes</li>
<li>Total Minutes</li>
<li>Step Points</li>
<li>Exercise Points</li>
<li>Weekly Winners</li>
</ul>
You can add absolute positions to your button :
.btn.btn-info.btn-lg {
background: #104723;
border-color: #104723;
border-radius: 3px;
float: right;
display: inline-block;
position: absolute;
right:15px;
top: 10px;
}
Perhaps Add a
<br>
in between the two divs. If not then maybe change this.
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal" >Prize Plaza</button>
to
<button type="button" class="btn btn-info btn-lg ml-5" data-toggle="modal" data-target="#myModal" >Prize Plaza</button>
if not then change your css to
.btn.btn-info.btn-lg {
background: #104723;
border-color: #104723;
border-radius: 3px;
float: right;
display: inline-block;
position: absolute;
right:15px;
top: 10px;
margin-right: 50px;
}

MDbootstrap massive whitespace on mobile devices

I'm currently working on a Watch2Gether clone that looks fine on medium and large devices, but once you get to the phone view, everything looks awesome until you scroll left and find a massive whitespace on the right side. I'm not too sure why this is happening, I tried changing the margin and padding on some items which helped with the UI, but there's still a huge whitespace when you scroll which looks really bad. Any idea how to fix this?
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- Description -->
<meta name="description" content="Watch Youtube videos live with your friends, easily, for free!">
<!-- Favicon -->
<link rel="icon" href="/img/favicon.ico">
<!-- Font Awesome -->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.2/css/all.css">
<!-- Google Fonts -->
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap">
<!-- Bootstrap core CSS -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet">
<!-- Material Design Bootstrap -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.19.1/css/mdb.min.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght#300;400;500;700&display=swap" rel="stylesheet"> <link rel="stylesheet" href="css/styles.css" />
<title>Room</title>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="/">WatchWithFriends</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarText">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="/">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/create">Create Room</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/about">About</a>
</li>
</ul>
<input autocomplete="off" id="paste" name="paste" class="form-control form-control-md"placeholder="Paste Video URL Here" aria-label="Search">
<button id="watch" class="btn btn-outline-success waves-effect" type="submit">Watch</button>
</div>
</nav>
<div class="section">
<div class="row">
<div class="col-lg-8 col-md-7 col-sm-12 main-section">
<h1 id="roomBasic"><span id="name"></span><span id="users"></span></h1>
<div id="player"></div>
</div>
<div class="col-lg-4 col-md-5 col-sm-12">
<div id="chat-holder">
<div id="mario-chat">
<a id="leave" href="/" class="btn btn-primary btn-block btn-lg leave">Leave Room</a>
<div id="chat-window">
<div id="output"></div>
<div id="feedback"></div>
</div>
<form action="" id="chat-form">
<input
type="text"
id="message"
placeholder="Message"
required
autocomplete="off"
class="form-control form-control-lg"
/>
<button class="btn btn-black btn-block" id="send" onclick="reload()">Send</button>
</form>
</div>
</div>
</div>
</div>
</div>
<div class="info">
<div class="row">
<div class="col-md-8">
<h3 id="welcome-room">Welcome to your room!</h3>
<p class="room-info-p">
To invite a friend, just copy the link below. To change their name they
just have to replace the name in the "username" field. Ex:
username=Billy -> username=Ryan. They can also join using the "Join Room" page.
</p>
<div class="input-group mb-3">
<input id="urlInfo" type="text" class="form-control" placeholder="Url">
<div class="input-group-append">
<button onclick="copyUrl()" class="btn btn-md btn-outline-dark m-0 px-3 py-2 z-depth-0 waves-effect" type="button" id="button-addon2">Copy</button>
</div>
</div>
<p class="room-info-p">To play a new video, paste the URL into the form in the navigation bar and press watch!</p>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/qs/6.9.4/qs.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.3.0/socket.io.js"></script>
<script src="client.js"></script>
<script src="users.js"></script>
<%- include('partials/footer') %>
CSS:
/* room page */
#name {
color: #575ed8;
}
#roomBasic {
font-weight: 600;
}
.section {
height: 80vh;
}
#mario-chat {
max-width: 500px;
border: 1px solid #ddd;
box-shadow: 1px 3px 5px rgba(0, 0, 0, 0.05);
border-radius: 2px;
}
#chat-holder {
margin: 11vh 3vh;
}
#chat-window {
height: 50vh;
overflow: auto;
background: #f9f9f9;
}
#sentText {
padding: 14px 0px;
margin: 0 20px;
border-bottom: 1px solid #e9e9e9;
color: #555;
}
#sentText p {
font-size: 1.1rem;
margin-bottom: 0.1px;
}
#feedback p {
color: #aaa;
padding: 14px 0px;
margin: 0 20px;
}
#output strong {
color: #575ed8;
}
#mario-chat input {
padding: 10px 20px;
box-sizing: border-box;
background: #eee;
border: 0;
display: block;
width: 100%;
background: #fff;
border-bottom: 1px solid #eee;
font-size: 16px;
}
#send {
background-color: #292b2c;
color: #fff;
font-size: 18px;
border: 0;
padding: 12px 0;
width: 100%;
border-radius: 0 0 2px 2px;
}
#player {
margin: 30px 30px;
border: 1px solid #ddd;
height: 62vh;
width: 100%;
}
.main-section h1 {
margin-left: 30px;
margin-top: 20px;
}
.info {
margin: 30px 30px;
}
.leave {
background: #575ed8;
font-size: 18px;
width: 100%;
margin-top: 0;
margin-bottom: 0;
}
/* info section */
.info {
height: 50vh;
font-family: "Roboto", sans-serif;
}
#welcome-room {
font-weight: 600;
}
I got the same issue and this meta tag belon helped me :
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=320, height=device-height, target-densitydpi=medium-dpi" />
Or
//from another topic
It is true that the row class is what is causing the issue, but that is because it is always supposed to be placed inside a container element.
from http://getbootstrap.com/css/ :
Rows must be placed within a .container (fixed-width) or .container-fluid (full-width) for proper alignment and padding.
The container element usually has a -15px padding on both right and left and the row class has a 15px padding on right and left. The two cancel each other out. If one of the two is not present you will see extra space.
From : Twitter bootstrap white gap on right side of page

Scrollbar too long due to bootstrap 4 navbar

This is a pretty funky issue.
I'm trying to create an frameless app using electron and bootstrap 4 and wanted to style the app a bit.
After a lot of work, I came by the most odd of issues I have encountered in the entire project.
This is not an electron issue tho (hence the lack of the relevant tag).
You see, I have a header element that is 87px height (to contain the navbar and window controls like maximize and close), with a main element under it that contains the actual content of the page.
<header>
<div class="window-control bg-primary">
<button class="btn btn-primary btn-sm float-right" (click)="exitApp()"><fa-icon [icon]="faTimes"></fa-icon></button>
<button class="btn btn-primary btn-sm float-right" *ngIf="isMaximized" (click)="unmaximizeWindow()"><fa-icon [icon]="faMinusSquare" ></fa-icon></button>
<button class="btn btn-primary btn-sm float-right" *ngIf="!isMaximized" (click)="maximizeWindow()"><fa-icon [icon]="faPlusSquare" ></fa-icon></button>
<button class="btn btn-primary btn-sm float-right" (click)="minimizeWindow()"><fa-icon [icon]="faMinus"></fa-icon></button>
</div>
<nav class="navbar navbar-expand navbar-dark bg-secondary">
<div class="container-fluid">
<a class="navbar-brand" href="#">
<span class="text-primary font-weight-bold">9</span>AnimeDl
</a>
<ul class="nav navbar-nav mr-auto">
<li class="nav-item"><a class="nav-link" href="#">Discover</a></li>
</ul>
<form class="form-inline my-2 my-lg-0 mr-2">
<div class="input-group">
<input class="form-control bg-secondary border-0 text-center" aria-describedby="basic-addon1" type="search" placeholder="Search" aria-label="Search" #search (keyup)="searchChange(search.value)">
<div class="input-group-append">
<button class="btn btn-outline-primary bg-secondary text-white" type="button">
<fa-icon [icon]="faSearch"></fa-icon>
</button>
</div>
</div>
</form>
<button class="btn btn-primary" (click)="doDonate()">Donate</button>
</div>
</nav>
</header>
<app-donate-modal *ngIf="nagDonation"></app-donate-modal>
<app-waf-captcha *ngIf="_9anime.isWafActive" [siteKey]="_9anime.siteKey"></app-waf-captcha>
<main [hidden]="!isBusy" class="container-fluid bg-gray-dark">
<div class="content">
<app-loading-spinner></app-loading-spinner>
</div>
</main>
<main [hidden]="isBusy" class="container-fluid bg-gray-dark">
<router-outlet></router-outlet>
</main>
Now I added the following css to my stylesheet:
body {
overflow: hidden;
height: 100%;
}
main {
height: 100%;
padding-top: 25px;
position: absolute;
overflow-y: scroll;
}
.window-control {
height: 31px;
-webkit-app-region: drag;
-webkit-user-select: none;
button {
-webkit-app-region: none;
}
}
::-webkit-scrollbar {
width: 12px; /* for vertical scrollbars */
height: 12px; /* for horizontal scrollbars */
}
::-webkit-scrollbar-track {
background: map-get($theme-colors, "gray-dark");
}
::-webkit-scrollbar-thumb{
background: map-get($theme-colors, "primary");
}
::-webkit-resizer {
display: none;
}
This causes the "regular" scrollbar to be gone from the body and slams it into the main element
Now, here is the funky part.
When I remove the header (display: none) and scroll all the way down this is what I get:
The scrollbar reaches the bottom and says put, the cards show fully with a small padding at the bottom.
Now when I add the header back in again and scroll all the way down, this happens:
The cards don't fully show, there is no padding under it (like in the first screenshot) and the scrollbar scrolls farther than it should scroll.
My question is if anyone knows what is causing this issue and, more importantly, how to solve it.
solved it by adding an 87px thick border on the bottom of the content:
main {
border-bottom: 87px solid #ccc;
}

Horizontal scroll bar bot working in bootstrap modal

I am having a modal, showing div in 'modal-body'.
<div class="modal-body">
<div class="scoll-tree">
<div class="history">
Report Event Details
</div>
<div class="history">
Report Event Details 1
</div>
<div class="history">
Report Event Details 2
</div>
<div class="history">
Report Event Details 3
</div>
</div>
</div>
Set the class as bellow :
.scoll-tree{
width: 400px;
height:80px;
overflow-x: scroll;
}
.history {
background: rgba(255, 255, 255, 0.7);
float: left;
min-width: 5em;
width: 25ex;
max-height: 3em;
margin: 2em;
padding: 1em;
border: 1px solid rgba(0, 0, 0, 0.2);
border-radius: 16px;
box-shadow: 2px 5px 5px rgba(0,0,0,0.2);
vertical-align: central;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
I want horizontal scroll bar to 'scoll-tree' container, when 'history' div exceed the width.
Currently it give vertical scroll bar, i want only horizontal scroll bar.
https://jsfiddle.net/hemantmalpote/4duq2svh/35/
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Modal Example</h2>
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<div style="height:100px; width:100px; overflow-x:auto">
Content1
Content2
Content3
Content4
Content5
Content6
Content7
Content8
Content9
Content10
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
Well not sure whether it is what you are looking for, but check it https://jsfiddle.net/4duq2svh/44/. I changed you css little bit,
.modal-body {
width: 400px;
overflow-x: scroll;
}
.scoll-tree{
width: 800px;//ideally you it is better to make js script which will calculate this value
height:80px;
}
Very Simple -
Just use max-width instead of width & set overflow-x: auto.
So it will be -
.scoll-tree{
max-width: 400px;
height:80px;
overflow-x: auto;
}
You may first set it to 200px for testing whether scroll appears or not.