1)我的choice-box
组件的高度固定,是否可以相对于页面设置?
2)我该怎样做才能使Upload New File
和Download Template
文本垂直居中?我试图垂直对齐它们,但是它不起作用...
3)我想在我的Wrong move...
文本上方添加一个边距,我尝试了margin-top
和padding-top
,但是它也不起作用...我认为这是因为我上面的组件(choice-boxes
)设置不正确
我是css
的新手,所以如果有人可以帮助我,那就太好了!
这是我的html
和css
代码:
<div className="choice-box">
<div className="head-title head-title-choice">
What are you trying to do ?
</div>
<div className="choice-boxes">
<div className="choice left-choice">
Upload New File
</div>
<div className="choice right-choice">
Download Template
</div>
</div>
<div className="under-choice">
Wrong move, get back to Dashboard
</div>
</div>
然后:
.choice-box{
background-color: #FFFFFF;
margin-left: 20%;
margin-right: 20%;
margin-top: 5%;
height: 600px;
border-radius: 5px;
}
.head-title-choice{
text-align: center;
padding-top: 2%;
font-size: 25px;
}
.choice-boxes{
width: 100%;
height: 400px;
}
.choice{
float: left;
text-align: center;
background-color: blue;
margin-top: 5%;
height: 100%;
}
.left-choice{
width: 44.5%;
margin-left: 5%;
}
.right-choice{
width: 44.5%;
margin-left: 1%;
margin-right: 5%;
}
.under-choice{
text-align: center;
}
答案 0 :(得分:0)
我认为这里没有理由使用float
。尝试使用flexbox进行布局,然后使用vh来使高度与窗口成比例。
.choice-box {
text-align: center;
}
.choice-boxes {
display: flex;
align-items: center;
margin: 20px 0;
}
.choice-boxes>* {
flex: 1 1 auto;
background: blue;
height: 50vh;
display: flex;
align-items: center;
justify-content: center;
margin: 10px;
color: white;
}
<div class="choice-box">
<div class="head-title head-title-choice">
What are you trying to do ?
</div>
<div class="choice-boxes">
<div class="choice left-choice">
Upload New File
</div>
<div class="choice right-choice">
Download Template
</div>
</div>
<div class="under-choice">
Wrong move, get back to Dashboard
</div>
</div>