CSS 浮动第三个元素,其内容取决于宽度

发布于 2024-11-18 00:04:05 字数 668 浏览 2 评论 0原文

我正在为他们动态添加的一家餐厅制作菜单。看起来像这样

Dish Name                                            Price
Content in the dish,Content in the dish,Content in the dish,
Content in the dish,Content in the dish.

我想要做的是用 来点缀空白区域。或虚线边框。 但我不知道如何让 css 自动调整空白 div 的宽度。 菜名可以比“菜名”更长。 Any1对此有解决方案吗?

编辑 价格和名称位于 2 个 div 中,上面已经有浮动了

.dishHead 
{
font-family:Verdana;
font-size: 18px;
color:#262626;  
float:left;
font-weight:200;
}

.dishPrice
{
font-family:Verdana;
font-size: 14px;
color:#262626;  
float:right;
}

Edit2: 整个结构如下:

一个向右或向左浮动的div 左边的浮动头,右边的浮动价格,以及下面的说明。 我需要在 head 和 Price 之间有一个 div,而不影响它所在的​​整个 div

I'm doing a menu for a restaurant that they dynamiclly add. it looks like this

Dish Name                                            Price
Content in the dish,Content in the dish,Content in the dish,
Content in the dish,Content in the dish.

What i want to do is to get the blank space dotted, with . or dotted border.
But i cannot figure out how to get the css to autoadjust the width of the blank space div.
The dishnames could be longer then "dishname".
Any1 have a solution for this?

EDIT
The price and name is in 2 divs already with floats on them

.dishHead 
{
font-family:Verdana;
font-size: 18px;
color:#262626;  
float:left;
font-weight:200;
}

.dishPrice
{
font-family:Verdana;
font-size: 14px;
color:#262626;  
float:right;
}

Edit2:
The whole thing is structured as below:

a div that floats right or left
the left floating head, the right floating price, and a description below.
I need a div between the head and price without affecting the whole div it lies in

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

—━☆沉默づ 2024-11-25 00:04:05

我想我会在整个“标题”部分使用背景图像,然后在名称和价格 div 上使用背景颜色来覆盖图像,但这只有在背景是纯色时才有效。

为了回答您的问题,让第三个 div 占据左右 div 之间的剩余空间,您将在其上使用 overflow:hidden ,因此使用虚线边框的示例可能如下所示:

< a href="http://jsfiddle.net/clairesuzy/Q6WAx/" rel="nofollow noreferrer">示例 Fiddle

CSS:

.dishHead {
  font-family:Verdana;
  font-size: 18px;
  color:#262626;  
  float:left;
  font-weight:200;
}

.dishPrice {
  font-family:Verdana;
  font-size: 14px;
  color:#262626;  
  float:right;
}

.spacer {
  overflow: hidden;
  border-bottom: 3px dotted #000;
}

HTML:

<div class="dishHead">Dish Name</div>
<div class="dishPrice">Price</div>
<div class="spacer"> </div>
<div class="dishContent">
Content in the dish,Content in the dish, Content in the dish,
Content in the dish,Content in the dish.
</div>

I think I would do it with a background image on the whole of the "heading" part then use a background color on the name and price div to cover the image however that will only work if the background is a plain colour.

In answer to your question to get a third div to take up the remaining space between the left and right divs you would use overflow:hidden on it so an example using a dotted border might look like this:

Example Fiddle

CSS:

.dishHead {
  font-family:Verdana;
  font-size: 18px;
  color:#262626;  
  float:left;
  font-weight:200;
}

.dishPrice {
  font-family:Verdana;
  font-size: 14px;
  color:#262626;  
  float:right;
}

.spacer {
  overflow: hidden;
  border-bottom: 3px dotted #000;
}

HTML:

<div class="dishHead">Dish Name</div>
<div class="dishPrice">Price</div>
<div class="spacer"> </div>
<div class="dishContent">
Content in the dish,Content in the dish, Content in the dish,
Content in the dish,Content in the dish.
</div>
芯好空 2024-11-25 00:04:05

您可以在带有菜肴名称的元素中放置很多点,并使用以下 css:

.dishname { 
   width:400px;
   overflow:hidden; 
   white-space:nowrap;
}

You could place lots of dots in an element with dishname and use the fallowing css:

.dishname { 
   width:400px;
   overflow:hidden; 
   white-space:nowrap;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文