2017-05-20 19 views
0

對不起,我是初學者,我也想了解解決方案。文字不會出現在浮動圖像旁

我希望文字在圖片旁邊浮動,同時我注意到圖片沒有完全顯示,而是其一部分位於標題下方。

body { 
 
    font-family: Arial, Helvetica, sans-serif; 
 
    font-size: 16px; 
 
    margin: 0; 
 
    padding: 0; 
 
} 
 
p, h1 { 
 
    margin: 0; 
 
    padding: 0; 
 
} 
 
header { 
 
    background-color: #191919; 
 
    position: fixed; 
 
    width: 100%; 
 
    color: #edf9ff; 
 
    min-height: 70px; 
 
    border-bottom: #0fe216 3px solid; 
 
    display: flex; 
 
    align-items: center; 
 
    justify-content: space-between; 
 
    margin-bottom: 20px; 
 
    margin-top:0; 
 
} 
 

 
header a { 
 
    text-decoration: none; 
 
    text-transform: uppercase; 
 
    color: #edf9ff; 
 
} 
 

 
header ul { 
 
    margin: 0; 
 
} 
 

 
header li { 
 
    list-style-type: none; 
 
    float: left; 
 
    padding-right: 20px; 
 
} 
 

 
#showtime img { 
 
    width:300px; 
 
    height:300px; 
 

 

 
} 
 
.clearfix { 
 
    overflow:auto; 
 
} 
 
#img1 { 
 
    float:right; 
 

 
} 
 
#img2 { 
 
    float:left; 
 
} 
 

 
footer { 
 
margin-top:30px; 
 
    background-color:#191919; 
 
    height: 100px; 
 
    display: flex; 
 
    align-items: center; 
 
    justify-content: center; 
 
    clear:both; 
 
} 
 
footer p{ 
 
    text-align: center; 
 
    color: white; 
 
}
<!doctype html> 
 
<html> 
 
    <head> 
 
     <title>Photography | Home </title> 
 
     <link href="About.css" rel="stylesheet"/> 
 
     <script type="application/javascript" src="Home.js"></script> 
 
    </head> 
 
    <body> 
 

 
     <header> 
 
      <div id="branding"> 
 
       <h2>PHOTOGRAPHY</h2> 
 
      </div> 
 
      <nav id="links"> 
 
      <ul> 
 
       <li><a href="Home.html">Home</a></li> 
 
       <li><a href="About.html">About</a></li> 
 
       <li><a href="#">PHOTO GALLERY</a></li> 
 
       <li><a href="#">VIDEO GALLERY</a></li> 
 
      </ul> 
 
       </nav> 
 
     </header> 
 
     <section id="showtime"> 
 
       <div> 
 

 
        <a href="./images/Person1.jpg"><img src="./images/Person1.jpg" width="300px;" height="300px;"></a> 
 
        <h2>Image</h2> 
 
        <p>The image will always try to be unique from the odthers and we will always try to deliver the best photo in our limited time</p> 
 
       </div> 
 
     </section> 
 
       
 
     <footer> 
 
      <p>Note that any copyright &copy; is reserved</p> 
 
     </footer> 
 
    </body> 
 
</html>

+0

在你的HTML代碼,它看起來像你沒有的id爲您的圖片集。解決這個問題是否解決了問題? – APerson

+0

似乎並不 –

+0

也許他/她的意思是'#showtime img'如果是這樣,只需爲該id添加'float:left'@ModinaBegum –

回答

0

使用align="left"浮動旁邊的一些文本的圖像。 showtime部分需要空格以允許標題高度重疊。

body { 
 
    font-family: Arial, Helvetica, sans-serif; 
 
    font-size: 16px; 
 
    margin: 0; 
 
    padding: 0; 
 
} 
 
p, h1 { 
 
    margin: 0; 
 
    padding: 0; 
 
} 
 
