0

我正在使用React bootstrap的Modal組件。 它默認出現在屏幕的中央。Floats bootstrap modal to the right

我該如何將它對齊到正確的位置?我曾嘗試以下沒有任何效果:

float: right; 
margin-left: auto; 
marigin-right: 0; 

margin-left: 65%;作品,但不適合動態調整窗口大小,模式的內容將被切斷。

回答

0

/******************************* 
 
* MODAL AS LEFT/RIGHT SIDEBAR 
 
* Add "left" or "right" in modal parent div, after class="modal". 
 
* Get free snippets on bootpen.com 
 
*******************************/ 
 
\t .modal.left .modal-dialog, 
 
\t .modal.right .modal-dialog { 
 
\t \t position: fixed; 
 
\t \t margin: auto; 
 
\t \t width: 320px; 
 
\t \t height: 100%; 
 
\t \t -webkit-transform: translate3d(0%, 0, 0); 
 
\t \t  -ms-transform: translate3d(0%, 0, 0); 
 
\t \t  -o-transform: translate3d(0%, 0, 0); 
 
\t \t   transform: translate3d(0%, 0, 0); 
 
\t } 
 

 
\t .modal.left .modal-content, 
 
\t .modal.right .modal-content { 
 
\t \t height: 100%; 
 
\t \t overflow-y: auto; 
 
\t } 
 
\t 
 
\t .modal.left .modal-body, 
 
\t .modal.right .modal-body { 
 
\t \t padding: 15px 15px 80px; 
 
\t } 
 

 
/*Left*/ 
 
\t .modal.left.fade .modal-dialog{ 
 
\t \t left: -320px; 
 
\t \t -webkit-transition: opacity 0.3s linear, left 0.3s ease-out; 
 
\t \t -moz-transition: opacity 0.3s linear, left 0.3s ease-out; 
 
\t \t  -o-transition: opacity 0.3s linear, left 0.3s ease-out; 
 
\t \t   transition: opacity 0.3s linear, left 0.3s ease-out; 
 
\t } 
 
\t 
 
\t .modal.left.fade.in .modal-dialog{ 
 
\t \t left: 0; 
 
\t } 
 
     
 
/*Right*/ 
 
\t .modal.right.fade .modal-dialog { 
 
\t \t right: -320px; 
 
\t \t -webkit-transition: opacity 0.3s linear, right 0.3s ease-out; 
 
\t \t -moz-transition: opacity 0.3s linear, right 0.3s ease-out; 
 
\t \t  -o-transition: opacity 0.3s linear, right 0.3s ease-out; 
 
\t \t   transition: opacity 0.3s linear, right 0.3s ease-out; 
 
\t } 
 
\t 
 
\t .modal.right.fade.in .modal-dialog { 
 
\t \t right: 0; 
 
\t } 
 

 
/* ----- MODAL STYLE ----- */ 
 
\t .modal-content { 
 
\t \t border-radius: 0; 
 
\t \t border: none; 
 
\t } 
 

 
\t .modal-header { 
 
\t \t border-bottom-color: #EEEEEE; 
 
\t \t background-color: #FAFAFA; 
 
\t } 
 

 
/* ----- v CAN BE DELETED v ----- */ 
 
body { 
 
\t background-color: #78909C; 
 
} 
 

 
.demo { 
 
\t padding-top: 60px; 
 
\t padding-bottom: 110px; 
 
} 
 

 
.btn-demo { 
 
\t margin: 15px; 
 
\t padding: 10px 15px; 
 
\t border-radius: 0; 
 
\t font-size: 16px; 
 
\t background-color: #FFFFFF; 
 
} 
 

 
.btn-demo:focus { 
 
\t outline: 0; 
 
} 
 

 
.demo-footer { 
 
\t position: fixed; 
 
\t bottom: 0; 
 
\t width: 100%; 
 
\t padding: 15px; 
 
\t background-color: #212121; 
 
\t text-align: center; 
 
} 
 

 
.demo-footer > a { 
 
\t text-decoration: none; 
 
\t font-weight: bold; 
 
\t font-size: 16px; 
 
\t color: #fff; 
 
}
<div class="container demo"> 
 
