【发布时间】:2022-01-02 17:50:53
【问题描述】:
我正在尝试制作一个带有标题和标题右侧图像的 html 标题。但是当屏幕尺寸改变时,图像会在标题上滑动。如何让它留在它的位置?我已经尝试了所有我能想到的,但没有运气。我想出的最好的方法是图像位于标题下方。然后它保持它的位置。但我宁愿把它放在一边。
这是我的代码:
<body>
<header>
<h1>Title text</h1>
<p>some text</p>
<div class="picture">
<img src="assets/images/xxxx.png">
</div>
</header>
some code ....
</body>
以及style.css中的header部分:
header { padding: 25px 20px 40px 20px; margin: 0; position: fixed; top: 0; left: 0; right: 0; width: 100%; text-align: center; background: #15253e; box-shadow: 1px 0px 2px rgba(0, 0, 0, 0.75); z-index: 99; -webkit-font-smoothing: antialiased; min-height: 76px; }
header h1 { font: 42px/50px 'Copse', "Helvetica Neue", Helvetica, Arial, sans-serif; color: #f3f3f3; text-shadow: 0px 2px 0px #235796; margin: 0px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; -o-text-overflow: ellipsis; -ms-text-overflow: ellipsis; }
header p { color: #f3f3f3; text-shadow: rgba(0, 0, 0, 0.2) 0 1px 0; font-size: 20px; margin: 10px; }
header img { width: 60px; height: 100px; position: fixed; right: 900px; top: 15px; text-align: right; }
header .picture { display: block; }
我会添加一张图片,但我没有这样做的权利。所以这里有一个页面an example,它可能会让我不了解我想要做什么。有一个标题和一个箭头图像的图片。我的目标是在标题文本的右侧获取图像。如果屏幕尺寸发生变化,请保留它。
【问题讨论】:
-
请提供更多详细信息和minimal reproducible example。
-
对不起,我不知道还有什么细节?有header部分和img?
-
例如你想要的结果是什么,你会得到什么,提供一个可行的例子。没有人知道你想要什么,所以如果你需要一些帮助,你必须提供更多的帮助。如果您对如何提问有疑问,请阅读How to Ask
-
css
boxäshadow不存在。而且您没有关闭您的img元素(缺少>) -
我想要标题右侧的标题中的图像。现在,当屏幕尺寸发生变化时,图像会浮在标题上。我不知道如何更清楚地说明这一点。