html - 如何使图像居中并位于 <h1> 标签的顶部

标签 html css

<分区>

你好吗?我希望你在那里一切都好。伙计们,我被困在某个地方,我需要你的帮助。请浏览本文附带的 pic1 和 pic2。我希望 pic1 的输出看起来与 pic2 相似。

实际上我需要将 Logo 居中,它应该位于 h1 标签上方,例如检查 pic2。

* {
    margin: 0px;
    padding: 0px;
    box-sizing: border-box;
  }
  body {
    font-family: sans-serif;
  }

  /* Global Styles */

  .container {
    width: 80%;
    margin: auto;
  }

  header {
    background-color: #009866;
    padding: 10px;
  }

  #branding {
    float: left;
  }
  #branding h1 {
    margin-left: 15px;
    color:white;
  }

  .navbar {
    list-style-type: none;
    display: flex;
    justify-content: flex-end;
  }

  .navbar li {
    padding:6px;
  }
  .navbar li a  {
    text-decoration: none;
    color: white;
  }
  #cent-logo h1 {
    text-align: center;
  }
  #cent-logo img {

  }

    <!DOCTYPE html>
<html>
<head>
    <title></title>
    <link rel="stylesheet" type="text/css" href="StyleSheets/style.css">
</head>
<body>

<header>
   <section>
       <div id="branding">
           <h1>MJCET</h1>
       </div>
       <nav>
           <ul class="navbar">
               <li><a href="#">LOGIN</a></li>
               <li><a href="#">SIGN UP</a></li>
           </ul>
       </nav>
   </section>
</header>

    <section>
        <div class="container">
            <div id="cent-logo">
                <img src="Resources/logo.png">
                <h1>Sign in to MJC316</h1>
            </div>
        </div>

    </section>

</body>
</html>

pic1-this is my code

pic2-i want the output like this

最佳答案

你的 CSS 中有以下内容

img {
  display: block;
  margin-left: auto;
  margin-right: auto;    
}

看看https://www.w3schools.com/howto/howto_css_image_center.asp如果您有任何问题。

希望这对您有所帮助。

关于html - 如何使图像居中并位于 <h1> 标签的顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52577823/

上一篇:html - 创建一个空的 div 来放置边框

下一篇:javascript - 制作基于 slider 的图像集合

相关文章:

php-mysql在html下拉菜单中查询输出

css - 用 widget 封装 css

html - 仅使用 css 将表格从一个位置移动到另一个位置

javascript - 将 css 应用于旋转木马幻灯片上的另一个跨度

javascript - 如何将网页加载到 <div> 元素中?

html - 垂直对齐基线不起作用

javascript - 无法使用 jQuery 均衡 anchor 高度

javascript - 计时器在 php 文件上使用 js 使输入和文本区域样式返回为默认值

css - 使用 gulp-sass npm 模块编译 scss 文件

javascript - 计算器只需要删除一个数字