我目前正在建立一個示例站點,以遵循我在bootstrap中學到的知識(或者我認爲我學到的東西)。在這個網站上,我想在某個位置對齊DIV。該網站不針對移動設備進行調整,因爲我當時只是在計算機上進行測試。Div對齊最佳實踐
就定位H1 & H2而言,以下代碼是否是最佳實踐?我已經嘗試了大約3個小時,垂直定位div id="outer"
垂直&水平居中,無濟於事。沮喪,我轉向position: absolute
使用top
和left
規格。使用我提供的代碼,這是最佳實踐,AKA是對齊這些標題文本的最佳解決方案嗎?非常感謝你提前(抱歉NOOBing):
https://jsfiddle.net/8kqxtvn8/
@import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css');
html,
body {
height: 100%;
}
.navbar {
background-color: transparent;
background: transparent;
border-color: transparent;
border-radius: 0;
display: flex;
margin: 0;
}
.nav {
display: inline-flex;
flex-wrap: wrap;
font-size: 28px;
}
.navbar-brand img {
height: auto;
margin-top: -15px;
width: 50px;
}
.nav-link {
margin-right: 2rem;
}
.maincontent {
background-color: grey;
background-image: url('img/bgcover.jpg');
background-position: center;
background-repeat: no-repeat;
background-size: cover;
height: 100%;
}
#vertical {
position: absolute;
top: 30%;
left: 15%;
}
#outer {
background-color: yellow;
}
<nav class="navbar navbar-inverse navbar-fixed-top fixed-top">
<div class="container-fluid">
<nav class="nav">
<a class="nav-link" href="#">Galaxies</a>
<a class="nav-link" href="#">Telescopes</a>
<div class="logo">
<a class="navbar-brand custom-logo" href="#"><img src="https://www.shareicon.net/download/2016/07/11/794282_education_512x512.png" /></a>
</div>
<a class="nav-link" href="#">Projects</a>
<a class="nav-link" href="#">Get involved</a>
</nav>
</div>
</nav>
<section class="maincontent">
<div class="container-fluid">
<div class="row" id="vertical">
<div id="outer">
<h1>Welcome to <span class="LogoTitle">TITLE!</span></h1>
<h2>Lorem ipsum bla bla bla i dont know bootstrap</h2>
</div>
</div>
</div>
</section>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
你能解釋一下用import導入引導CSS的'link'替換嗎?我從開發人員的網站獲取 – Helle