所有帖子都在Bootstrap网格系统的左侧。

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

All posts are left side left side in Bootstrap Grid system

问题

我使用React.js中的Bootstrap制作了相册。帖子是通过Bootstrap网格系统显示的。
所有帖子都在左侧,但我想使它们居中。我不知道如何使它们居中。

在justify-content-center之后

在从.top_post中删除margin: 10px;之后

在从.top_post CSS中删除width: 250px;之后

CSS

.top_hello {
text-align: right;
margin: 20px 0 0 0;
}

.top_search {
margin: 20px 0 20px 0;
justify-content: right;
}

.top_search_input {
display: flex;
margin-right: 0;
margin-left: auto;
}

.top_post {
/* position: relative; */
background: lightgreen;
padding: 15px;
border-radius: 10px;
margin-bottom: 30px;
width: 250px;
height: 400px;
margin: 10px;
}

.top_post_photo {
object-fit: cover;
width: 200px;
height: 200px;
}

JSX

Hello Hiroko!



<>
{post.map((item, i) => (

{item.photo &&

所有帖子都在Bootstrap网格系统的左侧。

}
{item.photo2 &&

所有帖子都在Bootstrap网格系统的左侧。

}
{item.photo3 &&

所有帖子都在Bootstrap网格系统的左侧。

}
{item.photo4 &&

所有帖子都在Bootstrap网格系统的左侧。

}
{item.photo5 &&

所有帖子都在Bootstrap网格系统的左侧。

}

Title: {item.title}

Condition: {item.condition_name}

      <Link to={`/post/${item.id}`} className='btn btn-secondary'>Detail</Link>
    </div>
  ))}
</div>

英文:

I make gallery by using Bootstrap in React.js. Posts are displays by bootstrap grid system.
All posts are left side but I want make center it. I don't have idea how I make them center.

所有帖子都在Bootstrap网格系统的左侧。

After justify-content-center

所有帖子都在Bootstrap网格系统的左侧。

After removing margin: 10px; from .top_post

所有帖子都在Bootstrap网格系统的左侧。

After removing width: 250px; from .top_post CSS

所有帖子都在Bootstrap网格系统的左侧。

xxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxx

xxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxx

CSS

.top_hello {
  text-align: right;
  margin: 20px 0 0 0;
}

.top_search {
  margin: 20px 0 20px 0;
  justify-content: right;
}

.top_search_input {
  display: flex;
  margin-right: 0;
  margin-left: auto;
}


.top_post {
  /* position: relative; */
  background:lightgreen; 
  padding:15px;
  border-radius: 10px;
  margin-bottom: 30px;
  width: 250px;
  height: 400px;
  margin: 10px;
}

.top_post_photo {
  object-fit: cover;
  width: 200px;
  height: 200px;
}

JSX

&lt;div className=&quot;container&quot;&gt;
    &lt;div className=&quot;row text-center&quot;&gt;
        &lt;p className=&quot;top_hello&quot;&gt;Hello Hiroko!&lt;/p&gt;
        &lt;div className=&quot;top_search col-12&quot;&gt;
            &lt;form className=&quot;top_search_input form-inline col-4&quot; onSubmit={handleSubmit(getSearchResult)}&gt;
            &lt;input placeholder=&quot;Search Title or Maker&quot; className=&#39;form-control&#39; {...register(&#39;search&#39;, { required: true })} /&gt;
            &lt;input className=&#39;btn btn-secondary&#39; type=&quot;submit&quot; value=&quot;Search&quot; /&gt;
            &lt;/form&gt;
        &lt;/div&gt;
        &lt;&gt;
            {post.map((item,i) =&gt; (
              &lt;div key={i} className=&quot;top_post col-6 col-lg-3&quot;&gt;
                &lt;div className=&quot;slideshow-container&quot;&gt;
                  {item.photo &amp;&amp;
                  &lt;div className=&quot;mySlides fade&quot;&gt;
                    &lt;img className=&quot;top_post_photo&quot; src={item.photo} /&gt;
                  &lt;/div&gt;
                  }
                  {item.photo2 &amp;&amp;
                  &lt;div className=&quot;mySlides fade&quot;&gt;
                    &lt;img className=&quot;top_post_photo&quot; src={item.photo2} /&gt;
                  &lt;/div&gt;
                  }
                  {item.photo3 &amp;&amp;
                  &lt;div className=&quot;mySlides fade&quot;&gt;
                    &lt;img className=&quot;top_post_photo&quot; src={item.photo3} /&gt;
                  &lt;/div&gt;
                  }
                  {item.photo4 &amp;&amp;
                  &lt;div className=&quot;mySlides fade&quot;&gt;
                    &lt;img className=&quot;top_post_photo&quot; src={item.photo4} /&gt;
                  &lt;/div&gt;
                  }&#207;
                  {item.photo5 &amp;&amp;
                  &lt;div className=&quot;mySlides fade&quot;&gt;
                    &lt;img className=&quot;top_post_photo&quot; src={item.photo5} /&gt;
                  &lt;/div&gt;
                  }
                  &lt;a className=&quot;prev&quot; onclick=&quot;plusSlides(-1)&quot;&gt;&amp;#10094;&lt;/a&gt;
                  &lt;a className=&quot;next&quot; onclick=&quot;plusSlides(1)&quot;&gt;&amp;#10095;&lt;/a&gt;
                &lt;/div&gt;
                &lt;p&gt;Title: {item.title}&lt;/p&gt;
                &lt;p&gt;Condition: {item.condition_name}&lt;/p&gt;
        
                &lt;Link to={`/post/${item.id}`} className=&#39;btn btn-secondary&#39;&gt;Detail&lt;/Link&gt;
              &lt;/div&gt;
            ))}
    &lt;/div&gt;
&lt;/div&gt; 

答案1

得分: 0

只需将justify-content-center类与row一起添加。

codepen

英文:

You just need to add justify-content-center class along with row.

codepen

huangapple
  • 本文由 发表于 2023年2月10日 12:24:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/75406929.html
匿名

发表评论

匿名网友

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

确定