header { 
 
    background-color: #191919; 
 
    position: fixed; 
 
    width: 100%; 
 
    color: #edf9ff; 
 
    min-height: 70px; 
 
    border-bottom: #0fe216 3px solid; 
 
    display: flex; 
 
    align-items: center; 
 
    justify-content: space-between; 
 
    margin-top:0; 
 
} 
 

 
header a { 
 
    text-decoration: none; 
 
    text-transform: uppercase; 
 
    color: #edf9ff; 
 
} 
 

 
header ul { 
 
    margin: 0; 
 
} 
 

 
header li { 
 
    list-style-type: none; 
 
    float: left; 
 
    padding-right: 20px; 
 
} 
 
#showtime { 
 
padding-top:60px; 
 
} 
 
#showtime img { 
 
    width:300px; 
 
    height:300px; 
 

 

 
} 
 
.clearfix { 
 
    overflow:auto; 
 
} 
 
#img1 { 
 
    float:right; 
 

 
} 
 
#img2 { 
 
    float:left; 
 
} 
 

 
footer { 
 
margin-top:30px; 
 
    background-color:#191919; 
 
    height: 100px; 
 
    display: flex; 
 
    align-items: center; 
 
    justify-content: center; 
 
    clear:both; 
 
} 
 
footer p{ 
 
    text-align: center; 
 
    color: white; 
 
}
<!doctype html> 
 
<html> 
 
    <head> 
 
     <title>Photography | Home </title> 
 
     <link href="About.css" rel="stylesheet"/> 
 
     <script type="application/javascript" src="Home.js"></script> 
 
    </head> 
 
    <body> 
 

 
     <header> 
 
      <div id="branding"> 
 
       <h2>PHOTOGRAPHY</h2> 
 
      </div> 
 
      <nav id="links"> 
 
      <ul> 
 
       <li><a href="Home.html">Home</a></li> 
 
       <li><a href="About.html">About</a></li> 
 
       <li><a href="#">PHOTO GALLERY</a></li> 
 
       <li><a href="#">VIDEO GALLERY</a></li> 
 
      </ul> 
 
       </nav> 
 
     </header> 
 
     <section id="showtime"> 
 
       <div> 
 

 
        <a href="./images/Person1.jpg"><img align="left" src="./images/Person1.jpg" width="300px;" height="300px;"></a> 
 
        <h2>Image</h2> 
 
        <p>The image will always try to be unique from the odthers and we will always try to deliver the best photo in our limited time</p> 
 
       </div> 
 
     </section> 
 
       
 
     <footer> 
 
      <p>Note that any copyright &copy; is reserved</p> 
 
     </footer> 
 
    </body> 
 
</html>

+0

umm ..你在哪裏放置「align:left;」至? –

+0

nvm我想通了,thx的答案! –

+0

HTML5中不支持任何的** align **屬性。您應該使用CSS代替。 –

0

與頭替換CSS:

header { 
    background-color: #191919; 
    position: fixed; 
    width: 100%; 
    color: #edf9ff; 
    min-height: 70px; 
    border-bottom: #0fe216 3px solid; 
    display: flex; 
    align-items: center; 
    justify-content: space-between; 
    margin-bottom: 20px; 
    margin-top: 0; 
    top: 0; // Added. Is required for fixed positioning 
} 

,並添加以下:

#showtime { 
    margin-top: 70px; 
} 
0

您需要添加到CSS #showtime { padding-top: 100px;}因爲position: fixed;從相對位置刪除你的元素,所以你需要在上面添加額外的空間,。

並將id添加到img標籤<img id="img1" src="./images/Person1.jpg" width="300px;" height="300px;">。這實際上不是最好的主意。最好使用類。

您應該通過向img添加一個類來適當地實現,id對於所有HTML文檔元素都必須是唯一的,您不能多次使用它。例如,你可以這樣做:

CSS .img1 { float: left; }

HTML <img class="img1" src="./images/Person1.jpg" width="300" height="300">