CSS implements horizontal buttons without other techniques
P粉893457026
2023-09-04 12:29:02
<p>I'm trying to create two horizontal buttons that are the same width - based on the width of the longest button. </p>
<ul>
<li>The text content of each button can be adjusted by the user on a separate page...so I have no control over their text length/the text length of the first button and the second button. </li>
<li>I want the button to adjust to the length of the longest text, but not exceed the width of the page (like on mobile devices). </li>
<li>I want the buttons to appear horizontally by default, but if they don't appear horizontally, stacked as columns. </li>
<li>I need the button's text to wrap if the entire text won't fit. </li>
</ul>
<pre class="brush:php;toolbar:false;"><div class="button-container">
<div class="horizontal-button" data-role="yes">Yes</div>
<div class="horizontal-button" data-role="no">No, sorry - I can't do that</div>
</div></pre>
<p>I tried various options...but can't get it to work! </p>
<ul>
<li>When using grid layout grid-template-colums: 1fr 1fr, I can't find a way to stack the buttons into columns when needed. </li>
<li>I can't find a way to make the width of the button fit the length of the text when using flex and flex:1 1 0. </li>
</ul>
<p>Please help! </p>
<p>Thank you very much!
Damian. </p>
Let's try this option. What do you dislike about this approach?
A: In this case the container/button takes up the entire width of the page... they don't adjust to the width of the text.
Q: Okay, then: