Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
220 views
in Technique[技术] by (71.8m points)

Aligning HTML panels vertically using CSS

I'm trying to place forms vertically within a canvas. I have two panels, which when they're set to absolute are placed as, I would expect, on the right of the page (but occupying the same space). The complication is that the panels have collapse buttons at the top and so hard coding an offset wont work (I need the lower one to move up when the upper one is collapsed).

My CSS for the forms is as below:

#properties-tab {
position: absolute;
display: inline;
top: 16px;
right: 20px;
width: 20%;
text-align: center;
z-index: 101;
display: block;
background-color: #9e9a90;
background: rgba(0, 0, 0, 0.1);
border-top-left-radius: 6px;
border-top-right-radius: 6px;
border: 0;

}

#tag-tab {
position: absolute;
display: inline;
top: 16px;
right: 20px;
width: 20%;
text-align: center;
z-index: 101;
display: block;
background-color: #9e9a90;
background: rgba(0, 0, 0, 0.1);
border-top-left-radius: 6px;
border-top-right-radius: 6px;
border: 0;

}

The CSS on the buttons looks like this:

#job-info {
position: absolute;
display: inline;
top: 34px;
right: 20px;
width: 20%;
text-align: center;
z-index: 101;
display: block;
background-color: #9e9a90;
background: rgba(0, 0, 0, 0.1);
border-bottom-left-radius: 6px;
border-bottom-right-radius: 6px;

}

#tag-info {
position: absolute;
display: inline;
top: 34px;
right: 20px;
width: 20%;
text-align: center;
z-index: 101;
display: block;
background-color: #9e9a90;
background: rgba(0, 0, 0, 0.1);
border-bottom-left-radius: 6px;
border-bottom-right-radius: 6px;

}

Placed using the above code, it looks like this:

enter image description here

When I change the settings to relative, this happens:

enter image description here

Any help would be appreciated.

question from:https://stackoverflow.com/questions/65902087/aligning-html-panels-vertically-using-css

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Flexbox solved the problem well, I suspect grid might also have given a solution:

.flex-container {
top: 16px;
right: 20px;
position: absolute;
display: flex;
flex-wrap: wrap;
width: 20%;

}

enter image description here

Thanks @Sfili_81


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...