我正在學習網絡開發幾個月,現在我通常會遇到一些前端和用戶界面佈局問題。我經常在將元素完全放在我想要的位置時遇到困難。在這種情況下,我要麼使用相對值,要麼破壞網站的響應能力,要麼編寫一些在我看來就像黑客一樣的規則。使這種佈局的正確方法?
對於這個例子,讓我們考慮這個形象:
正如你可以看到,有一個引導的容器,全寬背景顏色,容器內的兩個經典元素和外部的圖像。
對於這種佈局,我會做類似如下:
<!-- /* MAIN WRAPPER -->
<div class="pull-right">
<img src="/img/topright_image.PNG" alt="shape">
</div>
<div class="bg-red"> <!-- Red background color. -->
<div class="container">
<header class="row">
<div class="hidden-sm hidden-xs col-sm-2" id="logo"> <!-- I'm using Bootstrap 3, IIRC there's a better way to do that in Bootstrap 4. -->
<img src="/img/logo.PNG" alt="logo">
</div>
<div class="col-sm-6 col-sm-push-3" id="title"> <!-- First difficulty, how to make sure the title will always be centered without being relative to the logo and no matter its content? -->
<h1>Centered title</h1>
</div>
</header>
</div>
</div>
<div class="bg-green"> <!-- Multiple containers, just to have colored backgrounds at 100% width of the page. -->
<div class="container">
<section></section>
</div>
</div>
<!-- MAIN WRAPPER */ -->
這是一個快速的草案,但你的想法。然後,CSS將爲頁眉和部分(300px和400px)實現任意高度,然後爲容器設置最大寬度。
如何正確地做到這一點?
(如果我想使標題有點上面的標誌是什麼;兩行之間)
根據您需要支持的內容以及支持的嚴格程度,[Grid Layout](http://caniuse.com/#search=grid)是一個不錯的選擇。 – Christoph