帮我写一段在html页面内悬浮在两侧的图片广告的代码
时间: 2023-05-19 14:04:31 浏览: 86
以下是一段在 HTML 页面内悬浮在两侧的图片广告的代码:
```html
<style>
.ad-container {
position: fixed;
top: 0;
width: 100%;
height: 100%;
display: flex;
justify-content: space-between;
z-index: 9999;
}
.ad-container img {
max-height: 100%;
max-width: 50%;
object-fit: contain;
}
.ad-container img:first-child {
margin-right: 10px;
}
.ad-container img:last-child {
margin-left: 10px;
}
</style>
<div class="ad-container">
<img src="left-ad.jpg" alt="Left Ad">
<img src="right-ad.jpg" alt="Right Ad">
</div>
```
这段代码使用了 CSS 的 `position: fixed` 属性,将广告容器固定在页面上方,然后使用 `display: flex` 和 `justify-content: space-between` 属性将两张广告图片分别放在容器的左右两侧。图片的大小使用了 `max-height` 和 `max-width` 属性限制,同时使用 `object-fit: contain` 属性保持图片比例不变。最后,使用 `margin-right` 和 `margin-left` 属性为左右两张图片添加间距。