向<h1>添加新内容时图像移动

时间:2017-10-28 04:22:55

标签: html css

这里的第一个网站(只是一个抬头)! 我的问题是我试图将我的内容(下面的飞鱼绘画和维护服务链接)都放在h1类别中而不移动图像!当我添加Services 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 &amp 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>

2 个答案:

答案 0 :(得分:2)

首先,不是在H1标签内塞满所有内容,而是可以将内容放在单独的div中,然后使用flex-box来对齐它们。为什么不在H1标签?这意味着headings

如何实现你所瞄准的目标有很多方法,这只是其中之一

&#13;
&#13;
/*
 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 }
&#13;
<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 &amp 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>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

我希望这会有所帮助。

&#13;
&#13;
.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%;
  position: relative;
}

h1:before {
  position: absolute;
  content: url('https://flyingfishpainting.files.wordpress.com/2013/04/flying_fish_logo_hressmall.png?w=50,h=50');
  left: 0;
  border-top-left-radius: 10px;
  border-bottom-left-radius: 10px;
  width: 70px;
  height: 70px;
  background-color: black;
}

h1:after {
  position: absolute;
  content: url('https://flyingfishpainting.files.wordpress.com/2013/04/flying_fish_logo_hressmall.png?w=50,h=50');
  right: 0;
  top: 0;
  border-top-right-radius: 10px;
  border-bottom-right-radius: 10px;
  width: 70px;
  height: 70px;
  background-color: black;
}
&#13;
<h1>
  Flying Fish Painting &amp Maintenance <br/>
  <a class="linkto" href="C:\Users\CEUser\Desktop\services.html">Services</a>
</h1>
&#13;
&#13;
&#13;