我注意到有些浏览器的边距有问题,特别是当元素浮动时.例如,我正在做的这个网站在Firefox中看起来不错,但IE7似乎完全搞砸了边距.我也在几个Linux浏览器上测试它,其中一些也犯了类似的错误.
该网站是 http://w3box.com/mat
据我所知,这在FF3.0中看起来很好.尚未在FF2中看到它,或IE6.为什么会这样?是因为我有浮动的DIV具有指定的边距吗?
是否有一些我应该避免或应该采取不同的做法?
编辑:所以看起来我的标签是搞砸的源头.我将图像放置在CSS中没有定义的图像中,并且浮动图像与边距相结合.这些搞砸了所有东西,我必须重做这些.
此外,当我使用XHTML Strict时发生了一些事情:) Thanx everyone!我会尝试自己解决这个问题:)
嘿所有,我需要一些帮助,找出如何在我的CSS中覆盖"*{margin:0; padding:0;}".
原因是我有这个css:
.postcomments { width: 547px; padding: 5px 5px 5px 5px; margin: 0 0 5px 0;}
.postcomments a { text-decoration: underline;}
.postcomments ul { margin: 0; padding: 0; list-style-type: none;}
.postcomments ul li { width: 547px; margin: 0 0 5px 0; padding: 0; list-style-type: none;}
.postcomments .right { color: #474747; font-size: 11px; background: #fff url('http://www.nextbowluser.com/img/ucBG.gif') no-repeat top left; line-height: 17px; padding: 5px 0 0 0; width: 430px; position: relative; float: right; min-height: 50px;}
.postcomments .right .bottom { padding: 0 …Run Code Online (Sandbox Code Playgroud) 我刚开始使用WPF.从那时起,我就开始关注造型系统了.我来自CSS背景,我想设置百分比保证金.
<Style TargetType="TextBlock" x:Key="workflowNameTextBlock">
<Setter Property="Margin" Value="50"/>
</Style>
Run Code Online (Sandbox Code Playgroud)
当前值以像素为单位设置,但我想将其设置为%,即50%.
我怎么能得到这个?
谢谢
可能是一个令人困惑的问题标题.
具有红色矩形的网格是它应该如何看的示例.
具有蓝色矩形的网格(未出现在图像中)具有一个边距,迫使第二个网格小于我明确设置的网格.这似乎导致WPF翻转并隐藏其排列范围之外的所有内容.

我已经尝试将Clip设置为大于Grid.
我能够避免这种情况的唯一方法是编写一个自定义面板来测量它的具有PositiveInfinity约束的子节点,然后排列具有正确宽度的子节点.那种方法有很多问题.骗你的孩子是不好的.
无论如何,这是代码:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="NegativeMarginTooMuchClipping.MainWindow"
x:Name="Window"
Title="MainWindow"
Width="640"
Height="400">
<Grid>
<StackPanel Width="600" Height="300">
<Grid Margin="40,50,60,50" Background="#FFB8B8B8" Width="500" Height="50">
<Rectangle Fill="Red" HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Width="50" Margin="0,-50,0,0"/>
</Grid>
<Grid Margin="40,50,61,50" Background="#FFB8B8B8" Width="500" Height="50">
<Rectangle Fill="Blue" HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Width="50" Margin="0,-50,0,0"/>
</Grid>
</StackPanel>
</Grid>
Run Code Online (Sandbox Code Playgroud)
已知问题?我做错了吗?需要更多说明吗?
这很奇怪.我正在尝试在右浮动div旁边有一个固定宽度的div,我不想重新排序div(因为这是分布式主题).所以我在固定div上使用负边距右边,我觉得奇怪的是:如果它是-4px或更小,那么浮动移动到一边; 否则,它会保持在低于.
与戏剧的代码现场演示在jsbin,其中有这样的:
<style>
.container {
width: 200px;
height: 200px;
}
.box {
width: 100px;
height: 100px;
}
.one {
margin-right: -4px; /* If <= -4, .two box shifts up */
display: inline-block;
}
.two {
float: right;
}
</style>
<div class="container">
<div class="box one"></div>
<div class="box two"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
有人可以解释这个谜吗?在这种情况下,数字-4有什么特别之处?
让我们开始说我理解盒子模型.在我作为开发人员的短暂时间里,我试图非常贴近语义html并使用响应式设计实践.我最近在Jr. Developer的新公司找到了一份工作,而我的老兄则虔诚地反对填充.就像他不想在任何情况下都使用它一样.他希望我在所有东西上使用设置高度和宽度,如果我需要模拟填充,我必须使用边距添加子div.例如:
<div class="caption" style="padding: 5px;">
Caption
</div>
Run Code Online (Sandbox Code Playgroud)
需要成为
<div class="caption">
<div class="captionContainer" style="margin:5px;">
Caption
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我试图弄清楚为什么会这样,以及我怎么可能解释为什么我认为这很糟糕,但它不起作用.这对我来说似乎是错的.他说这是因为填充拉伸了一个元素的宽度,我用盒子大小来响应:border-box.
我必须按照他的说法去做,但有时我们谈论它,他似乎有点接受我的建议,但我不认为我说的是正确的事情.它真的更好吗?如果不是,为什么?
这个问题可能因为讨论而被关闭 - 但是这让我发疯,我不知道还有什么地方可以转.
提前致谢!
这是HTML:
<div id="menu">
<ul>
<li><a href="#">Home</a>
</li>
<li><a href="#">Blog</a>
</li>
<li><a href="#">About</a>
</li>
<li><a href="#">Contact</a>
</li>
</ul>
</div>
Run Code Online (Sandbox Code Playgroud)
这是CSS:
li {
display:inline;
padding: 10px;
}
#menu {
margin: 21px 646px 21px 646px;
}
Run Code Online (Sandbox Code Playgroud)
我似乎无法增加菜单项之间的空间.我应该怎样调整呢?
只是一个让我烦恼的快速问题:为什么要集中精力
margin:0 auto
Run Code Online (Sandbox Code Playgroud)
做得很好
display:block
Run Code Online (Sandbox Code Playgroud)
但是当显示设置为时,不会将div居中
display:inline-block
Run Code Online (Sandbox Code Playgroud)
谢谢你的回答
在Android的RelativeLayout中,我们可以使用以下代码在屏幕中央设置textView:
<TextView
android:text="This is TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
Run Code Online (Sandbox Code Playgroud)
结果:
top
-
-
-
-
This is TextView (center vertical)
-
-
-
-
bottom
Run Code Online (Sandbox Code Playgroud)
但我需要textView有点底部,我尝试添加marginTop但似乎在使用后layout_centerVertical=true变得不可能.有解决方案吗
预期结果(略微下调):
top
-
-
-
-
-
-
This is TextView (center vertical slight to bottom)
-
-
bottom
Run Code Online (Sandbox Code Playgroud) 我正在投资组合页面,我想我会添加一些证书.我已经制作了一个网格,并使用了网格中{grid-row-gap: 50px;}的其他块.但其中一个并没有落实到位.
最后一个块(.cert5)的上边距比其他块大.
我将把代码放在下面,这样你就可以看到我到目前为止所做的事情:(SideNote - 我是编码的新手,所以我可能写的不太优雅.)
这是CSS和HTML:
.certcontainer {
background-color: hsl(120, 30%, 40%);
display: grid;
grid-template-columns: 1fr 1fr;
grid-template-rows: repeat(3, 1fr);
grid-row-gap: 50px;
justify-items: center;
width: auto;
height: auto;
margin-top: 0;
margin-left: -10px;
margin-right: -8px;
}
.cert1 {
border: 30px solid transparent;
border-image: url(http://pngimage.net/wp-content/uploads/2018/06/marcos-para-fotos-dorado-png-5.png) 100 repeat;
width: 400px;
height: 247px;
margin-top: 80px;
}
.cert2 {
border: 30px solid transparent;
border-image: url(http://pngimage.net/wp-content/uploads/2018/06/marcos-para-fotos-dorado-png-5.png) 100 repeat;
width: 400px;
height: 247px;
margin-top: 80px;
}
.cert3 {
border: 30px solid transparent;
border-image: url(http://pngimage.net/wp-content/uploads/2018/06/marcos-para-fotos-dorado-png-5.png) …Run Code Online (Sandbox Code Playgroud)