\t 
 
\t 
 
\t <div class="text-center"> 
 
\t \t <button type="button" class="btn btn-demo" data-toggle="modal" data-target="#myModal"> 
 
\t \t \t Left Sidebar Modal 
 
\t \t </button> 
 

 
\t \t <button type="button" class="btn btn-demo" data-toggle="modal" data-target="#myModal2"> 
 
\t \t \t Right Sidebar Modal 
 
\t \t </button> 
 
\t </div> 
 

 
\t <!-- Modal --> 
 
\t <div class="modal left fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> 
 
\t \t <div class="modal-dialog" role="document"> 
 
\t \t \t <div class="modal-content"> 
 

 
\t \t \t \t <div class="modal-header"> 
 
\t \t \t \t \t <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button> 
 
\t \t \t \t \t <h4 class="modal-title" id="myModalLabel">Left Sidebar</h4> 
 
\t \t \t \t </div> 
 

 
\t \t \t \t <div class="modal-body"> 
 
\t \t \t \t \t <p>Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS. 
 
\t \t \t \t \t </p> 
 
\t \t \t \t </div> 
 

 
\t \t \t </div><!-- modal-content --> 
 
\t \t </div><!-- modal-dialog --> 
 
\t </div><!-- modal --> 
 
\t 
 
\t <!-- Modal --> 
 
\t <div class="modal right fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel2"> 
 
\t \t <div class="modal-dialog" role="document"> 
 
\t \t \t <div class="modal-content"> 
 

 
\t \t \t \t <div class="modal-header"> 
 
\t \t \t \t \t <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button> 
 
\t \t \t \t \t <h4 class="modal-title" id="myModalLabel2">Right Sidebar</h4> 
 
\t \t \t \t </div> 
 

 
\t \t \t \t <div class="modal-body"> 
 
\t \t \t \t \t <p>Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS. 
 
\t \t \t \t \t </p> 
 
\t \t \t \t </div> 
 

 
\t \t \t </div><!-- modal-content --> 
 
\t \t </div><!-- modal-dialog --> 
 
\t </div><!-- modal --> 
 
\t 
 
\t 
 
</div><!-- container --> 
 

 
<footer class="demo-footer"> 
 
\t <a href="http://www.bootpen.com" target="_blank">Get more code snippets</a> 
 
</footer>

0

/******************************* 
 
* MODAL AS LEFT/RIGHT SIDEBAR 
 
* Add "left" or "right" in modal parent div, after class="modal". 
 
* Get free snippets on bootpen.com 
 
*******************************/ 
 
\t .modal.left .modal-dialog, 
 
\t .modal.right .modal-dialog { 
 
\t \t position: fixed; 
 
\t \t margin: auto; 
 
\t \t width: 320px; 
 
\t \t height: 100%; 
 
\t \t -webkit-transform: translate3d(0%, 0, 0); 
 
\t \t  -ms-transform: translate3d(0%, 0, 0); 
 
\t \t  -o-transform: translate3d(0%, 0, 0); 
 
\t \t   transform: translate3d(0%, 0, 0); 
 
\t } 
 

 
\t .modal.left .modal-content, 
 
\t .modal.right .modal-content { 
 
\t \t height: 100%; 
 
\t \t overflow-y: auto; 
 
\t } 
 
\t 
 
\t .modal.left .modal-body, 
 
\t .modal.right .modal-body { 
 
\t \t padding: 15px 15px 80px; 
 
\t } 
 

 
/*Left*/ 
 
\t .modal.left.fade .modal-dialog{ 
 
\t \t left: -320px; 
 
\t \t -webkit-transition: opacity 0.3s linear, left 0.3s ease-out; 
 
\t \t -moz-transition: opacity 0.3s linear, left 0.3s ease-out; 
 
\t \t  -o-transition: opacity 0.3s linear, left 0.3s ease-out; 
 
\t \t   transition: opacity 0.3s linear, left 0.3s ease-out; 
 
\t } 
 
\t 
 
\t .modal.left.fade.in .modal-dialog{ 
 
\t \t left: 0; 
 
\t } 
 
     
 
