2017-02-07 112 views
0

我正在試圖在圓形窗體中創建一個bootstrap模態。已經創建了一個,但我的問題是我如何可以響應式地插入圓形模式中的文本?Bootstrap Circle Modal

<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/2.1.1/jquery.min.js"></script> 
 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
 

 
<style> 
 
    .modal-content { 
 
    background-color: #0099FF; 
 
    position: relative; 
 
    border-radius: 50%; 
 
    width: 100%; 
 
    height: auto; 
 
    padding-top: 100%; 
 
    } 
 
</style> 
 

 

 
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal"> 
 
    Modal 
 
</button> 
 

 
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> 
 
    <div class="modal-dialog" role="document"> 
 
    <div class="modal-content"> 
 
    </div> 
 
    </div> 
 
</div>

回答

1

Flex box會幫助你,並且我刪除了padding-top推動內容在底部。對於身高我已使用height:100vwmax-height:600px,這將使框正確的圓形狀。

<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/2.1.1/jquery.min.js"></script> 
 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
 

 

 
<style> 
 
    .modal-content { 
 
    background-color: #0099FF; 
 
    position: relative; 
 
    border-radius: 50%; 
 
    width: 100%; 
 
    height: 100vw; 
 
    display: flex; 
 
    justify-content: center; 
 
    align-items: center; 
 
    max-height: 600px; 
 
    } 
 
</style> 
 

 

 
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal"> 
 
    Modal 
 
</button> 
 

 
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> 
 
    <div class="modal-dialog" role="document"> 
 
    <div class="modal-content"> 
 
     Content 
 
    </div> 
 
    </div> 
 
</div>

+1

幫了我很多! – Duplicated

+0

很高興!我可以幫忙。 –

+0

我可以再問一下有關Flexbox的事嗎?爲什麼不是我的Firefox支持語法?已經添加了 「 顯示:-webkit-FLEX; 顯示:-webkit-箱; 顯示:-moz-箱; 顯示:-MS-Flexbox的; 顯示:彎曲; 」 – Duplicated

1

追加一個div來model-content並給它position:absolute並將其定位是在中心

<style> 
    .modal-content { 
     background-color: #0099FF; 
     position: relative; 
     border-radius: 50%; 
     width: 100%; 
     height: auto; 
     padding-top: 100%; 
    } 
    #text { 
    position: absolute; 
    top:50%; 
    left:45%; 
    } 
</style> 


<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal"> 
    Modal 
</button> 

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> 
    <div class="modal-dialog" role="document"> 
     <div class="modal-content"> 
     <div id="text">Lorem ipsum</div> 
     </div> 
    </div> 
</div> 

下面是一個例子:http://www.bootply.com/kBT3elyYFV