这里是第一个网站(请注意)! 我的问题是我试图将我的内容(下面有服务链接的飞鱼绘画和维护)全部放在 h1 类别中而不移动图像!当我添加服务 href 链接时,我真的希望这两个图像(左侧和右侧)分别位于左上角和右上角。有任何想法吗?这是我的代码:
.round1 {
border-top-left-radius: 10px;
border-bottom-left-radius: 10px;
width: 70px;
height: 70px;
}
.round2 {
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
width: 70px;
height: 70px;
}
.linkto {
color: white;
font-size: 60%;
font-family: Arial;
}
.linkto:hover {
color: blue;
}
body {
padding: 20px 20px 20px 20px;
}
h1 {
color: white;
border: 6px solid black;
border-radius: 25px;
text-align: center;
font-family: Forte;
font-weight: bold;
background-color: black;
font-size: 180%;
padding-bottom: -50px;
}
<h1>
Flying Fish Painting & Maintenance</br>
<img class="round1" src="https://flyingfishpainting.files.wordpress.com/2013/04/flying_fish_logo_hressmall.png?w=300&h=291" align=left>
<img class="round2" src="https://flyingfishpainting.files.wordpress.com/2013/04/flying_fish_logo_hressmall.png?w=300&h=291" align=right>
<a class="linkto" href="C:\Users\CE User\Desktop\services.html">Services</a>
</h1>
最佳答案
首先,您可以将内容放在单独的 div 中,然后使用 flex-box 对齐它们,而不是将所有内容都塞进 H1 标签中。为什么不在 H1 标签中?它适用于 headings
实现目标的方法有很多种,这只是其中一种
/*
More about box-sizing:
https://developer.mozilla.org/en-US/docs/Web/CSS/box-sizing
https://www.paulirish.com/2012/box-sizing-border-box-ftw/
*/
html {
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: inherit;
}
.wrapper {
background: black;
border-radius: 25px;
text-align: center;
padding: 1rem;
margin: 0 auto;
display: flex;
justify-content: center;
/* could be any number you want */
max-width: 780px;
}
.image-wrapper {
flex-basis: 70px;
}
img {
max-width: 100%;
}
h1 {
text-align:center;
font-family:Forte;
font-weight:bold;
color: white;
margin: 0 1rem 0 1rem;
}
a {
color: white;
text-decoration: none;
font-size: 1.5rem;
font-family:Arial;
}
a:hover { color: blue }
<div class="wrapper">
<div class="left image-wrapper">
<!-- removed the align attribute -->
<img src="https://flyingfishpainting.files.wordpress.com/2013/04/flying_fish_logo_hressmall.png?w=300&h=291">
</div>
<div>
<h1> Flying Fish Painting & Maintenance</h1>
<a class ="linkto" href="C:\Users\CE User\Desktop\services.html">Services</a>
</div>
<div class="right image-wrapper">
<img src="https://flyingfishpainting.files.wordpress.com/2013/04/flying_fish_logo_hressmall.png?w=300&h=291">
</div>
</div>
关于html - 向 <h1> 添加新内容时图像移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46986228/