我正在编写一个jQuery插件,我需要做的是确定用户指定的元素的宽度.问题是.width()或.css('width')将始终报告精确的像素,即使开发人员已经使用CSS分配了宽度:90%.
有没有办法让jQuery输出px或%中元素的宽度,具体取决于开发人员用CSS给出的内容?
我试着打电话View.getMeasuredHeight和View.getHeight在onGlobalLayout.两者都给我相同的结果.
我想知道,在什么情况下他们的价值会有所不同?有没有例子可以证明这一点?
我试着在谷歌搜索.第一个结果似乎与此问题无关:Android:如何获得自定义View的高度和宽度?
我目前正在使用PanelWPF中的s,我注意到关于Width和Height属性,还有另外两个属性叫做ActualWidth和ActualHeight.
ActualWidth获取此元素的呈现宽度.这是一个依赖属性.(继承自FrameworkElement.)
Width获取或设置元素的宽度.这是一个依赖属性.(继承自FrameworkElement.)
参考:MSDN
任何人都可以指出两者之间的差异以及何时使用其中任何一个?
我有这个HTML
div#permalink_section {
width: 960px
}Run Code Online (Sandbox Code Playgroud)
目前,这个CSS
<div id='permalink_section'>
<a href="here goes a very long link">here goes a very very long link</a>
</div>Run Code Online (Sandbox Code Playgroud)
链接文本可能很长,当它的长度超过div宽度时它会溢出div.当宽度超过div宽度时,有没有办法强制链接断开并继续下一行?
好吧我正在使用jQuery并且当前获得滚动条的最大值:
var $body = $('body');
$body.scrollLeft(99999); // will give me the max value since I've overshot
var max_value = $body.scrollLeft(); // returns 300
$('body').scrollLeft(0);
Run Code Online (Sandbox Code Playgroud)
当我尝试这个:$body[0].scrollWidth我只是获得内容的实际宽度 - 1580
我想我必须忘记一个更好的方法.
编辑
为了澄清,我也试过$(window).width(),$(document).width()分别给了我1280和1580.
如何使包含2列(单元格)的表格如下所示:
例:
<table style="width: 500px;">
<tr>
<td>foo</td>
<td>bar</td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
我需要这个表看起来像这样:
.___________________________________________________________________________.
| foo | bar <a lot of space here> |
|_____|_____________________________________________________________________|
500 px total width
Run Code Online (Sandbox Code Playgroud)
注意:我不知道"foo"的宽度,所以我不能设置"50px","10%"或类似的东西.
这是一个假设的例子:
table, thead, tbody, tr { width: 100%; }
table { table-layout: fixed }
table > thead > tr > th { width: auto; }Run Code Online (Sandbox Code Playgroud)
<table>
<thead>
<tr>
<th>Column A</th>
<th>Column B</th>
<th>Column C</th>
<th class="absorbing-column">Column D</th>
</tr>
</thead>
<tbody>
<tr>
<td>Data A.1 lorem</td>
<td>Data B.1 ip</td>
<td>Data C.1 sum l</td>
<td>Data D.1</td>
</tr>
<tr>
<td>Data A.2 ipsum</td>
<td>Data B.2 lorem</td>
<td>Data C.2 some data</td>
<td>Data D.2 a long line of text that is long</td>
</tr>
<tr>
<td>Data A.3</td>
<td>Data …Run Code Online (Sandbox Code Playgroud)我正在使用jQuery(v1.7.1),我需要得到一个元素的绝对浮点宽度,但所有jQuery的宽度方法似乎都是对宽度值进行四舍五入.
例如,如果元素的实际宽度是20.333333px,则jQuery的width方法返回20,即忽略小数值.
你可以在这个jsFiddle上看到我的意思
所以,我的问题是:如何获得元素宽度的浮点值?
我有一个ListBox带ItemTemplate组成的TextBlock和ComboBox.问题是TextBlock每个项目内部文本的宽度不同,ComboBox控件未对齐.
如何TextBlock在模板中设置所有项目的宽度相同,哪个是最宽的?
这是我的xaml:
<ListBox MinHeight="100" ItemsSource="{Binding Trainees}">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Margin="1">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock VerticalAlignment="Center" Grid.Column="0">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0}, {1}">
<Binding Path="LastName" />
<Binding Path="FirstName" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
<ComboBox HorizontalAlignment="Left" Grid.Column="1"
ItemsSource="{Binding Source={StaticResource Functions}}" SelectedValue="{Binding Path=Function}"
MinWidth="100" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Run Code Online (Sandbox Code Playgroud) 内联块在它们之间有这个奇怪的空间.我可以忍受它,直到某一点,如果我用AJAX调用加载更多内容,那么微小的空间就会消失.我知道我在这里遗漏了一些东西.
div {
width: 100px;
height: auto;
border: 1px solid red;
outline: 1px solid blue;
margin: 0;
padding: 0;
display: inline-block;
}
Run Code Online (Sandbox Code Playgroud)
如何使Inline块中的间距保持一致?
width ×10
css ×6
html ×3
html-table ×2
jquery ×2
wpf ×2
actualwidth ×1
android ×1
itemtemplate ×1
javascript ×1
listbox ×1
scrollbar ×1
size ×1
view ×1
word-wrap ×1