简体   繁体   English

如何将图像浮动到居中的div旁边?

[英]How can I have an image float next to a centered div?

How can I make a image float next to a centered box? 如何使图像浮动在居中的框旁边? What would be the correct HTML/CSS-code? 什么是正确的HTML / CSS代码? Here's a outline of what I'm trying to make: 这是我想要做的概述:

在此输入图像描述

Thanks in advance. 提前致谢。

Place your image inside the centered div. 将图像放在居中的div中。 Give the centered div position:relative . 给出居中的div position:relative Now give the image position:absolute and left:-XXpx where XX is the width of your image. 现在给图像position:absoluteleft:-XXpx其中XX是图像的宽度。

Place the image inside of a floating div and then put the floating div anywhere you want. 将图像放在浮动div中,然后将浮动div放在任何您想要的位置。

Here's some HTML to create the div and an image placeholder... Simply change the top and left values in the #layer1 css code below to position the div... 这里有一些用于创建div和图像占位符的HTML ...只需更改下面#layer1 css代码中的顶部和左侧值来定位div ...

It would probably be in your interest to wrap most page elements in their own divs so you can layout the page without using a table. 将大多数页面元素包装在自己的div中可能符合您的兴趣,因此您可以在不使用表格的情况下布局页面。

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
#Layer1 {
position:absolute;
width:200px;
height:115px;
z-index:1;
left: 475px;
top: 291px;

} --> } - >

<body>
<div id="Layer1"><img src="" alt="" name="someimage" width="32" height="32" id="someimage" /></div>
</body>
</html>

Good Luck, 祝好运,

Rodney Barbati 罗德尼巴尔巴蒂

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM