#Struggling with making a button behave
18 messages · Page 1 of 1 (latest)
This is what I'm trying to recreate
Goes without saying I'm an absolute beginner at coding
This is how I'd personally do it:
<a href="/" class="flex flex-auto">
<button class="border border-gray-300 rounded-lg py-2 px-4 w-max flex items-center">
<span class="mr-2">title</span>
<AiFillPlusCircle />
</button>
</a>
Obviously update the href, title and icon (replace my <AiFillPlusCircle /> with your svg)
TLDR is a flex flex-auto on the parent should help
I'd personally set rounded-xl instead of rounded-lg too if I was trying to get a better match on roundness but obviously personal preference
Hey @spare turret , just copied your code and somehow I'm getting the same issue
well it's not really the same issue, it's beside it now rather than below. The issue now is that your svg is too large so it's squishing the other content. You'll need to scale it down a bit which is something I wouldn't be too familiar with as I never use svg's but use React-Icons or other means to import graphics. A quick google on how to modify the size of SVGs would help, or even attempt to add a class via tailwind to see if that helps
If you wanna share the svg code with me I can take a crack at it
<svg width="100%" height="1em" stroke-width="1.5" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" color="var(--token-cdc990fc-1a39-492b-80a6-e13af03045cf, rgb(25, 25, 26)) /* {"name":"Black"} */" style="width: 100%; height: 100%;">
<path d="M6 12h12.5m0 0l-6-6m6 6l-6 6" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"></path>
</svg>
I was able to resize the svg using "transform" but the text won't flow in a single line
The problem is that your button is using 100% of the width. Just define a width of 1-2 rem, and height the same (or aspect-ratio of 1)
And for the text, since it's inline, you need to do white-space: nowrap, since text's default behavior is to wrap when a word is going to cut (or enlarge the button's horizontal (inline) padding) for it to fit
I think buttons inside anchors, or anchors inside buttons are not valid HTML, you could style both and make it work, buuut...
If you put everything inside a <button> or a <a> with all the style classes, it will probably work
yeah what said porfirio is correct, even more so, you don't need to make a button to style an anchor, just style the anchor, they both have default HTML behaviors
@outer osprey @unkempt bridge hey thanks guys, I tried the same code but I still had the same issue. Strangely what fixed it for me was the "style" parameter inside the svg.
Now it's behaving as intended.
Looks like it was over-riding the style somehow, I got rid of it and still have the same result. 😅