问题描述
我有一些HTML:
< div align =centerstyle =border:1px solid red> ;
这是div元素中的一些文本!
< / div>
Div正在改变文档的间距,所以我想用一个跨距来代替。
但是span并未集中处理内容: $ < span style =border:1px solid red; align = center>
这是div元素中的一些文本!
< / span>
我该如何解决这个问题?
编辑:
我的完整代码:
< html>
< body>
< p>这是一段。此文字未指定任何对齐方式。< / p>
< span style =border:1px solid red; text-align = center>
这是div元素中的一些文本!
< / span>
< / body>
< / html>
< span align =centerstyle =border:1px solid red;>
这是div元素中的一些文本!
< / span>
但是,align属性已被弃用。您应该在容器上使用CSS text-align
属性。
< div style =text-align:center;>
< span style =border:1px solid red;>
这是div元素中的一些文本!
< / span>
< / div>
I have some HTML:
<div align="center" style="border:1px solid red">
This is some text in a div element!
</div>
The Div is changing the spacing on my document, so I want to use a span for this instead.
But span is not centralizing the contents:
<span style="border:1px solid red;align=center">
This is some text in a div element!
</span>
How do I fix this?
EDIT:
My complete code:
<html>
<body>
<p>This is a paragraph. This text has no alignment specified.</p>
<span style="border:1px solid red;text-align=center">
This is some text in a div element!
</span>
</body>
</html>
A div is a block element, and will span the width of the container unless a width is set. A span is an inline element, and will have the width of the text inside it. Currently, you are trying to set align as a CSS property. Align is an attribute.
<span align="center" style="border:1px solid red;">
This is some text in a div element!
</span>
However, the align attribute is deprecated. You should use the CSS text-align
property on the container.
<div style="text-align: center;">
<span style="border:1px solid red;">
This is some text in a div element!
</span>
</div>
这篇关于HTML span span center不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!