html - 居中图片和标题

标签 html css

我致力于将图片和标题置于头部的中心位置。我想要的是在图片比标题高两倍的位置居中。 我得到了一个高于另一个:

.body {
  font: 15px/1.5 Arial, Helvetica, sans-serif;
  padding: 0;
  margin: 0;
  background-color: #f4f4f4;
}

header h1 {
  font: 400 100px/1.3 'Berkshire Swash', Helvetica, sans-serif;
  color: #2b2b2b;
  text-shadow: 1px 1px 0px #ededed, 4px 4px 0px rgba(0, 0, 0, 0.15);
  border: 1px solid red;
}

.container {
  width: 90%;
  margin-left: 40px;
  margin-right: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid gray;
}

header {
  background: gray;
  text-align: center;
}

.logo {
  display: inline-block;
  margin: 0 auto;
  border: 1px solid white;
}
<header>
  <div class="container">
    <img src="my_logo2.png" alt="Logo" class="logo">
    <h1>Auto Service</h1>
  </div>
</header>

谁能解释一下我怎样才能得到想要的结果?

最佳答案

这是你想要的吗?

    <html>
	<style>
	.body{
      font: 15px/1.5 Arial, Helvetica, sans-serif;
      padding:0;
      margin:0;
      background-color:#f4f4f4;
    }
    header h1 {
      font: 400 100px/1.3 'Berkshire Swash', Helvetica, sans-serif;
      color: #2b2b2b;
      text-shadow: 1px 1px 0px #ededed, 4px 4px 0px rgba(0,0,0,0.15);
      border: 1px solid red;
    }

    .container {
      width: 90%;
      margin-left: 40px;
      margin-right: 0;
      padding: 0;
      overflow: hidden;
      border: 1px solid gray;
    }
   header{
      background: gray;
      text-align: center;
    }
    .logo{
       display: inline-block;
       margin: 0 auto;
       border: 1px solid white;
    }
	</style>
	<body>
	<header>
	<center>
      <div class="container">
        <Br><img src="my_logo2.png" alt="Logo" class="logo">
          <h1>Auto Service</h1>
          </div>
		  </center>
      </header>
	  <body>
</html>

关于html - 居中图片和标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48253410/

相关文章:

html - ul 列表不居中(css 和 html)

javascript - 不显示此警报 ---> 警报 ("I am inside change");

javascript - 没有插件的 Jquery Javascript 验证

javascript - 为什么 LinkedIn inFollow 按钮脚本在本地运行时不生成按钮?

html - 如何创建垂直菜单并在相关页面上水平显示其子菜单

html - 表格 - 头部在左,内容在右,都在一条垂直线上

html - top/bottom 对相对定位的元素没有影响

javascript - 如何创建一个可以访问函数及其对象的 JavaScript 包装器?

HTML:没有滚动条的水平滚动

css - Bootstrap 4.0 - 使用 flex 列