2017-01-26 44 views
0

所以我目前正在我的网站上工作......并且当我尝试将图像添加到页面时遇到了问题。所以我加入这个起步的主页 -我应该在我的网站上使用什么位置[建议需要]

#titleOne, #paraOne, #paraTwo, #paraThree{ 
 
\t text-align: center; 
 
}
<!DOCTYPE html> 
 
\t <html> 
 
\t \t <head> 
 
\t \t \t <link rel="stylesheet" type="text/css" href="style.css"> 
 
\t \t </head> 
 
\t <body> \t 
 
     <center> 
 
\t \t <h1 id="titleOne">Hello!</h1> 
 
\t \t <p id="paraOne">This is my first website!</p> 
 

 
\t \t <hr> 
 

 
\t \t <p id="paraTwo">Hopefully this isn't too boring :/ stay and you might like what you see in the future!</p> 
 
\t \t <p id="paraThree">Fact: I will not stop until I get it done.</p> 
 

 
    </center> 
 
\t </body> 
 
\t </html>

这工作不错,一切都在市中心,看上去很不错!但是现在,当我尝试添加图像并将其添加到中心标签时,它将添加到中心。我不希望那样...我想让图像进入屏幕的右上方,但有几个百分点的间隙,所以它不会卡在屏幕的一侧。我似乎无法做到这一点,因为这样做我必须表明立场:绝对的;当我做所有事情都不合时宜的时候。你们会推荐什么?这是图片代码。

#img { 
 
    /*position: absolute;*/ 
 
\t width: 100px; 
 
\t height: 100px; 
 
\t border-radius: 100%; 
 
\t -webkit-animation: fadein 2s; 
 
} 
 

 
@keyframes fadein { 
 
\t from { opacity: 0; } 
 
\t to { opacity: 1; } 
 
}
<img id="img" src="imgs/meFive.JPG" alt="My picture" >

谢谢!

+0

添加绝对定位到一个元素不会敲别的一切不合适的地方,一定有别的东西造成它。 –

+0

中心标记已弃用,因此您应该在DIV中进行转换,并最终通过CSS将文本居中放置。关于图片,请使用float:right – Massimo

回答

0

你不应该把图像放在中心标签。你应该把中央标签

img { 
    width: 100px; 
    height: 100px; 
    border-radius: 100%; 
    -webkit-animation: fadein 2s; 
    position: absolute; 
    top: 0px; 
    right: 0px; 
} 
0

外正如你可以看到下面,绝对定位的元素不会改变什么已经在页面上使用:

#img { 
    position: absolute; 
    right: 0; 
    top: 0; 
    margin: 3%; 
    width: 100px; 
    height: 100px; 
    background: red; 
} 

#titleOne, #paraOne, #paraTwo, #paraThree{ 
 
\t text-align: center; 
 
} 
 
#img { 
 
    position: absolute; 
 
    right: 0; 
 
    top: 0; 
 
    margin: 3%; 
 
    width: 100px; 
 
    height: 100px; 
 
    background: red; 
 
}
<!DOCTYPE html> 
 
\t <html> 
 
\t \t <head> 
 
\t \t \t <link rel="stylesheet" type="text/css" href="style.css"> 
 
\t \t </head> 
 
\t <body> \t <img id="img" src="imgs/meFive.JPG" alt="My picture" > 
 
     <center> 
 
\t \t <h1 id="titleOne">Hello!</h1> 
 
\t \t <p id="paraOne">This is my first website!</p> 
 

 
\t \t <hr> 
 

 
\t \t <p id="paraTwo">Hopefully this isn't too boring :/ stay and you might like what you see in the future!</p> 
 
\t \t <p id="paraThree">Fact: I will not stop until I get it done.</p> 
 

 
    </center> 
 
\t </body> 
 
\t </html>

0

我真的不明白你想做什么! 但记得当你想使用position: absolute;该元素的父母必须有一个位置。不要紧,哪个位置relative, absolute, ...但它必须有一个OR元素在屏幕上或在一些奇怪的地方(通常基于窗口屏幕位置)

相关问题