I’m trying to create a button that looks like this using html. I want the button to look like one is on top of the other, not just two rectangles next to each other (so the rounded edges/border-radius is important).
If it helps, I’m looping over a list of documents and displaying them as buttons in this format. It needs to be able to adjust its’ width for different document names/extensions. I don’t want the .pdf/.docx to be covered if the document name is too long.
I started by creating two buttons and having each on a different z-index, but I’m wondering if there’s a better way to do this.
Is there a way to dynamically size two buttons so that they appear overlapping like this, but are able to adjust their location/width so their text is still visible?
I’m sure this is a simple fix – but I’m stuck
<button style="position: absolute; padding: 10px 20px; background-color: darkgray; border-radius: 15px; border: none; z-index: 1;">Document</button>
<button style="position: absolute; padding: 10px 50px; background-color: gray; border-radius: 15px; border: none; z-index: 0;">.pdf</button>
5
Answers
Use a single
button
but wrap the document name in aspan
, then you can apply different styling to the document name and the button itself.You can put everything inside 1 element and control the children with display:flex.
I try to make this for you, but only the style. You still need the link and href, etc.
You definitely don’t want two buttons unless you want a different behavior based on whether a user clicks one side or the other. Many solid ways to do this, here’s my approach:
you can use pseudo :befor element instead of two buttons