I'm trying to setup a modal that has a an image and text strictly on the left side with a border around it with also a button also inline with the image and text on the left hand side with a border around it as well. From there I'm trying to put links on the left side of the image/text/button so that it's symmetrical. I'm having trouble though getting the border to stay only around the image and have the text word-wrap under the image. This is currently what I've been creating:
HTML:
<!-- Button trigger modal --> <a data-toggle="modal" href="#myModal" class="btn btn-primary btn-lg">Launch demo modal</a>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Modal title</h4>
</div>
<div class="modal-body">
<div class="content" style="word-wrap">
<img class="img-responsive" src="https://www.gl.ciw.edu/sites/www.gl.ciw.edu/files/users/pwoodard/microbiology.jpg" alt="image" />
<p float:left;>This is the text. This is the text. This is the text. This is the text. This is the text. This is the text. This is the text. This is the text.</p>
<button type="button" class="btn btn-primary" data-dismiss="modal" align="center">$4500</button>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
CSS:
.content {
padding: 10px 10px 10px 10px;
position: left;
border:1px solid gray;
outline: thin;
}
http://jsfiddle.net/wan4q/11/
I think you can
Create the class only for the image and specify the border on it.
Using javascript you can set the container width to be equal to the width of the image.
Have your text and the image is the same div so that the text wraps according to the size of you parent div.
JSFiddle
<a data-toggle="modal" href="#myModal" class="btn btn-primary btn-lg">Launch demo modal</a>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Modal title</h4>
</div>
<div class="modal-body">
<div class="container">
<div class="wrap">
<img class="img-responsive bordered-image" src="https://www.gl.ciw.edu/sites/www.gl.ciw.edu/files/users/pwoodard/microbiology.jpg" alt="image"/>
<div class="content">
<p style="float:left;">
This is the text.
This is the text.
This is the text.
This is the text.
This is the text.
This is the text.
This is the text.
This is the text.
</p>
<button type="button" class="btn btn-primary" data-dismiss="modal" align="center">$4500</button>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
JS :
(function() {
var img = new Image();
var $mydiv = $('.wrap');
img.src = 'https://www.gl.ciw.edu/sites/www.gl.ciw.edu/files/users/pwoodard/microbiology.jpg';
$mydiv.width(img.width);
})();
CSS:
.content {
padding: 10px 10px 10px 10px;
position: left;
outline: thin;
}
.bordered-image{
border:1px solid gray;
}
.wrap {
display: inline-block;
position: relative;
}
Related
Is there a way to limit the size of bootstrap 5 modal dialog and backdrop?
The example below is occupying 100% of the screen, is it possible to make it cover only the parent main container?
<main class="container-fluid pt-4 px-4" style="height: 400px">
<!-- Button trigger modal -->
<button
type="button"
class="btn btn-primary"
data-bs-toggle="modal"
data-bs-target="#exampleModal"
>
Launch demo modal
</button>
<!-- Modal -->
<div
class="modal fade hide"
data-backdrop="false"
id="exampleModal"
tabindex="-1"
aria-labelledby="exampleModalLabel"
aria-hidden="true"
>
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5
class="modal-title"
id="exampleModalLabel"
>
Modal title
</h5>
<button
type="button"
class="btn-close"
data-bs-dismiss="modal"
aria-label="Close"
></button>
</div>
<div class="modal-body">...</div>
<div class="modal-footer">
<button
type="button"
class="btn btn-secondary"
data-bs-dismiss="modal"
>
Close
</button>
<button
type="button"
class="btn btn-primary"
>
Save changes
</button>
</div>
</div>
</div>
</div>
</main>
I added the CSS below but not working.
.modal-dialog, .modal-backdrop {
/* supposed to take the height and width of parent container */
height: 100% !important;
width: 100% !important;
}
How it works:
What I want (or expected behavior):
The modal component adds a the backdrop element (outside the .modal's parent) automatically, so if you want the modal to be completely contained inside the parent, start by disabling the backdrop with data-bs-backdrop="false".
By default the .modal has position: fixed so it gets rendered relative to the viewport without regards to its parent element(s). This behavior can be overridden by giving the (main) parent position: relative; and give the .modal child position: absolute;. You can also give the .modal an rgba() background-color to simulate an encapsulated, static backdrop within the parent only (clicking on a static backdrop does not close the modal).
To have the modal centered within the parent add .modal-dialog-centered to the .modal-dialog.
In the snippet below I have given both main and .modal a background to more clearly demonstrate:
main {
position: relative;
background: #EEE;
}
main .modal {
position: absolute;
background: rgba(0, 100, 0, 0.35);
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
<div class="container-fluid">
<div class="row">
<div class="col-2">
sidebar
</div>
<div class="col-10">
<div class="row">
<nav class="navbar bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">Navbar</a>
</div>
</nav>
</div>
<div class="row">
<main class="container-fluid pt-4 px-4" style="height: 400px">
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade hide" data-bs-backdrop="false" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">
Modal title
</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body flex-grow-1">...</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
Close
</button>
<button type="button" class="btn btn-primary">
Save changes
</button>
</div>
</div>
</div>
</div>
</main>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.2.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4" crossorigin="anonymous"></script>
The modals in the project seems to have broke for some reason. It worked a few days ago now it seems it broke. The container div is overflowing.
This is a sample html I've been using after all the modals broke
<!-- Modal -->
<div id="regHomeModal" class="modal fade" role="dialog">
<div class="modal-dialog modal-lg">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Modal Header</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
<div class="container" style="border-style: dotted; border-color: black;">
<div class="row" style="border-style: dotted; border-color: red;">
<div class="col-sm-9">
<btn class="test btn btn-info btn-block btn-lg">TEST BUTTON</btn>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
That's happening because bootstrap already has an inbuilt '.container' class which has its width predefined, try changing the class name and check.
screenshot of the page
Hi, i'm losing my head trying to figure it out why this modal is shown like this. The code i followed was copied from the bootstrap website.
Here it is
<button type="button" class="btn btn-info btn-lg" (click)="showPerformedActivityModal()">Show Performed Activities</button>
<!--Modal -->
<div class="container">
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true"
[ngStyle]="{'display': myModalIsOpen ? 'block' : 'none', 'opacity': 5}">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<app-table [config]="config" [columns]="columns" [entity]="entity" [sort]="sort" [sortOrder]="sortOrder">
</app-table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" (click)="refreshResources()">Select Activities</button>
<button type="button" class="btn btn-default" (click)="closeModal()">Close</button>
</div>
</div>
</div>
</div>
</div>
This does the job : http://jsfiddle.net/sRmLV/1140/
You need to use new DIV and custom CSS, change the class 'modal-dialog-centered' by 'vertical-align-center'
HTML
<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">Launch demo modal</button>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="vertical-alignment-helper">
<div class="modal-dialog vertical-align-center">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">...</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</div>
CSS
.vertical-alignment-helper {
display:table;
height: 100%;
width: 100%;
pointer-events:none;}
.vertical-align-center {
/* To center vertically */
display: table-cell;
vertical-align: middle;
pointer-events:none;}
.modal-content {
/* Bootstrap sets the size of the modal in the modal-dialog class, we need to inherit it */
width:inherit;
max-width:inherit; /* For Bootstrap 4 - to avoid the modal window stretching
full width */
height:inherit;
/* To center horizontally */
margin: 0 auto;
pointer-events:all;}
when I use the bootstrap's modal like this:
<style>
.modal-content {
border-radius: 60px;
}
</style>
<div id="upload-loading" class="modal" role="dialog">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button id="loadingClose" type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Upload in progress...</h4>
</div>
</div>
</div>
</div>
it shows an underline
I tried to add this style
<style>
.modal-content, .modal-content * {
text-decoration: none !important;
}
</style>
but it doesn't seem to make any difference..
.modal-content {border: 0px solid rgba(0, 0, 0, 0.2);}
Just give border to the class .modal-header
I just solve it in React
<div>
{/* Button trigger modal */}
<button type="button" className="btn btn-primary" data-toggle="modal" data-target="#exampleModalCenter">
Launch demo modal
</button>
{/* Modal */}
<div className="modal fade" id="exampleModalCenter" tabIndex={-1} role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div className="modal-dialog modal-dialog-centered" role="document">
<div className="modal-content">
<div className="modal-header" style={{border:"1px solid #fff"}}>
<h5 className="modal-title" id="exampleModalLongTitle">Buy Premium</h5>
<button type="button" className="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div className="modal-body">
<p>Your account is limited to only 3 CV views.
To review more, purchase Premium Subscription</p>
<button className="btn btn-primary">Purchase</button>
</div>
<div className="modal-footer">
<button type="button" className="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
I have a created a button when you click it a modal appears.
Here is the code:
<li style="float: right;">
<button id="myBtn" data-target="#myModal" ng-click="printDivModal('rollup-tab')">Modal Test</button>
</li>
In the js, the ng-click should open a model which contains data from stackModal.html
Here is the code in the js file:
$scope.printDivModal = function(divName) {
console.log('opening pop up');
var ModalInstance = $uibModal.open({
//animation: $ctrl.animationsEnabled,
templateUrl: 'app/views/modals/stackedModal.html',
size: 'lg',
/*
controller: function($scope) {
$scope.name = 'top';
}
*/
});
}
Here is the code for the model (stackedModal.html):
<!-- 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">The Modal Header</h4>
</div>
<div class="modal-body">
<p>Text inside the modal.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
When I click the Model-Test button, all I see is a small white rectangle show on the screen. Nothing appears from the stackedModal html page. Why is this? Thanks.
Just remove modal wrappers div's, bootstrap-modal does it for you.
You just need to put modal content:
stackedModal.html:
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">The Modal Header</h4>
</div>
<div class="modal-body">
<p>Text inside the modal.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>