3个div,中间div需要是一个可变长度的虚线

问题描述 投票:1回答:3

我想创建一个餐厅风格的菜单卡。

我不想使用表格。我试图仅使用DIV来完成此任务。

这就是我所拥有的:

.review-row {  // (1)
    padding: 0;
}

.review-cat {  // (2)
    font-size: 25px;
    float: left;
}

.review-dots {  // (3)
    padding-bottom: 5px;
    float: left;
}

.review-dots-inner {  // (3)
    height: 5px;
    border-bottom: 3px dotted #E65540;
}

.review-rating {  // (4)
    float: right;
    font-size: 50px;
}

在图像中将(3)视为2 DIVS,内部div用于获得与文本在同一基线上的点。

现在这不起作用。如何进行?

  • 所有DIV都应根据内容调整宽度
  • 中间DIV需要充当“填充物”
css html positioning
3个回答
2
投票

你不需要图像..见工作example here ..

请执行下列操作..

 <!--Markup and styles-->
<div class="item-container">
    <span class="item">Quality</span>
    <span class="fill"></span>
    <span class="score">8.0</span>
</div>
<div class="item-container">
    <span class="item">Presentation</span>
    <span class="fill"></span>
    <span class="score">9.5</span>
</div>
<style>
    .item-container{
    width:200px;
    /*border:1px solid #AAA;*/
    display:block;
    padding:5px;
    margin:2px;    
}

.item{
    float:left;   
    margin:2px; 
}
.score{
    float:right;
    margin:2px;
}
.fill{
    border:none;
    border-bottom:1px dotted #000;
    display:inline-block;
}
</style>

并在你的$().ready()做这个

$('.item-container').each(function(){
    //alert($('.fill', $(this)).width());
    var item = $('.item', $(this));
    var score = $('.score', $(this));
    var itemWidth = item.width();
    var scoreWidth = score.width();

    var offset1 = item.offset().left;
    var offset2 = score.offset().left;
    var fillerWidth = (offset2 - offset1) - (itemWidth + scoreWidth);

    $('.fill', $(this)).css('width', fillerWidth + 10);
});

0
投票

您可以将点设置为重复背景,然后为.review-cat和.review-rating添加白色(或其他)背景。

这样你就可以继续前进,将等级浮动到右边,确保它在html之前的第一个(2)浮动到左边。

background-color: white;是你需要做的

对于.review-row,你需要将点添加为重复背景background: transparent url(../images/dots.png) repeat 0 0;

祝好运


0
投票

使用Flexbox轻松:)。看到工作example here ..

<div class="row">
  <div class="text-box">Breakfast</div>
  <div class="dots-box"></div>
  <div class="text-box">8:30 am - 9:30 am</div>
</div>

CSS

.row{
  display: flex;
  overflow:hidden;
  padding:15px;
  width:90%;
}
.text-box{
  flex: 0 0 auto;
}
.dots-box{
  flex: 1 1 auto;
  position: relative;
}
.dots-box:before{
  position:absolute;
  bottom: 5px;
  width: 94%;
  border-bottom: 1px dotted #000;
  content: '';
  left: 3%;
}
© www.soinside.com 2019 - 2024. All rights reserved.