开发者社区 问答 正文

如何让浮动span自动占有一行

screenshot
测试代码:

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Test</title>
    <style>
    a {
        position: relative;
        display: block;
        padding: 10px 15px;
        margin-bottom: -1px;
        background-color: #fff;
        border: 1px solid #ddd;
        text-decoration: none;
    }
    span {
           float: right;
           display: inline-block;
           min-width: 10px;
           padding: 3px 7px;
           font-size: 12px;
           font-weight: bold;
           color: #fff;
           line-height: 1;
           vertical-align: baseline;
           text-align: center;
           background-color: #999;
           border-radius: 10px;
          }
    </style>
</head>
<body>
    <a href="script:;">Lorem ipsum dolor sit amet, consectetur adipisicing<span>2014年04月25日</span></a>
</body>
</html>

展开
收起
a123456678 2016-03-25 17:09:08 2520 分享 版权
1 条回答
写回答
取消 提交回答
  • <!doctype html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <title>float:hack</title>
        <style>
            .infos {
                margin-right: 100px;
                background: #f8f8f8;
                text-align: justify;
                padding: 10px;
            }
            .main {
                width: 100%;
                float: left;
                border: 1px solid #d8d8d8;
                background: #f8f8f8;
            }
            .tag {
                clear: right;
                float: left;
                border-radius: 50px;
                background: #e5e5e5;
                font-size: 84%;
                height: 30px;
                line-height: 30px;
                color: #06f;
                margin-left: -95px;
                margin-right: 15px;
                top: 50%;
                margin-top: 5px;
                width: 80px;
                text-align: center;
            }
        </style>
    </head>
    
    <body>
        <div class="main">
            <div class="infos">
                The delete operator removes a property from an object.Unlike what common beliefs suggests, the delete operator has nothing to do with directly freeing memoryM
            </div>
        </div>
        <div class="tag">verson5.2</div>
    </body>
    
    </html>
    2019-07-17 19:14:44
    赞同 展开评论
问答地址: