移动视图中弹性项目之间的空间过大。

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

Too much space-around between flex items in mobile view

问题

You can reduce the space between flex items in mobile view by adding the following CSS code:

@media (max-width: 768px) { /* Adjust the max-width as needed */
  .index-page-flexcon1 {
    justify-content: center; /* Center the items horizontally */
  }

  .index-page-flexcon1 .flexbox-item-1 {
    margin-bottom: 20px; /* Add margin to create space between title and description */
  }
}

This code targets screens with a maximum width of 768 pixels (typical for mobile devices) and adjusts the layout accordingly, reducing the space between the app title and description in the .index-page-flexcon1 container. You can adjust the max-width value as needed for your specific mobile breakpoint.

英文:

how to reduced the space between the flex items in mobile view? I already use gap or margin in flex items but still no luck. Here is my code for your reference. Thankyou

移动视图中弹性项目之间的空间过大。

I am expecting to reduce the space between the app title and description and my login form for mobile view only, it works fine in desktop view. Thankyou

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

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

* {
  box-sizing: border-box;
}

body {
  width: 100vw;
  height: 100vh;
  margin: 0;
  padding: 0;
  background-color: #181818;
  font-family: &#39;Poppins&#39;, sans-serif;
}

.flexbox-container {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
}

.form-group {
  margin: 10px 0;
}

input[type=&quot;text&quot;],
input[type=&quot;password&quot;] {
  width: 100%;
  padding: 12px;
  border: 1px solid #dadada;
  border-radius: 6px;
  font-size: 16px;
  outline: none;
  font-family: &#39;Open Sans&#39;, sans-serif;
}

input[type=&quot;text&quot;]:focus,
input[type=&quot;password&quot;]:focus {
  border: 1px solid #0066cc;
}

button {
  font-size: 15px;
  font-weight: 800;
}

.btn-info {
  border: 1px solid #2157eb;
  background-color: #2157eb;
  color: #fff;
}

.btn-success {
  border: 1px solid #1fa167;
  background-color: #1fa167;
  color: #fff;
}

.btn-link {
  text-decoration: none;
  font-size: 15px;
  font-weight: 400;
  color: #0066cc;
}

hr {
  border: none;
  border-bottom: 1px solid #cfcfcf;
  margin: 15px 0;
}

.index-page-flexcon1 {
  width: 100%;
  height: 100%;
  padding: 20px;
  gap: 40px;
  align-items: center;
  justify-content: space-around;
}

.index-page-flexcon1 .flexbox-item-1 {
  max-width: 380px;
  text-align: center;
}

.index-page-flexcon1 .flexbox-item-1 h1 {
  margin: 0;
  -webkit-text-fill-color: transparent;
  -webkit-background-clip: text;
  background-image: -webkit-linear-gradient(0deg, #3496e6 30%, #a465d9 70%);
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}

.index-page-flexcon1 .flexbox-item-1 p {
  color: #c4c4c4;
}

.index-page-flexcon1 .flexbox-item-2 {
  width: 300px;
  padding: 20px;
  border: 1px solid #f3f3f3;
  border-radius: 6px;
  background-color: #f3f3f3;
  text-align: center;
}

.index-page-flexcon1 .flexbox-item-2 .btn-info {
  width: 100%;
  padding: 10px;
}

.index-page-flexcon1 .flexbox-item-2 .btn-success {
  padding: 8px 16px;
  margin-top: 10px;
  border-radius: 20px;
}

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

&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot;&gt;

&lt;head&gt;
  &lt;meta charset=&quot;UTF-8&quot;&gt;
  &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&gt;
  &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0, interactive-widget=resizes-content&quot;&gt;

  &lt;link rel=&quot;preload&quot; href=&quot;assets/css/style.css?version=&lt;?php echo rand(0, 100); ?&gt;&quot; as=&quot;style&quot; onload=&quot;this.onload=null; this.rel=&#39;stylesheet&#39;;&quot;&gt;
  &lt;noscript&gt;&lt;link rel=&quot;stylesheet&quot; href=&quot;assets/css/style.css?version=&lt;?php echo rand(0, 100); ?&gt;&quot;&gt;&lt;/noscript&gt;

  &lt;!-- boxicons link --&gt;
  &lt;link href=&#39;https://unpkg.com/boxicons@2.1.4/css/boxicons.min.css&#39; rel=&#39;stylesheet&#39;&gt;
  &lt;title&gt;WeChitChat&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
  &lt;div class=&quot;flexbox-container index-page-flexcon1&quot;&gt;
    &lt;div class=&quot;flexbox-item-1&quot;&gt;
      &lt;h1&gt;WeChitChat&lt;/h1&gt;
      &lt;p&gt;
        &lt;span class=&quot;icon&quot;&gt;&lt;i class=&#39;bx bxs-heart&#39;&gt;&lt;/i&gt;&lt;/span&gt; Simple,
        &lt;span class=&quot;icon&quot;&gt;&lt;i class=&#39;bx bxs-zap&#39;&gt;&lt;/i&gt;&lt;/span&gt; Fast and
        &lt;span class=&quot;icon&quot;&gt;&lt;i class=&#39;bx bxs-check-shield&#39;&gt;&lt;/i&gt;&lt;/span&gt; Secured. Stay connected to your friends and family
        &lt;span class=&quot;special-text&quot;&gt;Anytime, Anywhere.&lt;/span&gt;
      &lt;/p&gt;
    &lt;/div&gt;
    &lt;div class=&quot;flexbox-item-2&quot;&gt;
      &lt;form action=&quot;&quot;&gt;
        &lt;div class=&quot;form-group&quot;&gt;
          &lt;input type=&quot;text&quot; name=&quot;&quot; id=&quot;&quot; placeholder=&quot;Username&quot;&gt;
        &lt;/div&gt;
        &lt;div class=&quot;form-group&quot;&gt;
          &lt;input type=&quot;password&quot; name=&quot;&quot; id=&quot;&quot; placeholder=&quot;Password&quot;&gt;
        &lt;/div&gt;
        &lt;div class=&quot;form-group&quot;&gt;
          &lt;button type=&quot;submit&quot; class=&quot;btn-info&quot;&gt;Log In&lt;/button&gt;
        &lt;/div&gt;
        &lt;div class=&quot;form-group&quot;&gt;
          &lt;hr&gt;
          &lt;a href=&quot;#&quot; class=&quot;btn-link&quot;&gt;Forgot your password?&lt;/a&gt;&lt;br/&gt;
          &lt;button type=&quot;button&quot; class=&quot;btn-success&quot;&gt;Register an account&lt;/button&gt;
        &lt;/div&gt;
      &lt;/form&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/body&gt;

&lt;/html&gt;

<!-- end snippet -->

答案1

得分: 0

你可以通过添加align-content属性来实现(用于在项目换行时 — 只有通过添加flex-wrap: wrap才能实现):

.index-page-flexcon1 {
    flex-wrap: wrap;
    align-content: center;
}

(其他选项包括align-content: flex-start等。)

英文:

You can do it by adding the align-content property (for when items wrap — which they can only do by adding flex-wrap: wrap):

.index-page-flexcon1 {
    flex-wrap: wrap;
    align-content: center;
}

(Other options include align-content: flex-start etc.)

huangapple
  • 本文由 发表于 2023年5月25日 12:04:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76328855.html
匿名

发表评论

匿名网友

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

确定