html - 多行对齐和段落背景

标签 html css alignment width background-color

我无法混合渲染文本的两个要求。

我需要能够允许 2 种不同的对齐方式。第一个是经典对齐方式:区域中的左、中、右。二是之后的文字对齐。例如,它可以在区域中左对齐,然后在文本中右对齐,或者文本居中对齐,然后文本在文本中右对齐(见上图)。

示例 1: enter image description here 示例 2: enter image description here

这是我当前的实现:https://jsfiddle.net/2vsxfzLd/4/

<div class="container" id="container">
    <p id="captionRegion" class="captionRegion" style="width: 90%; height: 20%; left: 5%; top: 50%; padding: 0%; -webkit-writing-mode: horizontal-tb; text-align: center; background-color: blue;">
        <span class="outerSpan" style="line-height: 18vh; text-align: end; display: inline-block; width: initial;">
            <span class="innerSpan" style="font-size: 24px; line-height: 30px; color: rgb(255, 255, 255); font-style: normal; font-weight: normal; text-decoration: none; font-family: Arial; padding-left: 12.8px; padding-right: 12.8px; vertical-align: middle; width: 100%; background-color: rgb(100, 100, 100);">
                This is center textAlign <br> 
                text aligned "end" inside the box.
            </span>
        </span>
    </p>
</div>

使用以下 CSS:

.container{
    width:160vh; /* 16:9 */
    height:90vh; /* 16:9 */
    position: absolute;
    display: block;
    overflow: hidden;
    margin: 0;
}

.captionRegion{
    position: absolute;
    z-index: 2147483647;
    margin: 0;
    }

.innerSpan{
    display: inline-block;
    line-height: initial;
}

问题是我希望我的灰色文本背景颜色占据 100% 的宽度。

(innerSpan - 显示:内联 block )。

这只能通过将 outerSpan 置于显示模式 inline-block 来实现,这会取消多重对齐。

有什么想法吗?

最佳答案

所以我这样做了:https://jsfiddle.net/2vsxfzLd/9/

感谢 flex 盒子。

<div class="container" id="container">
    <div id="captionRegion" class="captionRegion">
        <div class="outerParagraph">
            <div class="innerSpan">
                <span style="background-color: yellow; color: red; padding-left: 12px; line-height: initial;">
                This is center textAlign
                <br/>text aligned "end" inside the box.
                </span>
            </div>
        </div>
    </div>
</div>

关于html - 多行对齐和段落背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30982640/

相关文章:

jsf - 将单选按钮分解为 JSF 中的列

javascript - 使用 Jquery 将 HTML 标签属性值存储在变量中

jquery - 如何使用 jQuery 垂直对齐具有不同高度的多个图像?

javascript - 使用输入类获取经过验证的输入的父级

javascript - 将 If else 条件添加到点击功能

html - 按顺序对齐具有不同高度的两列中的元素

c - 多个格式说明符的 printf 对齐

html - 无法使用 Bootstrap 更改图像的宽度

html - 暂停 HTML5 音频元素会导致整个文件被下载

javascript - 如何更改 html 文本区域中的输入法(即外语)