首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > CSS >

div前前后后都是文字,想要在同一行上显示,发现变形了,加了float,clear都不行?

2013-04-09 
div前后都是文字,想要在同一行上显示,发现变形了,加了float,clear都不行??我想要在一行上输出“第2个div s

div前后都是文字,想要在同一行上显示,发现变形了,加了float,clear都不行??
我想要在一行上输出“  第2个<div style="bluestyle">的颜色”;
div中间是颜色,可是我写完后发现为啥div前后的文字不能出现在同一行?
写出这样也不行啊:<div>第2个<div><div style="bluestyle"><div>的颜色<div>


[解决办法]
你可以不用div,用span

[解决办法]
还有style="bluestyle" 这个是不合法的,浏览器无法解析
[解决办法]
你的div有封口么?style这样写是什么意思?
[解决办法]
楼主,div你都没有闭合的,而且div是块状元素,默认情况下,多个div肯定会换行显示的,给楼主整了下:


<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>div测试</title>
        <style>
            .bluestyle{
padding:0px 35px;
display:inline;
background-color:blue;
}
        </style>
    </head>
    <body>
        <div style="display:inline;">第2个</div><div class="bluestyle"></div><div style="display:inline;">的颜色</div>
    </body>
</html>

一般像这种在一行显示的用span就可以了,如下:

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>div测试</title>
        <style>
            .bluestyle{
padding:0px 35px;
display:inline;
background-color:blue;
}
        </style>
    </head>
    <body>
<span>第2个</span><span class="bluestyle"></span><span>的颜色</span>
    </body>
</html>

热点排行