与 CSS 中心对齐 - 既然它被替换为,它至少可以正常工作吗?
我有一个 CSS 似乎无法提供的简单请求...
我想要并排 3 个 DIV - 第一个和第三个 DIV 包含单个图像 - 第二个 DIV 包含一行文本、一个图像、另一行的文本。
它们应该出现这个
IMAGE1 TEXT1 IMAGE2
IMAGE2
TEXT2
- 这是我无法完成的工作 - TEXT1、IMAGE2 和 TEXT2 集中在第二个 DIV 的宽度内 - 像这样
MY TEXT
MY WIDER IMAGE
TEXT
CENTER 标签会在几秒钟内完成此操作,但 CSS 显然不能做如下事情就这么简单!?!?
ps 回复代码请求 - 对于初学者来说是这样的
<DIV>
<IMG src=image1.jpg>
</DIV>
<DIV>
<p>text 1</p>
<IMG src=image2.jpg>
<p>text 2</p>
</DIV>
<DIV>
<IMG src=image3.jpg>
</DIV>
基本的 CSS
.DIV {
display: inline;
float: left;
}
我所需要的就是使中心 DIV 以 CENTER 标签在毫秒内实现的方式集中对齐其内容的魔力......
而我已经尝试了多种方法,包括 inline-block、margin: auto 等 -
I have a simple request which CSS appears unable to deliver...
I'd like 3 DIVs side-by-side - the first and third DIVs contain a single image - the second DIV contains a line of text, an image, another line of text.
They should appear this
IMAGE1 TEXT1 IMAGE2
IMAGE2
TEXT2
With - and this is the bit I cannot make work - TEXT1, IMAGE2 and TEXT2 centered within the width of the 2nd DIV - something like this
MY TEXT
MY WIDER IMAGE
TEXT
The CENTER tag would have done this in seconds, but CSS cannot apparently do something as simple as that!?!?
p.s. in reply to a request for code - something like this for starters
<DIV>
<IMG src=image1.jpg>
</DIV>
<DIV>
<p>text 1</p>
<IMG src=image2.jpg>
<p>text 2</p>
</DIV>
<DIV>
<IMG src=image3.jpg>
</DIV>
The basic CSS would be
.DIV {
display: inline;
float: left;
}
All I need is the magic to make that centre DIV align it's contents centrally in the way the CENTER tag would have achieved in milliseconds...
and I've tried a variety of things including inline-block, margin: auto etc. -
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试这样的事情。
浮动
您的div
text-align:center
作为文本margin:1em auto
HTML
CSS
示例: http://jsfiddle.net/PvgSr/
Try something like this.
float
yourdiv
stext-align:center
for the textmargin:1em auto
HTML
CSS
Example: http://jsfiddle.net/PvgSr/
没有看到你的代码很难回答,但是这是一个非常简单的例子 (jsfiddle)基本上就是你所描述的。Without seeing your code it's difficult to answer butHere is a very simple example (jsfiddle) of basically what you have described.也许您应该将
放置在DIV2
中的图像和第一个文本之后。然后您应该将text-align: center
应用于DIV2
。这些是我在没有看到代码的情况下可以向您建议的唯一内容。编辑:
将
text-align: center
应用到内部段落并将图像单独居中,请参阅http://jsfiddle.net/Lapple/UAm5p/1/Probably you should place
<br>
after your image and first text inDIV2
. Then you should applytext-align: center
toDIV2
. These are the only things I can suggest you without seeing the code.EDIT:
Applied
text-align: center
to the inner paragraph and centered the image separately, please see http://jsfiddle.net/Lapple/UAm5p/1/