为什么我的SVG图标在输入框旁边的部分没有显示?

huangapple go评论54阅读模式
英文:

why my svg icon is not show in a section next to input?

问题

我的图标未显示。 但如果我将输入字段的宽度从100%减少到90%,然后它就会显示。 我做错了什么?

<section class="flex jc">
  <svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 512 512" color="#333" style="color:#333" height="15" width="15" xmlns="http://www.w3.org/2000/svg"><path fill="none" stroke-miterlimit="10" stroke-width="32" d="M221.09 64a157.09 157.09 0 10157.09 157.09A157.1 157.1 0 00221.09 64z"></path><path fill="none" stroke-linecap="round" stroke-miterlimit="10" stroke-width="32" d="M338.29 338.29L448 448"></path></svg>
  <input type="text" name="search">
</section>
英文:

my icon is not showing. But if I reduce the width of my input field from 100% to 90% then it shows. What I am doing wrong ?

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.flex {
  display: flex;
  align-items: center;
}

.jc {
  justify-content: center;
}

<!-- language: lang-html -->

&lt;section class=&quot;flex jc&quot;&gt;
  &lt;svg stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; viewBox=&quot;0 0 512 512&quot; color=&quot;#333&quot; style=&quot;color:#333&quot; height=&quot;15&quot; width=&quot;15&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path fill=&quot;none&quot; stroke-miterlimit=&quot;10&quot; stroke-width=&quot;32&quot; d=&quot;M221.09 64a157.09 157.09 0 10157.09 157.09A157.1 157.1 0 00221.09 64z&quot;&gt;&lt;/path&gt;&lt;path fill=&quot;none&quot; stroke-linecap=&quot;round&quot; stroke-miterlimit=&quot;10&quot; stroke-width=&quot;32&quot; d=&quot;M338.29 338.29L448 448&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
  &lt;input type=&quot;text&quot; name=&quot;search&quot;&gt;
&lt;/section&gt;

<!-- end snippet -->

答案1

得分: 1

将图标的宽度设置为15像素,将输入字段的宽度设置为100%减去15像素。

.icon {
  width: 15px;
}

input {
  width: calc(100% - 15px);
}

这段代码将图标的宽度设置为15像素,然后使用CSS calc 函数将输入字段的宽度设置为100%减去15像素。

英文:

set the icon width to 15px and the input field width to 100% - 15px

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.flex {
  display: flex;
  align-items: center;
}

.jc {
  justify-content: center;
}

.icon {
  width: 15px;
}

input {
  width: calc(100% - 15px);
}

<!-- language: lang-html -->

&lt;section class=&quot;flex jc&quot;&gt;
  &lt;svg class=&quot;icon&quot; stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; viewBox=&quot;0 0 512 512&quot; color=&quot;#333&quot; style=&quot;color:#333&quot; height=&quot;15&quot; width=&quot;15&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path fill=&quot;none&quot; stroke-miterlimit=&quot;10&quot; stroke-width=&quot;32&quot; d=&quot;M221.09 64a157.09 157.09 0 10157.09 157.09A157.1 157.1 0 00221.09 64z&quot;&gt;&lt;/path&gt;&lt;path fill=&quot;none&quot; stroke-linecap=&quot;round&quot; stroke-miterlimit=&quot;10&quot; stroke-width=&quot;32&quot; d=&quot;M338.29 338.29L448 448&quot;&gt;&lt;/path&gt;&lt;/svg&gt;
  &lt;input type=&quot;text&quot; name=&quot;search&quot;&gt;
&lt;/section&gt;

<!-- end snippet -->

答案2

得分: -1

你的SVG图标已经在section标签中。

英文:

Your SVG Icon is already in section tag

huangapple
  • 本文由 发表于 2023年2月18日 20:40:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/75493406.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定