简体   繁体   English

如何在位置:固定的情况下彼此相邻显示4个div元素?

[英]How to display 4 div elements next to each other while position: fixed?

So I'm trying to make 4 boxes fixed in the bottom middle of the page. 因此,我试图在页面的底部中间固定4个框。 But When I apply position: Fixed; 但是当我申请position: Fixed; to them, they just become one stacked box. 对他们来说,它们只是变成一个堆叠的盒子。

 .g{ height: 70px; width: 70px; background-color: black; margin: 5px; position: fixed; bottom: 15%; } 
 <div class="groups"> <div class="g g1"></div> <div class="g g2"></div> <div class="g g3"></div> <div class="g g4"></div> </div> 

What I want is this: 我想要的是: 在此处输入图片说明

Make outer div fixed then inner 4 div element will show next to each other. 使外部div fixed然后内部4 div元素将彼此相邻显示。

  .groups { display: flex; display: -webkit-flex; position: fixed; margin: 0 auto; left: 0; right: 0; justify-content: space-around; max-width: 500px; } .g{ height: 70px; width: 70px; background-color: black; margin: 5px; } 
  <div class="groups"> <div class="g g1"></div> <div class="g g2"></div> <div class="g g3"></div> <div class="g g4"></div> </div> 

Otherwise you can do it with flex: 否则,您可以使用flex来做到这一点:

 .g{ height: 70px; width: 70px; background-color: black; margin: 5px; } .groups { display: flex; justify-content: space-between; width: 400px } 
 <div class="groups"> <div class="g g1"></div> <div class="g g2"></div> <div class="g g3"></div> <div class="g g4"></div> </div> 

Try this fiddle 试试这个小提琴

Fiddle here 在这里摆弄

.groups{
 position: fixed;
 bottom: 15%;
 display:flex;
 justify-content:center;
 width:100%;
 }
.g{
 height: 70px;
 width: 70px;
 background-color: black;
 margin: 5px;
 }

Just add float:left; 只需添加float:left; to the css class .g Of course you MUST remove position: fixed; 当然,您必须删除position: fixed; You can also use position: fixed; 您还可以使用position: fixed; but you must provide different values for position for each div. 但您必须为每个div的排名提供不同的值。

<div class="groups">
  <div class="g g1"></div>
  <div class="g g2"></div>
  <div class="g g3"></div>
  <div class="g g4"></div>
</div>

<div class="groups">
  <div class="h h1"></div>
  <div class="h h2"></div>
  <div class="h h3"></div>
  <div class="h h4"></div>
</div>

.g {
  height: 70px;
  width: 70px;
  background-color: black;
  margin: 5px;
  float:left; /* add this */
  border: 1px solid red;  
  bottom: 15%; 
}

.h {
  height: 70px;
  width: 70px;
  background-color: blue;
  margin: 5px;
  position:fixed;
}

.h1 {
  bottom: 50px;
  right: 20px;
}

.h2 {
  bottom: 50px;
  right: 100px;
}

.h3 {
  bottom: 50px;
  right: 180px;
}

.h4 {
  bottom: 50px;
  right: 260px;
}

Here is a working Fiddle 这是一个工作的小提琴

As position is fixed, you may need to sepcify the positions of class g1, g2 and g3 like below. 由于位置是固定的,因此您可能需要像下面这样区分类g1,g2和g3的位置。

.g1{
    left: 0px;
}
.g2{
    left: 100px;
}
.g3{
    left: 200px;
}

如何显示<div>在 for 循环中彼此相邻?(laravel)</div><div id="text_translate"><p> 我正在开发一个校友门户网站,我需要在其中显示委员会成员的详细信息。 我需要在一行中打印 4 个成员,在下一行打印 4 个成员。 任何解决方案都会有所帮助。 <a href="https://i.stack.imgur.com/7jNiM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7jNiM.png" alt="在此处输入图像描述"></a></p><pre> <h2>Member Details</h2> <div class="jumbotron container"> <div class="pull-right"> <a class="btn btn-primary" data-toggle="modal" id="mediumButton" data-target="#mediumModal" data-attr="{{ route('add_details')}}" title="Add Institute Details"> <i class="fas fa-plus-circle"></i> </a> </div> <div class="container main" id="wrapper"> @foreach ($members as $member) <div class="img-box"> <pre> <img src="/uploads/image/{{ $member->image }}" width="100" height="100"/> &nbsp; &nbsp; &nbsp; {{ $member->id }}<br/> <a> &nbsp; {{ $member->name }}</a> <:-- @if(($member->id) >=5 ) <span style="white-space: pre-line"> </span> @endif </pre> --> </div> @endforeach </div> </div></pre></div> - how to display <div> next to each other within a for loop?(laravel)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将两个元素彼此相邻放置 - How to position two elements next to each other CSS:如何将2个div(一个固定)彼此并排放置,并在整个宽度上放置一个div? - CSS: how to position 2 divs (one fixed) next to each other with one div at full width? 如何将 div 元素彼此相邻放置? - How to Place div elements next to each other? div中彼此相邻的元素 - Elements next to each other in div 固定另一个div时,如何显示div? - How to display a div while another div is hovered with position: fixed? 如何将两个百里香叶元素彼此相邻放置 - How to position two thymeleaf elements next to each other 将两个<span>元素彼此相邻</span>放置 - Position two <span> elements next to each other div以固定div相互显示 - Divs display on top of each other in fixed div 如何显示<div>在 for 循环中彼此相邻?(laravel)</div><div id="text_translate"><p> 我正在开发一个校友门户网站,我需要在其中显示委员会成员的详细信息。 我需要在一行中打印 4 个成员,在下一行打印 4 个成员。 任何解决方案都会有所帮助。 <a href="https://i.stack.imgur.com/7jNiM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7jNiM.png" alt="在此处输入图像描述"></a></p><pre> <h2>Member Details</h2> <div class="jumbotron container"> <div class="pull-right"> <a class="btn btn-primary" data-toggle="modal" id="mediumButton" data-target="#mediumModal" data-attr="{{ route('add_details')}}" title="Add Institute Details"> <i class="fas fa-plus-circle"></i> </a> </div> <div class="container main" id="wrapper"> @foreach ($members as $member) <div class="img-box"> <pre> <img src="/uploads/image/{{ $member->image }}" width="100" height="100"/> &nbsp; &nbsp; &nbsp; {{ $member->id }}<br/> <a> &nbsp; {{ $member->name }}</a> <:-- @if(($member->id) >=5 ) <span style="white-space: pre-line"> </span> @endif </pre> --> </div> @endforeach </div> </div></pre></div> - how to display <div> next to each other within a for loop?(laravel) 将图像和Div元素彼此相邻放置? - Placing Images and Div Elements Next to Each Other?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM