html - 为任何浏览器(跨浏览器)在中心和左右定位 div

标签 html css angular flexbox angular6

Three div panels:-
1) (div-B) one div with max-width = 500px and min-width=400px should always on 
    the center of all browsers.
2) (div-A) one div should show and hide on the left of (div-B) having min-width 
   = 200px and max-width= 300px;
3) (div-C) one div should show and hide on the right of (div-B) having min-width 
   = 200px and max-width= 300px;

div-A 和 div-C 的显示和隐藏应该以这样的方式进行,它不应将 div-B 从其位置移动,但是,它可以达到其可用的最大宽度和最小宽度。 div-B 应始终位于所有浏览器的中心。

页面布局:-

Header
<--Left button here                                       right button here-->
to open div-A panel                                       to open div-c panel
(basically a dropdown)                                  (basically a dropdown)


         Left Panel <---20px---> Center Panel <---20px---> Right Panel   
         (div-A)                  (div-B)                     (div-C)    

1) (div-A && div-B), (div-B && div-C) having margin 20px in between always.
   div-A should grow towards left and div-c should grow towards right relative to div-B(min-width and 
   max-width availability).
2) div-B should not move to right or left when div-A and div-C should hide. 
 But div-B should grow towards its left or right keeping div-B fixed to 
  center of browser window and tries to achieve its max-width(keeping center 
 axis fixed) if space available towards right or left.

<header>
//show hide button for div-A
<div class="div-A-button">Dropdown button A</div>
//show hide button for div-C
<div class="div-C-button">Dropdown button C</div>
</header>

<main>
<div class="panel div-A">Panel A </div>  //show and hide using div-A-button
<div class="panel div-B">Panel B </div>  //fixed always show
<div class="panel div-C">Panel C </div>  //show and hide using div-C-button
</main>

这是 stackblitz 链接:https://stackblitz.com/edit/angular-tpj35u?file=src%2Fapp%2Fapp.component.html

最佳答案

您可以使用 CSS 网格。我想我已经理解你的布局了。让我知道下面的例子是否正确。

main {
  border: 1px solid;
  display: grid;
  grid-template-columns: minmax(200px, 300px) minmax(400px, 500px) minmax(200px, 300px);
  grid-gap: 20px;
  justify-content: center;
}

main>div {
  background: yellow;
  text-align: center;
  padding: 1em;
}

.div-B {
  grid-column: 2;
}
<main>
  <div class="panel div-A">Panel A </div>
  <div class="panel div-B">Panel B </div>
  <div class="panel div-C">Panel C </div>
</main>

关于html - 为任何浏览器(跨浏览器)在中心和左右定位 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52788923/

相关文章:

Angular 5 - 未定义谷歌(谷歌地图)

html - CSS 两个类使用具有多个设置的一个属性

android - Webview 中的 HTML 内容重叠

html - 关于 yui 下拉菜单的 css 设计问题

html - 我想用 SubMenus 的垂直 SubMenu 和 Horizo​​ntal SubMenus 制作纯 css 水平导航

angular - 为什么我在我的 Angular 应用程序中获得 "Module not found: Error: Can' t resolve '@angular/fire/firestore/firestore' “错误消息?

javascript - 有没有办法更改悬停时显示的文本?

javascript - 如果表单不无效,如何使用 ng-class 更改类?

jquery - 检测 Div 何时滚出 View

node.js - 在 VS Code 中调试 Angular Universal Starter App 的服务器端不起作用