在下面的代碼我想以下條件成立:浮動股利的權利時,屏幕很寬,當疊加屏幕窄
- 粉紅色的DIV總是整個視。
- 粉紅色div的文字始終居中在視口中。
- 當屏幕「足夠寬」時,藍色的div浮到右側。
- 當屏幕不是「足夠寬」時,藍色div會疊加在粉紅色div下面。
- 藍色div跨越視口,其堆疊時其文本居中。
- 該解決方案應該是純CSS。
這是我目前的合格:
<!DOCTYPE html>
<html>
<head>
<style>
#parent {
position: relative;
background-color: white;
width: 100%;
height: 20px;
}
#center {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
margin: auto;
background-color: pink;
text-align: center;
}
#placeholder {
position: relative;
height: 20px;
width: 500px;
}
#right {
position: relative;
float: right;
background-color: blue;
}
</style>
</head>
<body>
<div id="parent">
<div id="center">This text should always be centered in the VIEWPORT</div>
<div id="right">this text should float to the right</div>
<div id="placeholder"></div>
</div>
</body>
</html>
下面是它目前看起來,當屏幕寬(正確的),如:
這裏是什麼樣子時,屏幕很窄(不正確):
下面是它應該是什麼的時候,屏幕狹小,如:
使用媒體查詢根據屏幕大小http://www.w3schools.com/cssref/css3_pr_mediaquery.asp –
我知道這種可能性進行調整CSS。在你的估計中,是否是目前處理這種佈局問題的標準方法? – JoeyJoeJoeJuniorShabadoo