html - 试图整理 CSS 网格布局时遇到了困难

标签 html css css-grid

这是我第一次在元素中使用 CSS 网格,因此,如果这是一个愚蠢的问题,我深表歉意,我会尝试尽可能具体。

我正在构建的网站的设计计划是这样的:You can see the layout I'm trying to achieve with this

但是,我在定位其中一个“网格框”内包含的 Logo 时遇到了困难,正如您从以下屏幕截图中看到的那样:I'm trying to move the SVG logo to the right hand side and have the titles to the left of it, although for some reason the logo has taken up the entire row and forced the text down.

我将链接下面的 HTML 代码:

.wrapper {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: 15% 250px;
  height: 100vh;
}

.box1,
.box3,
.box5,
.box6,
.box8 {
  background-color: #ce6c47;
}

.box1 {
  grid-column: 1/3;
}

.box3 {
  grid-column: 1/3;
}

.box2,
.box4,
.box7 {
  background-color: #ef8354;
}

.box4 {
  grid-row: 2/4;
}

.box9 {
  grid-column: 2/4;
  background-color: #333533;
}
<div class="wrapper">
  <div class="box box1">
    <ul id="nav-wrapper">
      <li>History</li>
      <li>Services</li>
      <li>Work</li>
      <li>Contact</li>
    </ul>
  </div>
  <div class="box box2">Box 2</div>
  <div class="box box3">
    <div class="text">
      <h1>MHP</h1>
      <h2>CDM Coordination and<br>Quantity Surveying Services</h2>
    </div>
  </div>
  <div class="box box4">
    <object>
        <embed src="better 3.svg">
      </object>
  </div>
  <div class="box box5">Box 5</div>
  <div class="box box6">Box 6</div>
  <div class="box box7">Box 7</div>
  <div class="box box8">Box 8</div>
  <div class="box box9">Box 9</div>
</div>

任何回复将不胜感激!

非常感谢, 亚当

最佳答案

坚持顶部两行,我会添加一个变换以使其穿过列

.wrapper {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: 15% 250px;
  height: 100vh;
}
.box {
  border: 1px solid green;
}
.box1,
.box3 {
  background-color: #ce6c47;
}
.box1 {
  grid-column: 1/3;
}
.box2,
.box4 {
  background: brown;
}
.box3 {
  grid-column: 1/3;
}
.box4 {
  display: flex;
  align-items: center;
}
.box4 img {
  transform: translateX(-50%);
  -webkit-transform: translateX(-50%);
  -moz-transform: translateX(-50%);
  -ms-transform: translateX(-50%);
  -o-transform: translateX(-50%);
}
<div class="wrapper">
  <div class="box box1">
    <ul id="nav-wrapper">
      <li>History</li>
      <li>Services</li>
      <li>Work</li>
      <li>Contact</li>
    </ul>
  </div>
  <div class="box box2">Box 2</div>
  <div class="box box3">
    <div class="text">
      <h1>MHP</h1>
      <h2>CDM Coordination and<br>Quantity Surveying Services</h2>
    </div>
  </div>
  <div class="box box4">
    <img src="http://www.fillmurray.com/140/100" alt="">
  </div>
</div>

关于html - 试图整理 CSS 网格布局时遇到了困难,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51966546/

相关文章:

html - 填充溢出文本字段中的容器

CSS 网格 - 列的规则必须尽可能窄,但最大宽度为 50%

css - 为什么网格间隙中的百分比值会在 CSS 网格中造成溢出?

html - div contenteditable 和 span 元素的自动换行

jquery - 如何防止 slider 标签重叠?

javascript - 将滚动区域的顶部与 CSS 固定的重叠元素分开

javascript - 在通过 CSS 转换元素的尺寸时获取元素的(最终)高度

html - ul 内的 li 间距不均匀

c# - 使用 Lookahead 使用正则表达式匹配字符串

javascript - 如何使用 javascript 创建链接?