因此警报给出了宽度和高度的未定义值.我认为来自img.onload计算的图像的w和h值没有被传递给要返回的值,或者它可能在onload计算它们之前返回w和h :
function getMeta(url){
var w; var h;
var img=new Image;
img.src=url;
img.onload=function(){w=this.width; h=this.height;};
return {w:w,h:h}
}
// "http://snook.ca/files/mootools_83_snookca.png" //1024x678
// "http://shijitht.files.wordpress.com/2010/08/github.png" //128x128
var end = getMeta("http://shijitht.files.wordpress.com/2010/08/github.png");
var w = end.w;
var h = end.h;
alert(w+'width'+h+'height');
Run Code Online (Sandbox Code Playgroud)
如何让警报显示正确的宽度和高度?
有没有办法告诉WPF中的组件占用100%的可用空间?
喜欢
width: 100%;
Run Code Online (Sandbox Code Playgroud)
在CSS中
我有这个XAML,我不知道如何强制Grid占用100%的宽度.
<ListBox Name="lstConnections">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Background="LightPink">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Text="{Binding Path=User}" Margin="4"></TextBlock>
<TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding Path=Password}" Margin="4"></TextBlock>
<TextBlock Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Text="{Binding Path=Host}" Margin="4"></TextBlock>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
结果看起来像
替代文字http://foto.darth.cz/pictures/wpf_width.jpg
我把它做成了粉红色,这显然需要多少空间.我需要使粉红色网格100%宽度.
我目前正在使用svgJavaScript中的元素.我是新手.
我的问题是我有一个svg元素,我有多个svg:g元素.在我的svg:g元素中,我有各种其他的svg元素.
<svg>
<g class="my-class">
<g class "c1">
<text style="font-size: 9" x="0" y="-4"> john </text>
<text style="font-size: 9" x="70" y="-4"> 13 </text>
</g>
<g class="c2">
<text style="font-size: 9" x="0" y="-4"> john </text>
<text style="font-size: 9" x="70" y="-4"> 13 </text>
</g>
<g class="c3">
<text style="font-size: 9" x="0" y="-4"> john </text>
<text style="font-size: 9" x="70" y="-4"> 13 </text>
</g>
</g>
</svg>
Run Code Online (Sandbox Code Playgroud)
g 动态附加在我的
g"my_class"
现在我想将svg宽度设置为宽度g.my_class宽度.
var svgWidth = $('.my-class').width()
alert(svgWidth); …Run Code Online (Sandbox Code Playgroud) 如何为宽度创建CSS规则
默认情况下使用100%宽度
如果100%宽度超过某个像素宽度(假设为512像素),则将宽度限制为此像素宽度
我不确定宽度和最大宽度关系,或者如何支持calc()或表达这一点.这需要使用最新的WebKit浏览器和Firefox 4. IE8等支持不需要
如何设置ViewGroup的最大宽度?我正在使用一个Theme.Dialog活动,然而,当调整大屏幕时,这看起来不那么好,它也有点轻量级,我不希望它占用整个屏幕.
我试过这个建议无济于事.此外,没有android:maxWidth像一些观点的属性.
有没有办法限制根LinearLayout,以便它只(例如)640 dip?我愿意为此换到另一个ViewGroup.
有什么建议?
<div id="outer" style="min-width: 2000px; min-height: 1000px; background: #3e3e3e;">
<div id="inner" style="left: 1%; top: 45px; width: 50%; height: auto; position: absolute; z-index: 1;">
<div style="background: #efffef; position: absolute; height: 400px; right: 0px; left: 0px;"></div>
</div>
</div>Run Code Online (Sandbox Code Playgroud)
我想要发生的是内部div占用给予其父div(外部)50%的空间.相反,它正在获得视口可用空间的50%,这意味着随着浏览器/视口的大小缩小,它也会缩小.
鉴于外div有min-width的2000px,我希望内部的div至少1000px宽.
我已设置width: 200px;在左侧,<div>但如果我使用浏览器检查器工具查看它,则显示实际宽度是随机的.它会根据窗口大小不断变化.
为什么宽度没有生效?
编辑:如果我删除width: 100%宽度保持固定.但我需要这样,所以#maindiv取剩余的宽度:(有没有办法让侧边栏@固定宽度和另一个<div>填充容器宽度的其余部分?width: auto;on #main不起作用..
我有一个宽度为"1*"的网格.所以我认为在运行时确定实际宽度.在该网格中,我有另一个网格,其宽度我想设置为父网格的运行时宽度.我怎么能通过绑定在xaml中做到这一点.
我似乎无法控制对话框的宽度.我有一个像这样简单的布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:theme="@android:style/Theme.Dialog">
<ScrollView
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/name_prompt_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/name_prompt"
android:padding="10dip"/>
<EditText
android:id="@+id/name_inp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:lines="1"
android:maxLines="1"
android:maxLength="48"
android:inputType="text" />
<TextView
android:id="@+id/t1_prompt_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/t1_prompt"
android:padding="10dip"/>
<Spinner
android:id="@+id/t1_inp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:lines="1"
android:maxLines="1"
android:maxLength="48"
android:inputType="text"
android:singleLine="true"
android:layout_weight="1"
android:entries= "@array/t1_allowed_values" />
</LinearLayout>
</ScrollView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
由于某种原因,对话框只有足够宽的文本输入字段大约11个字符宽.如何使对话框宽度填满屏幕?
所以我有一个小问题,我正在编写一个需要向服务器发送屏幕宽度的功能.我得到了一切工作,我使用:
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
Run Code Online (Sandbox Code Playgroud)
获得宽度.但是.getWidht()函数已被弃用,它表示你需要使用:
Point size = new Point();
display.getSize(size);
Run Code Online (Sandbox Code Playgroud)
但是这个功能只适用于api等级13或更高,而我的最小sdk是8.那我该怎么办?如果我留在getWidth是否安全?为什么要添加新功能而不使它们向后兼容?