/*Right*/ 
 
\t .modal.right.fade .modal-dialog { 
 
\t \t right: -320px; 
 
\t \t -webkit-transition: opacity 0.3s linear, right 0.3s ease-out; 
 
\t \t -moz-transition: opacity 0.3s linear, right 0.3s ease-out; 
 
\t \t  -o-transition: opacity 0.3s linear, right 0.3s ease-out; 
 
\t \t   transition: opacity 0.3s linear, right 0.3s ease-out; 
 
\t } 
 
\t 
 
\t .modal.right.fade.in .modal-dialog { 
 
\t \t right: 0; 
 
\t } 
 

 
/* ----- MODAL STYLE ----- */ 
 
\t .modal-content { 
 
\t \t border-radius: 0; 
 
\t \t border: none; 
 
\t } 
 

 
\t .modal-header { 
 
\t \t border-bottom-color: #EEEEEE; 
 
\t \t background-color: #FAFAFA; 
 
\t } 
 

 
/* ----- v CAN BE DELETED v ----- */ 
 
body { 
 
\t background-color: #78909C; 
 
} 
 

 
.demo { 
 
\t padding-top: 60px; 
 
\t padding-bottom: 110px; 
 
} 
 

 
.btn-demo { 
 
\t margin: 15px; 
 
\t padding: 10px 15px; 
 
\t border-radius: 0; 
 
\t font-size: 16px; 
 
\t background-color: #FFFFFF; 
 
} 
 

 
.btn-demo:focus { 
 
\t outline: 0; 
 
} 
 

 
.demo-footer { 
 
\t position: fixed; 
 
\t bottom: 0; 
 
\t width: 100%; 
 
\t padding: 15px; 
 
\t background-color: #212121; 
 
\t text-align: center; 
 
} 
 

 
.demo-footer > a { 
 
\t text-decoration: none; 
 
\t font-weight: bold; 
 
\t font-size: 16px; 
 
\t color: #fff; 
 
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script> 
 

 

 
<div class="container demo"> 
 

 
\t <div class="text-center"> 
 
\t \t <button type="button" class="btn btn-demo" data-toggle="modal" data-target="#myModal"> 
 
\t \t \t Left Sidebar Modal 
 
\t \t </button> 
 

 
\t \t <button type="button" class="btn btn-demo" data-toggle="modal" data-target="#myModal2"> 
 
\t \t \t Right Sidebar Modal 
 
\t \t </button> 
 
\t </div> 
 

 
\t <!-- Modal --> 
 
\t <div class="modal left fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> 
 
\t \t <div class="modal-dialog" role="document"> 
 
\t \t \t <div class="modal-content"> 
 

 
\t \t \t \t <div class="modal-header"> 
 
\t \t \t \t \t <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button> 
 
\t \t \t \t \t <h4 class="modal-title" id="myModalLabel">Left Sidebar</h4> 
 
\t \t \t \t </div> 
 

 
\t \t \t \t <div class="modal-body"> 
 
\t \t \t \t \t <p>Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS. 
 
\t \t \t \t \t </p> 
 
\t \t \t \t </div> 
 

 
\t \t \t </div><!-- modal-content --> 
 
\t \t </div><!-- modal-dialog --> 
 
\t </div><!-- modal --> 
 
\t 
 
\t <!-- Modal --> 
 
\t <div class="modal right fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel2"> 
 
\t \t <div class="modal-dialog" role="document"> 
 
\t \t \t <div class="modal-content"> 
 

 
\t \t \t \t <div class="modal-header"> 
 
\t \t \t \t \t <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button> 
 
\t \t \t \t \t <h4 class="modal-title" id="myModalLabel2">Right Sidebar</h4> 
 
\t \t \t \t </div> 
 

 
\t \t \t \t <div class="modal-body"> 
 
\t \t \t \t \t <p>Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS. 
 
\t \t \t \t \t </p> 
 
\t \t \t \t </div> 
 

 
\t \t \t </div><!-- modal-content --> 
 
\t \t </div><!-- modal-dialog --> 
 
\t </div><!-- modal --> 
 
\t 
 
</div><!-- container -->