首页 \ 问答 \ 位置绝对和溢出隐藏(Position absolute and overflow hidden)

位置绝对和溢出隐藏(Position absolute and overflow hidden)

我们有两个DIV,一个埋在另一个。 如果外部DIV不是绝对的,则绝对位置的内部DIV不会遵守外部DIV( 示例 )隐藏的溢出。

有没有机会使内部DIV服从外部DIV隐藏的溢出,而不设置外部DIV定位绝对(因为这将填补我们的完整布局)? 我们内部DIV的位置也不是一个选择,因为我们需要“扩展”TD表( 例如 )。

还有其他选择吗?


We have two DIVs, one embedded in the other. If the outer DIV is not positioned absolute then the inner DIV, which is positioned absolute, does not obey the overflow hidden of the outer DIV (example).

Is there any chance to make the inner DIV obey the overflow hidden of the outer DIV without setting the outer DIV to position absolute (cause that will muck up our complete layout)? Also position relative for our inner DIV isn't an option as we need to "grow out" of a table TD (exmple).

Are there any other options?


原文:https://stackoverflow.com/questions/4605715
更新时间:2022-10-16 21:10

最满意答案

http://jsfiddle.net/KvNVN/

您可以向它们添加类,而不是显示/隐藏每个元素:

<select id="selFather">
    <option id="fnoble" value="fnoble" class="f">a Noble (f)</option>
    <option id="mnoble" value="mnoble" class="m">a Noble (m)</option>
    <option value="merchant">a Merchant</option>
    <option value="vetwarrior">a Veteran Warrior</option>
    <option value="thief">a Thief</option>
    <option id="fnomad" value="fnomad" class="f">a Nomad (f)</option>
    <option id="mnomad" value="mnomad" class="m">a Nomad (m)</option>
</select>

接着

$('.f').hide();
$('.m').show();

您还可以创建一个CSS样式表: .f{display:none} .m{display:block;}

你的代码有问题:如果你有......

<select id="selGender">
    <option value="1" >Male</option>
    <option value="2">Female</option>
</select>

...默认选中的值为“Male”,因此如果选择它,则不会触发onchange事件。 您可以使用

<select id="selGender">
    <option selected="selected" disabled="disabled">Select gender:</option>
    <option value="1" >Male</option>
    <option value="2">Female</option>
</select>

而且,你有

if (sGender = 1)

你应该用

if (sGender == 1)

因为你正在比较,而不是设定值。

关于您的另一个问题(在表格中导航),您可以创建一个JavaScript函数来执行该操作。 但是我不太清楚你想要什么,“左边两个细胞中的第三个细胞”。

编辑:

如果我理解得很好你有一张像这样的桌子

<table id="table">
 <tbody>
   <tr>
     <td>Skill 1</td>
     <td>Skill 2</td>
     <td>Skill 3</td>
   </tr>
   <tr>
     <td>Value 1</td>
     <td>Value 2</td>
     <td>Value 3</td>
   </tr>
 </tbody>
</table>

表

你想要的

table(1,1)=Skill 1 cell
table(1,2)=Value 1 cell

table(2,1)=Skill 2 cell
table(2,2)=Value 2 cell

...

然后,

function table(col,row){
   return document.getElementById('table').tBodies[0].getElementsByTagName('tr')[row-1].getElementsByTagName('td')[col-1];
}

在这里看到: http//jsfiddle.net/UGHHd/


See http://jsfiddle.net/KvNVN/

Instead of showing/hiding each element, you can add classes to them:

<select id="selFather">
    <option id="fnoble" value="fnoble" class="f">a Noble (f)</option>
    <option id="mnoble" value="mnoble" class="m">a Noble (m)</option>
    <option value="merchant">a Merchant</option>
    <option value="vetwarrior">a Veteran Warrior</option>
    <option value="thief">a Thief</option>
    <option id="fnomad" value="fnomad" class="f">a Nomad (f)</option>
    <option id="mnomad" value="mnomad" class="m">a Nomad (m)</option>
</select>

And then

$('.f').hide();
$('.m').show();

You could also create a CSS stylesheet with: .f{display:none} .m{display:block;}

Your code has a problem: if you have ...

<select id="selGender">
    <option value="1" >Male</option>
    <option value="2">Female</option>
</select>

... the default selected value is "Male", so if you select it it doesn't trigger onchange event. You can use

<select id="selGender">
    <option selected="selected" disabled="disabled">Select gender:</option>
    <option value="1" >Male</option>
    <option value="2">Female</option>
</select>

Moreover, you have

if (sGender = 1)

You should use

if (sGender == 1)

because you are comparing, not setting values.

About your other question (navigate through a table), you can create a JavaScript function which does that. But I don't understand very well what you want with "the third cell from the left two cells down".

Edit:

If I understand well you have a table like

<table id="table">
 <tbody>
   <tr>
     <td>Skill 1</td>
     <td>Skill 2</td>
     <td>Skill 3</td>
   </tr>
   <tr>
     <td>Value 1</td>
     <td>Value 2</td>
     <td>Value 3</td>
   </tr>
 </tbody>
</table>

Table

And you want

table(1,1)=Skill 1 cell
table(1,2)=Value 1 cell

table(2,1)=Skill 2 cell
table(2,2)=Value 2 cell

...

Then,

function table(col,row){
   return document.getElementById('table').tBodies[0].getElementsByTagName('tr')[row-1].getElementsByTagName('td')[col-1];
}

See it here: http://jsfiddle.net/UGHHd/

相关问答

更多
  • 见http://jsfiddle.net/KvNVN/ 您可以向它们添加类,而不是显示/隐藏每个元素: 的值,并在剩余的代码中使用它 如果我理解正确,您可以使用以下script区域中的捕获结果生成option的selected属性 ""... 如果使用php .js file操作不是一个选项,则在select元素中使用data属性并通过.data()检索它可以工作。 然后在.ready()的末尾调用$("# ...

相关文章

更多

最新问答

更多
  • h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
  • 创建一个功能(Create a function)
  • 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
  • PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
  • Qt冻结循环的原因?(Qt freezing cause of the loop?)
  • TableView重复youtube-api结果(TableView Repeating youtube-api result)
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
  • 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
  • 以编程方式创建UITableView(Creating a UITableView Programmatically)
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
  • Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
  • 设置kotlin扩展名(Setting a kotlin extension)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 如何在vim中启用python3?(How to enable python3 in vim?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • dedecms如何安装?
  • 在哪儿学计算机最好?
  • 学php哪个的书 最好,本人菜鸟
  • 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
  • 如何覆盖错误堆栈getter(How to override Error stack getter)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
  • 电脑高中毕业学习去哪里培训
  • 正则表达式验证SMTP响应(Regex to validate SMTP Responses)