英文:
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) => (
英文:
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.
After justify-content-center
After removing margin: 10px; from .top_post
After removing width: 250px; from .top_post CSS
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
<div className="container">
<div className="row text-center">
<p className="top_hello">Hello Hiroko!</p>
<div className="top_search col-12">
<form className="top_search_input form-inline col-4" onSubmit={handleSubmit(getSearchResult)}>
<input placeholder="Search Title or Maker" className='form-control' {...register('search', { required: true })} />
<input className='btn btn-secondary' type="submit" value="Search" />
</form>
</div>
<>
{post.map((item,i) => (
<div key={i} className="top_post col-6 col-lg-3">
<div className="slideshow-container">
{item.photo &&
<div className="mySlides fade">
<img className="top_post_photo" src={item.photo} />
</div>
}
{item.photo2 &&
<div className="mySlides fade">
<img className="top_post_photo" src={item.photo2} />
</div>
}
{item.photo3 &&
<div className="mySlides fade">
<img className="top_post_photo" src={item.photo3} />
</div>
}
{item.photo4 &&
<div className="mySlides fade">
<img className="top_post_photo" src={item.photo4} />
</div>
}Ï
{item.photo5 &&
<div className="mySlides fade">
<img className="top_post_photo" src={item.photo5} />
</div>
}
<a className="prev" onclick="plusSlides(-1)">&#10094;</a>
<a className="next" onclick="plusSlides(1)">&#10095;</a>
</div>
<p>Title: {item.title}</p>
<p>Condition: {item.condition_name}</p>
<Link to={`/post/${item.id}`} className='btn btn-secondary'>Detail</Link>
</div>
))}
</div>
</div>
答案1
得分: 0
只需将justify-content-center
类与row
一起添加。
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
- bootstrap-4
- css
- html
- reactjs
评论