簡體   English   中英

如何將按鈕內的圖標居中對齊?

[英]How to center align icon inside button?

 .close-button button { border: 1px solid black; border-radius: 50%; height: 25px; width: 25px; outline: none; } .close-button { margin-right: 50%; margin-top: 7%; /* I wrote to center the button */ } 
 <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css" integrity="sha384-Smlep5jCw/wG7hdkwQ/Z5nLIefveQRIY9nfy6xoR1uRYBtpZgI6339F5dgvm/e9B" crossorigin="anonymous"> <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/js/bootstrap.min.js" integrity="sha384-o+RDsa0aLu++PJvFqy8fFScvbHFLtbvScb8AjopnFD+iEQ7wo/CG0xlczd+2O/em" crossorigin="anonymous"></script> <button type="button" data-toggle="modal" data-target="#exampleModal" class="btn btn-success">Click</button> <div class="modal" id="exampleModal"> <div class="modal-dialog"> <div class="modal-content" style="height:100px;"> <div class="close-button"> <button type="button" class="close" data-dismiss="modal">&times;</button> </div> </div> </div> </div> 

例:

https://www.w3schools.com/code/tryit.asp?filename=FTCZIK9F0A66

文本對齊:居中或行高:50%不起作用。 如何解決? 謝謝。

添加以下類

<div class="close-button h-100 d-flex align-items-center justify-content-center">
    <button type="button" class="close" data-dismiss="modal">&times;</button>
</div>

添加font-size: 20px; 在按鈕上

 <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css" integrity="sha384-Smlep5jCw/wG7hdkwQ/Z5nLIefveQRIY9nfy6xoR1uRYBtpZgI6339F5dgvm/e9B" crossorigin="anonymous"> <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/js/bootstrap.min.js" integrity="sha384-o+RDsa0aLu++PJvFqy8fFScvbHFLtbvScb8AjopnFD+iEQ7wo/CG0xlczd+2O/em" crossorigin="anonymous"></script> <button type="button" data-toggle="modal" data-target="#exampleModal" class="btn btn-success">Click</button> <style> .close-button button { border: 1px solid black; border-radius: 50%; height: 25px; width: 25px; outline: none; color: black; font-size: 20px; } </style> <div class="modal" id="exampleModal"> <div class="modal-dialog"> <div class="modal-content" style="height:100px;"> <div class="close-button h-100 d-flex align-items-center justify-content-center"> <button type="button" class="close" data-dismiss="modal">&times;</button> </div> </div> </div> </div> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM