gpt4 book ai didi

css - 将页脚 DIV 和页眉 DIV 添加到我当前的 CSS Flexbox 布局

转载 作者:太空宇宙 更新时间:2023-11-04 09:16:32 26 4
gpt4 key购买 nike

下面是我正在处理的 CSS FLexbox 布局。此处以及不断更新的 CodePen 上都有一个实例:http://codepen.io/jasondavis/pen/OWbXNB?editors=1100

我需要向布局添加 2 个 DIV,并且需要帮助将它们定位在我需要的位置。

  • 在右侧内容面板上方添加标题 DIV
  • 添加一个表单页脚 DIV,就像当前包装页脚一样,带有保存和重置按钮以及右侧栏底部的保存指示器
  • 最后我需要删除当前页脚,因此基本上只需将当前页脚移至右侧边栏即可。

到目前为止,我已经尝试了多个 Flexbox CSS 属性来尝试将其置于所需的位置,但没有成功。

这张图片显示了我需要更好的... enter image description here

演示

.wrapper {
border: 1px solid #D7DBDD;
margin-bottom: 100px;
max-width: 1076px;
}
.button {
padding: 5px 15px;
color: #FFF;
background-color: #4EBBE4;
border: 1px solid #16A2D7;
border-radius: 4px;
font-size: 16px;
cursor: pointer;
font-family: Raleway, Helvetica, sans-serif;
}
.siteHeader {
/**
* Lay out the children of this container with
* flexbox, which is horizontal by default.
*/
display: flex;
/**
* Make the container put as much space as possible
* between its children, with the children at either
* end laying flush against the container's edges.
*/
justify-content: space-between;
padding: 10px;
background-color: #56727C;
}
.siteHeader__section {
/**
* Lay out the children of this container with
* flexbox.
*/
display: flex;
/**
* Align the children in the center, along
* the main axis. By default the children will
* align along their top edges.
*/
align-items: center;
}
.siteHeader__item {
padding: 5px 15px;
font-size: 12px;
}
.siteHeader__item + .siteHeader__item {
margin-left: 5px;
}
.siteHeader__item.is-site-header-item-selected {
color: #FFFFFF;
background-color: #415F69;
border-radius: 4px;
}
.siteHeaderLogo {
font-size: 20px;
line-height: 0;
color: white;
}
.siteHeaderButton {
cursor: pointer;
color: #D9E9EF;
}
.container {
display: flex;
flex-direction: row;
}
main {
display: flex;
width: 100%;
}
.sideBar {
/**
* This container orders items according to flexbox
* rules. By default, this would arrange its children
* horizontally. However, the next property...
*/
display: flex;
/**
* ...sets the main axis to be vertical instead of
* horizontal, so now the children are laid out
* vertically, from top to bottom.
*/
flex-direction: column;
/**
* It will also put as much space as possible
* between its children, with the children at either end
* laying flush against the container's edges.
*/
justify-content: space-between;
height: auto;
width: 150px;
background-color: #FCFDFD;
padding: 10px;
}
.sideBar-left {
border-right: 1px solid #D7DBDD;
}
.sideBar-right {
border-left: 1px solid #D7DBDD;
width: 750px;
}
.sideBar__item {
cursor: pointer;
padding: 5px 10px;
color: #16A2D7;
font-size: 12px;
}
.sideBar__item.is-side-bar-item-selected {
background-color: #EEF3F5;
border-radius: 4px;
}
.formFooter {
/**
* Lay out the children of this container with
* flexbox, which is horizontal by default.
*/
display: flex;
/**
* Make the container put as much space as possible
* between its children, with the children at either
* end laying flush against the container's edges.
*/
justify-content: space-between;
/**
* Align the children in the center, along
* the main axis, which is horizontal in this case.
*/
align-items: center;
border-top: 1px solid #D7DBDD;
padding: 10px;
}
.formFooter__section {
/**
* This container orders items horizontally.
*/
display: flex;
/**
* It aligns them vertically in the center.
*/
align-items: center;
}
.formFooter__item + .formFooter__item {
margin-left: 5px;
}
.formFooterFeedback {
color: #86969C;
font-size: 12px;
line-height: 0;
}
.formFooterSpinner {
animation: formFooterSpinner 1s infinite steps(8, end);
}
@keyframes formFooterSpinner {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
.button--clear {
color: #16A2D7;
background-color: #FFFFFF;
border: 1px solid #FFFFFF;
}
.centeredPrompt {
/**
* Lay out the children of this container with
* flexbox.
*/
display: flex;
/**
* Rotate the main axis so that the children
* are laid out vertically, the same as in the
* above "Side bar" example.
*/
flex-direction: column;
/**
* Instead of pushing the children apart, as in
* previous examples, we will group them together
* in the center of their container.
*/
justify-content: center;
/**
* Align the children in the center, along
* the main axis. Because the direction is
* "column" this has a similar effect as setting
* text-align: center.
*/
align-items: center;
min-height: 300px;
padding: 10px;
width: 100%;
}
.centeredPrompt__item + .centeredPrompt__item {
margin-top: 5px;
}
.centeredPromptIcon {
font-size: 60px;
line-height: 0;
}
.centeredPromptLabel {
color: #86969C;
font-size: 30px;
font-weight: 700;
text-align: center;
}
.centeredPromptDetails {
color: #86969C;
font-size: 16px;
margin-bottom: 10px;
text-align: center;
}
.icon {
color: #BCD2DA;
}
.gallery {
/**
* Lay out the children of this container with
* flexbox, which is horizontal by default.
*/
display: flex;
/**
* Allow the children to wrap to the next "row",
* instead of trying to squeeze them all into
* a single row.
*/
flex-wrap: wrap;
width: 100%;
padding: 5px;
}
.photo {
display: flex;
-ms-flex-pack: end;
justify-content: flex-end;
-ms-flex-align: end;
align-items: flex-end;
width: 145px;
margin: 5px;
padding: 5px 10px;
font-size: 18px;
font-weight: 700;
text-shadow: 0 2px 3px rgba(0, 0, 0, .5);
color: #FFF;
background-size: cover;
background-position: center;
border-radius: 4px;
height: 130px;
opacity: 1;
border: 4px solid #ffffff;
cursor: pointer;
}
.photo.selected,
.photo:hover {
opacity: 0.3;
border: 4px solid #F44336;
}
.photo1 {
background-image: url('http://www.flexboxpatterns.com/images/dog_2.jpg');
}
.photo2 {
background-image: url('http://www.flexboxpatterns.com/images/dog_2.jpg');
}
.photo3 {
background-image: url('http://www.flexboxpatterns.com/images/dog_3.jpg');
}
.photo4 {
background-image: url('http://www.flexboxpatterns.com/images/dog_4.jpg');
}
.photo5 {
background-image: url('http://www.flexboxpatterns.com/images/dog_5.jpg');
}
.photo6 {
background-image: url('http://www.flexboxpatterns.com/images/dog_1.jpg');
}
.photo7 {
background-image: url('http://www.flexboxpatterns.com/images/dog_2.jpg');
}
.photo8 {
background-image: url('http://www.flexboxpatterns.com/images/dog_3.jpg');
}
.photo9 {
background-image: url('http://www.flexboxpatterns.com/images/dog_4.jpg');
}
.photo10 {
background-image: url('http://www.flexboxpatterns.com/images/dog_5.jpg');
}
<div class="wrapper">
<!-- START HEADER -->
<div class="siteHeader">
<!-- This section gets pushed to the left side-->
<div class="siteHeader__section">
<div class="siteHeader__item siteHeaderLogo">
<div class="fa fa-inbox"></div>
</div>
<div class="siteHeader__item siteHeaderButton is-site-header-item-selected">Inbox</div>
<div class="siteHeader__item siteHeaderButton">Sent</div>
<div class="siteHeader__item siteHeaderButton">Trash</div>
</div>
<!-- This section gets pushed to the right side-->
<div class="siteHeader__section">
<div class="siteHeader__item siteHeaderButton">Settings</div>
<div class="siteHeader__item siteHeaderButton">Log out</div>
</div>
</div>
<!-- END HEADER -->


<div class="container">

<!-- START LEFT SIDEBAR -->
<div class="sideBar sideBar-left">
<!-- This section gets pushed to the top-->
<div class="sideBar__section">
<div class="sideBar__item is-side-bar-item-selected">Inbox</div>
<div class="sideBar__item">Contacts</div>
<div class="sideBar__item">Account</div>
</div>
<!-- This section gets pushed to the bottom-->
<div class="sideBar__section">
<div class="sideBar__item">Change theme</div>
<div class="sideBar__item">Legal</div>
</div>
</div>
<!-- END LEFT SIDEBAR -->


<main>
<!-- START GALLERY -->
<!-- IT SHOULKD BE TO THE RIGHT OF THE LEFT SIDEBAR BUT IS CURRENTLY BELOW THE SIDEBAR AND FORM FOOTER BAR -->
<div class="gallery">
<div class="photo photo1 photo--large">1</div>
<div class="photo photo2 photo--large">2</div>
<div class="photo photo3 photo--large">3</div>
<div class="photo photo4 photo--large">4</div>
<div class="photo photo5 photo--large">5</div>
<div class="photo photo6 photo--large selected">6</div>
<div class="photo photo7 photo--large">7</div>
<div class="photo photo8 photo--large">8</div>
<div class="photo photo9 photo--large">9</div>
<div class="photo photo10 photo--large">10</div>
</div>
<!-- END GALLERY -->


</main>
<!-- END CENTERED PROMPT -->

<!-- RIGHT-SIDEBAR-->
<div class="sideBar sideBar-right">

Form fields will be here loaded with Data from the selected image in the left panel
<!-- This section gets pushed to the top-
<div class="sideBar__section">
<div class="sideBar__item is-side-bar-item-selected">Inbox</div>
<div class="sideBar__item">Contacts</div>
<div class="sideBar__item">Account</div>
</div>
-->

</div>
<!-- END RIGHT-SIDEBAR-->
</div>


<!-- START BOTTOM FORM FOOTER BAR -->
<div class="formFooter">
<!-- This section gets pushed to the left side-->
<div class="formFooter__section">
<div class="formFooter__item formFooterFeedback">
<div class="fa fa-spinner formFooterSpinner"></div>&nbsp;Saving...
</div>
</div>
<!-- This section gets pushed to the right side-->
<div class="formFooter__section">
<div class="formFooter__item button button--clear">Reset</div>
<div class="formFooter__item button">Save</div>
</div>
</div>
<!-- END BOTTOM FORM FOOTER BAR -->

</div>

最佳答案

注意:此解决方案假定工具栏不会即时更改高度。

这里的技巧是将 padding 应用于 position:relative; 容器,与 position:absolute; 工具栏的大小一致.因为您可能会再次使用元素的 formFootermain,所以我们将使用实用程序类来指示它们具有工具栏。这些实用程序类将包含有关 padding 的信息,并且在 formFooter 的情况下,扩展它们作为实用程序类的子级的行为。

CSS

main.with-header{
padding-top:50px;
position:relative;
}
.gallery--header{
height:50px;
top:0;
left:0;
right:0;
background-color:blue;
position:absolute;
}
.sideBar.sideBar-with-footer{
position:relative;
padding-bottom:50px;
}
.sideBar.sideBar-with-footer .formFooter{
position:absolute;
bottom:0;
left:0;
right:0;
}

HTML

<div class="wrapper">
<!-- START HEADER -->
<div class="siteHeader">
<!-- This section gets pushed to the left side-->
<div class="siteHeader__section">
<div class="siteHeader__item siteHeaderLogo">
<div class="fa fa-inbox"></div>
</div>
<div class="siteHeader__item siteHeaderButton is-site-header-item-selected">Inbox</div>
<div class="siteHeader__item siteHeaderButton">Sent</div>
<div class="siteHeader__item siteHeaderButton">Trash</div>
</div>
<!-- This section gets pushed to the right side-->
<div class="siteHeader__section">
<div class="siteHeader__item siteHeaderButton">Settings</div>
<div class="siteHeader__item siteHeaderButton">Log out</div>
</div>
</div>
<!-- END HEADER -->

<div class="container">

<!-- START LEFT SIDEBAR -->
<div class="sideBar sideBar-left">
<!-- This section gets pushed to the top-->
<div class="sideBar__section">
<div class="sideBar__item is-side-bar-item-selected">Inbox</div>
<div class="sideBar__item">Contacts</div>
<div class="sideBar__item">Account</div>
</div>
<!-- This section gets pushed to the bottom-->
<div class="sideBar__section">
<div class="sideBar__item">Change theme</div>
<div class="sideBar__item">Legal</div>
</div>
</div>
<!-- END LEFT SIDEBAR -->

<main class="with-header">
<div class="gallery--header">
<p>Gallery Header</p>
</div>
<!-- START GALLERY -->
<!-- IT SHOULKD BE TO THE RIGHT OF THE LEFT SIDEBAR BUT IS CURRENTLY BELOW THE SIDEBAR AND FORM FOOTER BAR -->
<div class="gallery">
<div class="photo photo1 photo--large">1</div>
<div class="photo photo2 photo--large">2</div>
<div class="photo photo3 photo--large">3</div>
<div class="photo photo4 photo--large">4</div>
<div class="photo photo5 photo--large">5</div>
<div class="photo photo6 photo--large selected">6</div>
<div class="photo photo7 photo--large">7</div>
<div class="photo photo8 photo--large">8</div>
<div class="photo photo9 photo--large">9</div>
<div class="photo photo10 photo--large">10</div>
</div>
<!-- END GALLERY -->

</main>
<!-- END CENTERED PROMPT -->

<!-- RIGHT-SIDEBAR-->
<div class="sideBar sideBar-right sideBar-with-footer">
<!-- START BOTTOM FORM FOOTER BAR -->
<div class="formFooter">
<!-- This section gets pushed to the left side-->
<div class="formFooter__section">
<div class="formFooter__item formFooterFeedback">
<div class="fa fa-spinner formFooterSpinner"></div>&nbsp;Saving...
</div>
</div>
<!-- This section gets pushed to the right side-->
<div class="formFooter__section">
<div class="formFooter__item button button--clear">Reset</div>
<div class="formFooter__item button">Save</div>
</div>
</div>
<!-- END BOTTOM FORM FOOTER BAR -->

</div>
<!-- END RIGHT-SIDEBAR-->
</div>

</div>

CODEPEN

关于css - 将页脚 DIV 和页眉 DIV 添加到我当前的 CSS Flexbox 布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41731426/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com