HTML span span center不工作? [英] HTML span align center not working?

查看:401
本文介绍了HTML span span center不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些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>


解决方案

div是一个块元素,除非设置宽度,否则容器的宽度。 span是一个内联元素,并且将具有其中文本的宽度。目前,您正尝试将对齐设置为CSS属性。对齐是一个属性。

 < 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不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