I have four SVG shapes that I am using as text boxes containing a description of courses people can book. At the bottom of the text boxes I want two buttons that have the option to see more information on the course or to book the course. I have tried to create a "foreign object" tag nested in the SVG tags in my html code but this didn’t work. I then created button tags that aren’t in my SVG tags thinking that I could move the buttons on top of the SVG and just position them so they look contained in the SVG but this has moved the SVG to a different position and I am unsure how to make this collection of elements responsive to different screen sizes. I am a little unsure of what to do from here.
This is the code I have for one of the SVG text boxes:
button.home-course-button {
position:relative;
left: 215px;
bottom: 25px;
border-radius: 15px;
height: 44px;
width: 110px;
}
<svg xmlns="http://www.w3.org/2000/svg" width="359" height="375" viewBox="0 0 359 375" fill="none" transform="translate(113 40)">
<path d="M2 251.976V306.41M2 306.41V2H274.688L357 75.9886L357 373H84.5L2 306.41Z" stroke="url(#paint0_linear_71_5)" stroke-width="4"/>
<defs>
<linearGradient id="paint0_linear_71_5" x1="179.5" y1="2" x2="179.5" y2="373" gradientUnits="userSpaceOnUse">
<stop stop-color="#37E492"/>
<stop offset="1" stop-color="#008B4A"/>
</linearGradient>
</defs>
<text text-anchor="left" fill="#000000" font-size="31.8px" font-family="Mako" font-weight="400" font-style="normal" x="150" y="38">
</text>
</svg>
<div>
<button class="button home-course-button"><p>See More</p></button>
<button class="button home-course-button"><p>Book</p></button>
</div>
I am open to suggestions on easier ways to achieve the same effect as well.
2
Answers
Yes, you can nest a button in an SVG by embedding HTML elements within a tag. This allows you to include standard HTML within an SVG. Here’s a simple example to illustrate this:
.
Remember to adjust the x, y, width, and height attributes as needed to position and size the button appropriately within your SVG.
If you have any specific requirements or further question
You can use the SVG as a CSS background image.
Here, I have the SVG as a data URL, but you could also just refer to a SVG file.