4
<div class="ui left icon input">
  <input placeholder="Search users..." type="text">
  <i class="users icon"></i>
</div>

In the above code from https://semantic-ui.com/elements/input.html, how do I use my own src="../my-images/image-01.svg" instead of the users icon there?

Here's the SVG file content BTW:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 1000 1000" enable-background="new 0 0 1000 1000" xml:space="preserve">
<g><path fill="dark gray" d="M963.1,833.6L704.8,575.3c0,0,0,0-6.1,0c30.7-61.5,49.2-123,49.2-190.6c0-202.9-166-368.9-368.9-368.9S10,181.8,10,384.7c0,202.9,166,368.9,368.9,368.9c67.6,0,135.3-18.4,190.6-55.3l0,0l258.2,258.2c36.9,36.9,92.2,36.9,129.1,0C999.9,925.8,999.9,870.5,963.1,833.6z M133,384.7c0-135.3,110.7-245.9,245.9-245.9c135.3,0,245.9,110.7,245.9,245.9c0,135.3-110.7,246-245.9,246C243.7,630.7,133,520,133,384.7z"/></g>
</svg>
user1946932
  • 474
  • 1
  • 16
  • 41

2 Answers2

3

Here's a JSFiddle: https://jsfiddle.net/ChefGabe/oeoq9urj/

This solution only works if you're serving the SVG from the same origin.

If you're serving your SVG cross-origin (like a CDN), you'll need a workaround.

HTML

<div class="ui left icon input">
    <input placeholder="Search users..." type="text">
    <i class="icon"><svg><use href="../my-images/image-01.svg"></use></svg></i>
</div>

CSS

svg {
    height: 19px;
    width: 19px;
    margin-top: 9px;
}
Community
  • 1
  • 1
Gabe Rogan
  • 3,343
  • 1
  • 16
  • 22
0

I am using Fomantic.ui a later iteration of Semantic.ui, and the fontawesome icon library. Because fontawesome substitutes an "i" tag by a "svg", all expected css rules are not shown. My solution is to create a fake icon tag wrapping the actual one.:

    <i class="middle aligned icon">
      <i class="fa-solid fa-location-dot fa-lg "></i>
    </i>

Once compiled, the html is keeping an "i" tag for rules and generates the "svg" as this:

<i class="middle aligned icon">
  <svg class="svg-inline--fa fa-location-dot fa-lg" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="location-dot" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512" data-fa-i2svg=""><path fill="currentColor" d="M215.7 499.2C267 435 384 279.4 384 192C384 86 298 0 192 0S0 86 0 192c0 87.4 117 243 168.3 307.2c12.3 15.3 35.1 15.3 47.4 0zM192 128a64 64 0 1 1 0 128 64 64 0 1 1 0-128z"></path></svg>
  <!-- <i class="fa-solid fa-location-dot fa-lg "></i> -->
</i>
PedroSP
  • 1
  • 1