Rumah > Soal Jawab > teks badan
P粉6048485882023-09-05 00:33:10
Jom cuba pilihan ini. Apakah yang anda tidak suka tentang pendekatan ini?
div { background-color: rgba(0, 0, 0, 0.1); } .button-container { padding: 16px; display: flex; gap: 16px; } .horizontal-button { padding: 16px; flex: 1; text-align: center; word-wrap: hypens; } @media (max-width: 360px) { .button-container { flex-direction: column; } }
<div class="button-container"> <div class="horizontal-button" data-role="yes">Yes</div> <div class="horizontal-button" data-role="no">No, sorry - I cannot make it</div> </div>
J: Dalam kes ini bekas/butang mengambil keseluruhan lebar halaman... mereka tidak menyesuaikan dengan lebar teks.
S: Baiklah, kemudian:
div { background-color: rgba(0, 0, 0, 0.1); } .button-container { margin: auto; padding: 16px; box-sizing: border-box; display: flex; align-items: stretch; gap: 16px; max-width: max-content; } .horizontal-button { display: flex; flex-direction: column; justify-content: center; padding: 16px; flex: 1; text-align: center; max-width: 50%; } @media (max-width: 360px) { .button-container { flex-direction: column; } .horizontal-button { hyphens: auto; max-width: unset; } }
<div class="button-container"> <div class="horizontal-button" data-role="yes">Yes</div> <div class="horizontal-button" data-role="no">No, sorry - I cannot make it</div> </div>