【问题标题】:Put an image on the right side of the page将图像放在页面的右侧
【发布时间】:2023-03-25 22:18:01
【问题描述】:

所以我有这个 Html 和 CSS 网页,我有这个联系页面。但是我想将这张图片放在页面的右侧,但如果我这样做:float: right; 它似乎不起作用。我也尝试过对齐,但显然唯一接近的是text-align。如果需要,这是我的代码(HTML): CherryPlaysRoblox

</head>
<body>
    <div class="outer">
<ul>
  <li><a href="home.html">Home</a></li>
  <li><a href="about.html">About</a></li>
  <li><a href="gallery.html">Gallery</a></li>
  <li><a href="contact.html">Contact</a></li>
        <p id="Cherry">CherryPlaysRoblox1</p>
</ul>
<div class="jumbotron">
<h1>Contact</h1>
<h4>Here are a few ways you can contact me. I will update the page when I change anything.</h4>
    </div>
</div>

<!-- EMAIL -->
<img src="_gmail.png" alt="gmail" height="30" width="35"> <h4>My email</h4>
<!-- TWITTER -->
<img src="_twitter.png.png" alt="twitter" height="35" width="35"> <h4>Username</h4>
<!-- FACEBOOK -->
<img src="_facebook.png" alt="facebook" height="35" width="35"> <h4>Username</h4>
<!-- INSTAGRAM -->
<img src="_instagram.png" alt="instagram" height="35" width="35"> <h4>Username</h4>
<!-- ME -->
<div id="PhotoOfMe">
    <img src="_Cherry.png" alt="Me" id="Me">
</div>
</body>
</html>

还有我的 CSS 代码:

#Cherry {
    color: black;
    font-family: 'Happy Monkey', cursive;
    font-size: 20px;
}    
ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: DarkOrchid;
    position: fixed;
    top: 0;
    width: 100%;
}    
li {
    float: left;
    border-right: 1px solid White;
}    
li a {
    display: block;
    color: white;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
}    
li a:hover {
    background-color: PaleVioletRed;
}    
.active {
    background-color: PaleVioletRed;
}    
/*JUMBOTRON*/
.jumbotron {
    background-color: Sandybrown !important;
    float: top; 
}    
.jumbotron, p + h1 {
    color: black !important;
    font-family: 'Happy Monkey', cursive;
}  
/*BODY*/
body {
    background-color: Peachpuff !important;
}    
h2 {
    font-family: 'Happy Monkey', cursive !important;
} 
h4 {    
}    
#me {
    float: right;
    clear: right;
}

如果能得到所有帮助,我将不胜感激!

【问题讨论】:

标签: html css image


【解决方案1】:

为了正确浮动,它需要在顶部,然后它会直接浮动到文档后面的任何内容中,因此如果您将 #me 容器推到 #email 上方,它将在右侧对齐.同样在您的 HTML 中,id 是大写的 Me,在 css 中是小写的 #me

所以推到最上面,改成小写:

...
<!-- ME -->
<div id="PhotoOfMe">
    <img src="_Cherry.png" alt="Me" id="me">
</div>
<!-- EMAIL -->
<img src="_gmail.png" alt="gmail" height="30" width="35"> <h4>My email</h4>
...

【讨论】:

  • 非常感谢!它确实有效!还有一个问题:如果您要浮动某些东西,该项目是否必须在中间的身体上的其他任何东西之前?
  • 不客气。它需要在它浮动“进入”的元素之前。您可以在 MDN developer.mozilla.org/en/docs/Web/CSS/float 上找到示例。我还建议您研究 css flexbox,因为使用它创建多列布局更容易,请参见此处:css-tricks.com/snippets/css/a-guide-to-flexbox
  • 啊啊啊!非常感谢!我会彻底检查的!
猜你喜欢
  • 1970-01-01
  • 2015-12-05
  • 2021-04-30
  • 1970-01-01
  • 2010-10-04
  • 1970-01-01
  • 2021-11-19
  • 2015-09-18
  • 1970-01-01
相关资源
最近更新 更多