編輯:我能夠通過切換到基於浮動的佈局來解決此問題。不確定使用基於內聯塊的網格是否存在問題的解決方案。 (我想我可以使用這個位置:相對或絕對的,但這似乎是一個壞主意。)這是我的Codepen:https://codepen.io/mattgwater/pen/yXBqoe(它的工作原理是全屏)Ehsan的答案演示瞭如何基本完成此佈局,可能是更好的代碼示例。右欄中的文字在左欄中的圖像下方
我想根據這裏的圖片中的模板建立一個網站。 https://assets.themuse.com/uploaded/attachments/14846.png?v=None
但是,如果我在左列中有一個圖像,它會導致右列中的所有文本都在圖像下方。我該如何解決這個問題?
這裏是我的Codepen:https://codepen.io/mattgwater/pen/yXBqoe?editors=1100#0
我的HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/7.0.0/normalize.min.css">
<link rel="stylesheet" href="/Fonts/myFontsWebfontsKit/MyFontsWebfontsKit.css">
<link rel="stylesheet" href="/main.css">
</head>
<body>
<nav>
<div class="col left">
<div>
<h1 class="title">MATT GOLDWATER</h1>
</div>
</div><!--
--><div class="col right">
</div>
</nav>
<div class="nav-content-separator"></div>
<section>
<div class="col left">
<img class="profilepic" src="https://res.cloudinary.com/dyr8j9g6m/image/upload/v1496375439/my-headshot_bxpjqk.png" alt="Matt Goldwater">
<!--<p>yo</p>-->
</div><!--
--><div class="col right">
<p class="about">I want this sentence to be aligned with the top of the image.</p>
</div>
</section>
</body>
</html>
我的CSS(我也有標準化CSS)
html {
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: inherit;
}
.title {
color: #6fc3c3;
/*font-family: FuturaDCD-Lig;*/
font-weight: bold;
font-size: 32px;
text-align: center;
letter-spacing: .05em;
}
.col {
width: 50%;
display: inline-block;
/*white-space: nowrap;*/
}
.left {
padding-left: 10%;
}
.profilepic {
padding-top: 7%;
height: 450px;
margin: 0 auto;
display: block;
}
.nav-content-separator {
border: 1px solid #e8e8e8;
}
.about {
font-family: Avenir;
}
你可以發佈你的CSS嗎? –
@RalphDavidAbernathy哎呀!剛剛做到了。 – MattGoldwater
如果您嘗試將'float:right;'添加到'.col.right',該怎麼辦? –