考虑下面的代码,其中span元素浮动在其中div,如何div围绕浮动子元素进行环绕,以便1px边框包装子元素?
<div style="border:1px solid #000">
<span style="float:left">Content</span>
<span style="float:left">Content</span>
<span style="float:left">Content</span>
</div>
Run Code Online (Sandbox Code Playgroud) 我有一个div左浮动和一个div浮动右,我想改变背景颜色.它会改变背景,但它会在浮动div之前停止.当我把它们取下时,它会继续保持我想要的正确背景颜色.
<div style='clear:both;border-bottom:3px solid #999;border-top:#333 solid thin;background:#D7E7E8;position:relative;'>
<div style='width:1091px;margin:0 auto;margin-top:70px;'>
<div style='float:left;width:200px;border:thin solid black;margin-bottom:50px;position:relative;'>
float LEFT
</div>
<div style='float:right;border:thin solid black; width:800px;border:thin solid black;margin-bottom:50px;position:relative;'>
float RIGHT
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
谢谢!
我正在使用以下CSS来安排盒子列表:
li {
display: block;
float: left;
}
Run Code Online (Sandbox Code Playgroud)
我想仔细调整<li>项目的边距,以便行上的最后一项(水平跨度)获得不同的边距.
是否有任何CSS选择器可以根据其位置定位浮动元素?
在C#中,如果你有多个构造函数,你可以这样做:
public MyClass(Guid inputId, string inputName){
// do something
}
public MyClass(Guid inputId): this(inputId, "foo") {}
Run Code Online (Sandbox Code Playgroud)
这个想法当然是代码重用.但是,当需要一些复杂的逻辑时,最好的方法是什么?说我想要这个构造函数:
public MyClass(MyOtherClass inputObject)
{
Guid inputId = inputObject.ID;
MyThirdClass mc = inputObject.CreateHelper();
string inputText = mc.Text;
mc.Dispose();
// Need to call the main Constructor now with inputId and inputText
}
Run Code Online (Sandbox Code Playgroud)
这里需要说明的是,我需要创建一个对象具有使用后丢弃.(澄清:不是立即,但我必须调用Dispose()而不是等待垃圾收集)
但是,如果我在重载的构造函数中添加一些代码,我没有看到再次调用基础构造函数的方法.有没有办法从一个重载的内部调用基础构造函数?
或者是否可以使用
public MyClass(MyOtherClass inputObject): this(inputObject.ID,
inputObject.CreateHelper().Text)
{}
Run Code Online (Sandbox Code Playgroud)
这会自动从CreateHelper()中释放生成的对象吗?
编辑:谢谢到目前为止.两个问题:我不控制MyOtherClass,我没有扩展方法(只有.NET 3.0 ......).我确实控制了自己的类,因为我刚刚开始编写它,如果有一个好的方法,我没有问题重构构造函数.
我正在写一个网页,我在其中显示一些文字的标题和日期.
博客文章标题http://filesmelt.com/dl/head00.png
我的HTML:
<div class="post">
<h2>Post 1</h2>
<span class="date">February 28, 2011</span>
<div class="post-content">
...
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我的css:
.post h2
{
float: left;
}
.date
{
float: right;
}
.post-content
{
clear: both;
}
Run Code Online (Sandbox Code Playgroud)
我想要做的是垂直对齐标题和日期,使其底部匹配.现在他们没有:
带有对齐线的博客文章标题http://filesmelt.com/dl/head01.png
我尝试将div中的两个文本元素包装起来,将div设置position为relative,并在两个文本元素上使用绝对定位(并取出浮动声明).这不起作用,因为由于包装器div崩溃而没有保留上边距,即使我给它一个clearfix类.
如何转换Float64为NSStringobjective-c?
我一直在使用这种格式:
print 'blah, blah %f' %variable
Run Code Online (Sandbox Code Playgroud)
将变量放入字符串.我听说它比'+ str()+'方法更加pythonic,并且已经习惯了它.有没有办法用%f指定添加到字符串的小数位?我在提供变量之前尝试过舍入数字.
谢谢
我使用jQuery UI 1.8.16作为标签.我想在第一个标签中放置几个div作为列(带float:left属性).
但是我不能正确地做到这一点:看起来像标签不希望以正确的方式使用float属性(参见文本下的图像).
有代码:
<div id="tabs">
<ul>
<li><a href="#tabs-1">First</a></li>
<li><a href="#tabs-2">Second</a></li>
<li><a href="#tabs-3">Third</a></li>
</ul>
<div id="tabs-1">
<div style="border:1px solid red;float:left;">
some text<br>some text<br>some text<br>some text<br>some text<br>some text<br>some text<br>some text<br>
</div>
</div>
<div id="tabs-2"></div>
<div id="tabs-3"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
如何解决?
谢谢!

我试图阻止浮动(滑动)div到达包含div的底部,但它不起作用.变量bottom是包含div的页面上的最低点,但由于某种原因不能正常运行.谁有更好的方法?
$(document).ready(function () {
var top = $('#buttonsDiv').offset().top - parseFloat($('#buttonsDiv').css('margin-top').replace(/auto/, 0));
var bottom = $('#mainBody').offset().top + $('#mainBody').height();
$(window).scroll(function (event) {
// what the y position of the scroll is
var y = $(this).scrollTop();
var z = y + $('#buttonsDiv').height();
// whether that's below the form
if (y >= top && z <= bottom) {
// if so, add the fixed class
$('#buttonsDiv').addClass('fixed');
} else {
// otherwise remove it
$('#buttonsDiv').removeClass('fixed');
}
});
});
Run Code Online (Sandbox Code Playgroud)