我有类似的东西:
<div style="width:100px;float:left">menu</div>
<div style="float:left">content</div>
Run Code Online (Sandbox Code Playgroud)
两个花车都是必需的.我希望内容div填充整个屏幕减去菜单的100px.如果我不使用浮动,div就会完全扩展.但是如何在设置浮点数时设置它?如果我使用......
style=width:100%
Run Code Online (Sandbox Code Playgroud)
然后内容div获取父级的大小,它是我也尝试过的主体或另一个div,因此它当然不适合菜单,然后显示如下.
似乎在jQuery中,当元素不可见时,width()返回0.有道理,但我需要获取表的宽度,以便在显示父级之前设置父级的宽度.
如下所述,父母中有文本,使父母倾斜并且看起来很讨厌.我希望父级只有表格的宽度并且包含文本.
<div id="parent">
Text here ... Can get very long and skew the parent
<table> ... </table>
Text here too ... which is why I want to shrink the parent based on the table
</div>
Run Code Online (Sandbox Code Playgroud)
CSS:
#parent
{
display: none;
}
Run Code Online (Sandbox Code Playgroud)
使用Javascript:
var tableWidth = $('#parent').children('table').outerWidth();
if (tableWidth > $('#parent').width())
{
$('#parent').width(tableWidth);
}
Run Code Online (Sandbox Code Playgroud)
tableWidth总是返回0,因为它不可见(我猜是因为它在可见时给了我一个数字).有没有办法获得表格的宽度而不使父母可见?
我已经为此工作了大约2天,所以我想我和你分享我的经验.
问题是:是否可以使分组的UITableView中的单元格宽度更小?
答案是不.
但是有两种方法可以解决这个问题.
解决方案#1:更薄的表 可以更改tableView的框架,以便表格更小.这将导致UITableView以减小的宽度渲染内部单元格.
对此的解决方案可能如下所示:
-(void)viewWillAppear:(BOOL)animated
{
CGFloat tableBorderLeft = 20;
CGFloat tableBorderRight = 20;
CGRect tableRect = self.view.frame;
tableRect.origin.x += tableBorderLeft; // make the table begin a few pixels right from its origin
tableRect.size.width -= tableBorderLeft + tableBorderRight; // reduce the width of the table
tableView.frame = tableRect;
}
Run Code Online (Sandbox Code Playgroud)
解决方案#2:让图像呈现细胞
此解决方案在此处描述:http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html
我希望这些信息对您有所帮助.我花了大约2天时间尝试了很多可能性.这就是剩下的.
我正在使用jquery编写一个站点,该站点反复调用$(window).width()并$(window).height()根据视口大小定位和调整元素大小.
在故障排除中,我发现在未调整视口大小时,在重复调用上述jquery函数时,我的视口大小报告略有不同.
想知道是否有任何特殊情况,任何人都知道这种情况何时发生,或者这是否就是这样.显示的尺寸差异为20px或更小.它发生在Mac OS X 10.6.2上的Safari 4.0.4,Firefox 3.6.2和Chrome 5.0.342.7 beta中.我还没有测试其他浏览器,因为它似乎并不特定于浏览器.我也无法弄清楚差异取决于什么,如果它不是视口大小,是否会有另一个因素导致结果不同?
任何见解将不胜感激.
更新:
这不是值$(window).width(),并$(window).height()正在改变.这是我用来存储上述值的变量的值.
它不是影响值的滚动条,变量值更改时不会显示滚动条.这是我的代码将值存储在我的变量中(我正在做的只是因为它们更短).
(这一切都在$(document).ready())
//最初声明变量对于其中的otehr函数是可见的 .ready()
var windowWidth = $(window).width(); //retrieve current window width
var windowHeight = $(window).height(); //retrieve current window height
var documentWidth = $(document).width(); //retrieve current document width
var documentHeight = $(document).height(); //retrieve current document height
var vScrollPosition = $(document).scrollTop(); //retrieve the document scroll ToP position
var hScrollPosition = $(document).scrollLeft(); //retrieve the document scroll Left position
function …Run Code Online (Sandbox Code Playgroud) 有谁知道为什么宽度为100%的输入元素超过了表格的单元格边框.
在下面的简单示例输入框中查看表格的单元格边框,结果很可怕.这已经过测试,它以相同的方式发生:Firefox,IE7和Safari.
这对你有意义吗?我错过了什么,你知道可能的解决方案吗?
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <!-- don't use closing slash in meta tag, it breaks HTML4.01 transitional -->
<title>Test input text in table</title>
<style type="text/css">
table {border-top: 1px solid #ff0000; border-left: 1px solid #ff0000;}
table td {border-right: 1px solid #00ff00; border-bottom: 1px solid #00ff00;}
input[type="text"] {width: 100%;} /* removing this would make input not to go over cells border, but they would be too short, I want them to …Run Code Online (Sandbox Code Playgroud) 我有一个图形插件,<table>可以在其容器中插入画布和图例.在这个插件table中没有width定义,在我的CSS中,我的插件插入了容器内的表的宽度.
所以,新的div继承table{ width: 100%}自CSS并呈现错误.
我尝试使用width: initial;,在Chrome上看起来不错,但IE不喜欢它 检查浏览器兼容性
我承认在脚本/插件中更改/强制内联CSS,因为它必须在任何环境中工作.
这里最好的解决方案是什么?
我正在尝试为DIV添加宽度,但我似乎遇到了问题,因为它没有内容.这是我到目前为止的CSS和HTML,但它不起作用:
body{
margin:0 auto;
width:1000px
}
ul{
width:800px;
}
ul li{
clear:both;
}
.test1{
width:200px;
float:left;
}
Run Code Online (Sandbox Code Playgroud)
<body>
<div id="test">
<ul>
<li>
<div class="test1">width1</div>
<div class="test1">width2</div>
<div class="test1">width3</div>
</li>
<li>
<div class="test1"></div>
<div class="test1">width2</div>
<div class="test1">width3</div>
</li>
<li>
<div class="test1"></div>
<div class="test1">width2</div>
<div class="test1">width3</div>
</li>
</ul>
</div>
Run Code Online (Sandbox Code Playgroud)
setWidth(int pixels)是否使用设备无关像素或物理像素作为单位?例如,setWidth(100)是否将视图的宽度设置为100 dips或100 pxs?
谢谢.
android pixels units-of-measurement width density-independent-pixel
我有一个元素,需要它的宽度没有(!)垂直滚动条.
Firebug告诉我身体宽度是1280px.
这些都可以在Firefox中正常工作:
console.log($('.element').outerWidth() );
console.log($('.element').outerWidth(true) );
$detour = $('.child-of-element').offsetParent();
console.log( $detour.innerWidth() );
Run Code Online (Sandbox Code Playgroud)
他们都返回1263px,这是我正在寻找的价值.
但是所有其他浏览器都给我1280px.
是否有跨浏览器的方式来获得没有(!)垂直滚动条的全屏宽度?
我一直在寻找一种从我的C程序中获取终端宽度的方法.我一直想出的是:
#include <sys/ioctl.h>
#include <stdio.h>
int main (void)
{
struct ttysize ts;
ioctl(0, TIOCGSIZE, &ts);
printf ("lines %d\n", ts.ts_lines);
printf ("columns %d\n", ts.ts_cols);
}
Run Code Online (Sandbox Code Playgroud)
但每次我尝试我得到
austin@:~$ gcc test.c -o test
test.c: In function ‘main’:
test.c:6: error: storage size of ‘ts’ isn’t known
test.c:7: error: ‘TIOCGSIZE’ undeclared (first use in this function)
test.c:7: error: (Each undeclared identifier is reported only once
test.c:7: error: for each function it appears in.)
Run Code Online (Sandbox Code Playgroud)
这是最好的方法吗,还是有更好的方法?如果不是,我怎么能让它工作?
编辑:固定代码是
#include <sys/ioctl.h>
#include <stdio.h>
int main (void)
{
struct winsize …Run Code Online (Sandbox Code Playgroud)