简体   繁体   English

如何修复居中容器旁边的 DIV 容器 - CSS

[英]How to fix a DIV-Container next right to a centered Container - CSS

I've a simple DIV-Container for the main-content of the webpage.我有一个用于网页主要内容的简单 DIV 容器。 IE IE

#main { width: 50%; margin: 0 auto; }

Now I would like to fix another container, right and fixed at the top of the #main-Container.现在我想修复另一个容器,正确并固定在#main-Container 的顶部。 See Screenshot:见截图:

在此处输入图像描述

You can do something like the following using CSS Flex:您可以使用 CSS Flex 执行类似以下操作:

 .flex-container { display: flex; width: calc(66.66% - 20px); float: right; }.main { flex: 1; color: white; text-align: center; margin-right: 33.33%; }.main:first-child { width: 50%; margin: 0 auto; margin-right: 10px; }.red { background-color: red; height: 200px; line-height: 200px; }.green { background-color: green; height: 100px; line-height: 100px; max-width: 15%; }
 <div class="flex-container"> <div class="main red"> Main content </div> <div class="main green">? </div> </div>

Add the green div inside the centered div and style it.在居中的 div 中添加绿色 div 并设置样式。

<div id="main" style="position:relative;">
   <div id="green_div" style="position:absolute; left:100%; margin-left:20px; background:green;">
   <div>
</div>

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM