Flex环绕图像

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

Flex wrap around image

问题

我正在尝试定位图片中的第二个文本元素,但似乎无法实现。

目前的排列方式是这样的:文字完全放在图像下方,而不是文本在图像旁边。

英文:

I'm trying to position the second text element in this picture but I can't seem to be able to do it.
Flex环绕图像

The current arrangement is like this:

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

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

.crew-member-card {
  width: 400px;
  background-color: #292929;
  padding-top: 15px;
  border-radius: 8px;
  margin: 10px;
  margin-top: 0;
  text-align: center;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.name-and-profile-picture {
  display: flex;
  align-items: center;
  justify-content: space-evenly;
  flex-wrap: wrap;
}

.pfp {
  width: 100px;
  height: 100px;
  border-radius: 50%;
}

.userNames {
  font-size: 30px;
  font-weight: 900;
  text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.5);
}

.pronouns-position {
  color: #c7c7c7;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.pronouns-position&gt;* {
  margin-right: 5px;
}

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

&lt;div class=&quot;crew-member-card&quot;&gt;
  &lt;div class=&quot;name-and-profile-picture&quot;&gt;
    &lt;p&gt;&lt;img :src=&quot;getProfilePicture(user)&quot; class=&quot;pfp&quot;&gt;&lt;/p&gt;
    &lt;h3 class=&quot;userNames&quot;&gt;{{ user.FirstName }} {{ user.LastName }}&lt;/h3&gt;
    &lt;div class=&quot;pronouns-position&quot;&gt;
      &lt;p class=&quot;pronouns&quot; v-if=&quot;user.memberInfo.pronouns != &#39;Unset&#39;&quot;&gt;
        &lt;font-awesome-icon icon=&quot;fa-solid fa-user&quot; /&gt; {{ user.memberInfo.pronouns.toLowerCase() }}&lt;/p&gt;
      &lt;p class=&quot;division-dot&quot; v-if=&quot;user.memberInfo.pronouns != &#39;Unset&#39;&quot;&gt; • &lt;/p&gt;
      &lt;p class=&quot;position&quot;&gt;{{ user.memberInfo.position.toLowerCase() }}&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->

It results in the text going all the way under the image, rather than under the text and beside the image

答案1

得分: 1

以下是翻译好的部分:

"Grid is by far the best way to arrange this sort of layout. To get you started here's a few resources:

Your layout using grid can be seen below. I've annotated the pertinent bits:

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

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

body {
font-family: Arial, Helvetica, sans-serif;
background-color: #191919;
}

.crew-member-card {
width: 400px;
background-color: #292929;
padding-top: 15px;
border-radius: 8px;
margin: 10px;
margin-top: 0;
text-align: center;
cursor: pointer;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}

.name-and-profile-picture {
display: grid;
grid-template-columns: 1fr 1fr; /* have 2 columns and make them the same width. This will mean the pronouns section will automatically fall on to the next row down*/
align-items: center;
justify-items: center; /* added this */
/*flex-wrap: wrap; removed this */
}

.pfp {
width: 100px;
height: 100px;
border-radius: 50%;
}

.userNames {
color: #E6E6E6;
font-size: 30px;
font-weight: 900;
text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.5);
}

.pronouns-position {
color: #c7c7c7;
grid-column: span 2; /* this spans 2 columns to make it full width /
display: flex; /
make the child elements appear side by side /
justify-content: center; /
and in the center */
}

.pronouns-position>* {
margin-right: 5px;
}

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

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" integrity="sha512-iecdLmaskl7CVkqkXNQ/ZH/XLlvWZOJyj7Yy7tcenmpD1ypASozpmT/E0iPtmFIB46ZmdtAc9eNBvH0H/ZpiBw==" crossorigin="anonymous" referrerpolicy="no-referrer"
/>
<div class="crew-member-card">
<div class="name-and-profile-picture">
<p><img src="https://placekitten.com/200/200" class="pfp"></p>
<h3 class="userNames">Felix Cat</h3>
<div class="pronouns-position">
<p class="pronouns" v-if="user.memberInfo.pronouns != 'Unset'">
<i class="fa-solid fa-user"></i> pronouns
</p>
<p class="division-dot" v-if="user.memberInfo.pronouns != 'Unset'"> • </p>
<p class="position">Position</p>
</div>
</div>
</div>

<!-- end snippet -->

英文:

Grid is by far the best way to arrange this sort of layout. To get you started here's a few resources:

Your layout using grid can be seen below. I've annotated the pertinent bits:

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

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

body {
  font-family: Arial, Helvetica, sans-serif;
  background-color: #191919;
}

.crew-member-card {
  width: 400px;
  background-color: #292929;
  padding-top: 15px;
  border-radius: 8px;
  margin: 10px;
  margin-top: 0;
  text-align: center;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.name-and-profile-picture {
  display: grid;
  grid-template-columns: 1fr 1fr; /* have 2 columns and make them the same width. This will mean the pronouns section will automatically fall on to the next row down*/
  align-items: center;
  justify-items: center; /* added this */
  /*flex-wrap: wrap; removed this */
}

.pfp {
  width: 100px;
  height: 100px;
  border-radius: 50%;
}

.userNames {
  color: #E6E6E6;
  font-size: 30px;
  font-weight: 900;
  text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.5);
}

.pronouns-position {
  color: #c7c7c7;
  grid-column: span 2; /* this spans 2 columns to make it full width */
  display: flex; /* make the child elements appear side by side */
  justify-content: center; /* and in the center */
}

.pronouns-position&gt;* {
  margin-right: 5px;
}

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

&lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css&quot; integrity=&quot;sha512-iecdLmaskl7CVkqkXNQ/ZH/XLlvWZOJyj7Yy7tcenmpD1ypASozpmT/E0iPtmFIB46ZmdtAc9eNBvH0H/ZpiBw==&quot; crossorigin=&quot;anonymous&quot; referrerpolicy=&quot;no-referrer&quot;
/&gt;
&lt;div class=&quot;crew-member-card&quot;&gt;
  &lt;div class=&quot;name-and-profile-picture&quot;&gt;
    &lt;p&gt;&lt;img src=&quot;https://placekitten.com/200/200&quot; class=&quot;pfp&quot;&gt;&lt;/p&gt;
    &lt;h3 class=&quot;userNames&quot;&gt;Felix Cat&lt;/h3&gt;
    &lt;div class=&quot;pronouns-position&quot;&gt;
      &lt;p class=&quot;pronouns&quot; v-if=&quot;user.memberInfo.pronouns != &#39;Unset&#39;&quot;&gt;
        &lt;i class=&quot;fa-solid fa-user&quot;&gt;&lt;/i&gt; pronouns
      &lt;/p&gt;
      &lt;p class=&quot;division-dot&quot; v-if=&quot;user.memberInfo.pronouns != &#39;Unset&#39;&quot;&gt; • &lt;/p&gt;
      &lt;p class=&quot;position&quot;&gt;Position&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年5月22日 21:10:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76306553.html
匿名

发表评论

匿名网友

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

确定