html - 两个句子之间的虚线但句子是固定宽度的

标签 html css

我想要两个固定宽度的句子:30%,但我的第一个 div“words”转到下一行。 class="left"words 显示不正确,另一个我的第二个下一个 div "words"mixed 与这个 first div

HTML

<div class="bg">
    <span class="left">Hello Hello Hello Hello my text is missing plz show</span>
    <span class="right">My friend.</span>
</div>
  <div class="clear"></div>
<div class="bg">
    <span class="left">sohan sohan sohan sohan sohan sohan sohan</span>
    <span class="right">My friend.</span>
</div>

CSS

.bg{width:90%; margin:0 auto; position:relative;}
.bg .left{width:auto; max-width:30%; min-width:10%; position:absolute; text-align:justify; background-color:white;}
.bg .right{width:auto; max-width:30%; min-width:10%; float:right; overflow-x:hidden; overflow-y:hidden; text-align:justify; background-color:white;}
.bg .left:before {
    float: left;
    width: 0;
    white-space: nowrap;
    content:
 ". . . . . . . . . . . . . . . . . . . . "
 ". . . . . . . . . . . . . . . . . . . . "
 ". . . . . . . . . . . . . . . . ."}
.clear{clear:both;}

结果

Hello Hello Hello Hello.................................... My friend.
sohan sohan sohan ......................................... My Friend.
sohan sohan sohan sohan

最佳答案

.bg.left 中删除 position:absolute 并添加 display:inline-block 以重新建立允许宽度的 block 上下文在您的 span 上设置(默认情况下是内联元素,因此不遵守宽度声明)。此外,您应该在 .bg .left:before 上更改为 float:right

Your fixed Example

关于html - 两个句子之间的虚线但句子是固定宽度的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17315648/

相关文章:

javascript - Rest API 显示 [object Object] 而不是数组对象

javascript - 单击阅读更多信息时如何使每个框展开

jquery - 如何拥有清晰、锐利和 slim 的 jqueryUI GUI 元素?

jquery - 页面响应时隐藏 Bootstrap 下拉菜单

HTML CSS : odd behavior that I can't understand, 添加边框时多余空间消失

javascript - 下拉按钮只能使用一次

javascript - 显示/隐藏一个 div 有条件地点击另一个 div 中的链接

javascript - 这种效果应该叫什么?

javascript - HTML5 音频元素在移动设备上不起作用

css - href#section 标签在 safari 中不起作用