English 中文(简体)
根据内容和浏览器宽度更改 div 宽度
原标题:change div width based on content and browser width

这么说吧,我有类似的东西如下:

<div id="outer">
    <img src="my_first_image.gif" alt="My first image" />
    <div id="inner_div">Some text here...</div> <img src="my_second_image.gif" alt="My second image" />
</div>

我的inner_div 包含一些文本。 我如何使它不仅显示第一个图像, 内部div 和第二个相邻的图像, 并确保我的 outer div 的全部宽度扩展到浏览器窗口的全部宽度( 我的元素仍然彼此相邻显示, 不论我内部div 中文本的长度有多长 ) 。 这是否可能只显示直线的 cs 。 还是我需要 JQuery 来做到这一点?

NOTE : 元素也必须垂直地相互和在外插管内相互集中

谢谢

问题回答

实际上,对于网络标准,您不应该将 lt; div> 放在 lt; img> ; lt; img> 旁边。

The solution to your question is to wrap all contents within #outer, say each item wrapped up in a tag, then applied some CSS to them (like float: left).
For example,

<div id="outer">
   <div class="inner"><img src=".."/></div>
   <div class="inner"><img src=".."/></div>
   <div class="inner">some very long text</div>
</div>

哪个

<style type="text/css">
   .inner {
      float: left;
   }
</style>

如果你也希望它垂直居于外, 你的CS就会像这样。

<style type="text/css">
   #outer {
      display: table;
   }
   .inner {
      display: table-cell;
      vertical-align: middle;
   }
</style>

对此有更多的办法,但我认为这是最简单的办法。

希望这能帮上忙

我想这是你想要的 如果我理解正确的话?

<style>
#outer #inner_div{float:left;}
#outer img{clear:left;}

</style>

试试这个

CSS 安保部

#outer{
  width:100%;
}
#outer div, #outer img{
  width:33%;
  display:inline-block;
  vertical-align:middle;
  text-align:center;
}

HTML HTML

<div id="outer">
  <img src="my_first_image.gif" alt="My first image" />
  <div id="inner_div">Some text here...</div>
  <img src="my_second_image.gif" alt="My second image" />
</div>

需要为 < code> inline block 进行一些跨老浏览器工作,但你明白我的意思。

Presto < a href=> http://jsfiddle.net/EPpAn/" rel="no follow" > http://jsfiddle.net/EPpAn/

我希望这是你想要的:http://jsfiddle.net/linmic/CCut8/

干杯 干杯





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签