我试着按如下方式制作两列,但是,我无法更改左div的空格.

.half50 {
  width: 50%;
  display: table-cell;
  height: fit-content;
  align-content: flex-start;
}
<div class="half50" style="margin: 1px; border: solid 1px;background: red; height: 50px;">
  <h2> CONTACT INFORMATION </h2>
  <p>
    Department of Mathematics <br> University of xx <br> xx. <br>
    <strong>Office:</strong> xx
    <strong>E-mail:</strong> <code>xx</code> <br>
  </p>
</div>

<div class="half50">
  <p>
    <img src="https://images.unsplash.com/photo-1583433713740-6b3f35a3d232?      crop=entropy&cs=srgb&fm=jpg&ixid=MnwxNDU4OXwwfDF8cmFuZG9tfHx8fHx8fHx8MTY0OTIyMjEwNw&ixlib=rb-1.2.1&q=85" alt="wave2" width="400" height="150">
  </p>

推荐答案

Use the modern flexbox layout mode for this:

  • 避免使用内联样式,try 将样式与标记分开
  • 避免设置导致元素溢出的明确高度

body {
  display: flex;
}

.contact {
  margin: 1px;
  border: solid 1px;
  background: red;
  /* height: 50px; Avoid setting explicit heights like this */
}
<div class="contact">
  <h2>CONTACT INFORMATION</h2>
  <p>
    Department of Mathematics <br> University of xx <br> xx. <br>
    <strong>Office:</strong> xx
    <strong>E-mail:</strong> <code>xx</code> <br>
  </p>
</div>
<div class="image">
  <p>
    <img src="https://images.unsplash.com/photo-1583433713740-6b3f35a3d232?crop=entropy&cs=srgb&fm=jpg&ixid=MnwxNDU4OXwwfDF8cmFuZG9tfHx8fHx8fHx8MTY0OTIyMjEwNw&ixlib=rb-1.2.1&q=85" alt="wave2" width="400" height="150">
  </p>
</div>

当屏幕不够宽,无法让两个元素相邻时,你决定了会发生什么吗?

body {
  display: flex;
  /* If I can't fit my children on one line at the size they want to be, wrap onto a new line */
  flex-wrap: wrap;
}

.contact { 
  flex-grow: 1;
  /* Grow at a rate of 1 if there is room for me to do so */
  margin: 1px;
  border: solid 1px;
  background: red;
}

.image {
  min-width: 500px;
  flex-grow: 1;
}

img {
  width: 100%;
  height: auto;
}
<div class="contact">
  <h2>CONTACT INFORMATION</h2>
  <p>
    Department of Mathematics <br> University of xx <br> xx. <br>
    <strong>Office:</strong> xx
    <strong>E-mail:</strong> <code>xx</code> <br>
  </p>
</div>
<div class="image">
  <img src="https://images.unsplash.com/photo-1583433713740-6b3f35a3d232?crop=entropy&cs=srgb&fm=jpg&ixid=MnwxNDU4OXwwfDF8cmFuZG9tfHx8fHx8fHx8MTY0OTIyMjEwNw&ixlib=rb-1.2.1&q=85" alt="wave2" width="400" height="150">
</div>

Html相关问答推荐

如何让一个动态列表以网格方式水平显示

自动字间距以适应行CSS

删除第一个列表项上的左边框

在css嵌套 Select 器中,尾随的`&;‘是什么意思?

如何在R中渲染Quarto文档时动态设置html文件名

角化、剪裁、边缘,但仅在底部2和平滑包装上

如何从elementor中的滑块中获取文本?

在TWebLabel标题中设置换行符/换行符的方法?

可以';t使我的导航栏在HTML/CSS中正确对齐

如何使Bootstrap 5卡可点击

排列卡片时遇到困难

在Angular中,类型"HTMLDivElement"不能分配给类型"Node"

如何垂直平移一个元素,使其新位置位于另外两个元素之间?

如何使文本区域自动扩展到最大高度?

如何让一个 div 始终贴在容器的边缘?

屏幕缩小时背景图像裁剪高度

修复 Vue 3 Component 中的 CSS 以显示后面的 Select 器样式而无需 !important

将背景图像裁剪成两半

无法使用 flexbox 裁剪图像

在部分而不是正文中定义页面宽度