繁体   English   中英

将div中的图像与下面的文本对齐

[英]Align an image in div with text below

我一直在寻找对我有帮助但找不到的答案。

HTML:

  <section id="pane_one">
    <h1 id="logo">lel</h1>
    <h2 id="hello"><span>Hello.</span> You&rsquo;ve reached my page.</h2>
  </section>

CSS:

section#pane_one {
    display: block;
    position: relative;
    width: 100%;
    text-align: center;
    min-height: 450px;
    height: 700px;
}

h1#logo {
    position: absolute;
    z-index: 0;
    width: 200px;
    height: 200px;
    background-color: #000;
    text-indent: -9999px;
    top: 35%;
    left: 44.5%;
    margin-top: -65px;
    margin-left: -33px;

    background: url('https://i.imgur.com/RMQi9Js.jpg') center center no-repeat;

    background-size: 100%;
    border-radius: 50%;
    border: solid black;
}

如何设置它,以便无论页面缩放如何,div /图像始终与其下方的文本水平对齐?

该站点是: http : //libeclipse.me/

<html>
<head>
<style>
section#pane_one {
    display: block;
    position: relative;
    width: 100%;
    text-align: center;
    min-height: 450px;
    height: 700px;
}

h1#logo {
position:relative;
    z-index: 0;
    width: 200px;
    height: 200px;
    background-color: #000;
    text-indent: -9999px;
    top: 200px;
display: inline-block;
    background: url('https://i.imgur.com/RMQi9Js.jpg') center center no-repeat;
    background-size: 100%;
    border-radius: 50%;
    border: solid black;
}

h2#hello {
position:absolute;
top:0px;
width:100%;
margin:auto;
}
</style>
</head>
<body>
  <section id="pane_one">
    <h1 id="logo">lel</h1>
    <h2 id="hello"><span>Hello.</span> You&rsquo;ve reached my page.</h2>
  </section>
  </body>
<html>

对此进行检查并记下margin:auto(将h2text居中在绝对位置)并显示:inline-block(将兔子图像居中)。

删除了h1#logo中剩余的%和边距。 请享用。

谢谢。

h1#logo规则上,将left更改为50% ,将margin-left更改为-100px

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM