我在XAML中有一个WPF ListView/GridView规范.第一列使用CellTemplate指定图标,其他列使用DisplayMemberBinding填充自己.图标列是20宽,图标16但它们被边距/填充/东西截断.我无法确定它的位置.
这是必需品(我删除了一些列,因为它们是相同的):
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
<Setter Property="FontWeight" Value="Normal" />
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="FontWeight" Value="Bold" />
</Trigger>
</Style.Triggers>
</Style>
</ListView.ItemContainerStyle>
<ListView.Resources>
<DataTemplate x:Key="image">
<Image Width="16" Height="16" Margin="0,0,0,0"
HorizontalAlignment="Center"
Source="{Binding Path=ObjectType,
Converter={StaticResource imageConverter} }" />
</DataTemplate>
</ListView.Resources>
<ListView.View>
<GridView>
<GridViewColumn Width="20"
CellTemplate="{StaticResource image}"/>
<GridViewColumn Width="120" Header="Name"
DisplayMemberBinding="{Binding Path=Name}"/>
</GridView>
</ListView.View>
Run Code Online (Sandbox Code Playgroud)
ImageConverter只是将ObjectType转换为图像,因此每种类型的项都有自己的图标.
我创建了一个skinny没有边距,填充或边框的CSS类:
.skinny
{
margin:0 0 0 0;
padding:0 0 0 0;
border:0 0 0 0;
}
Run Code Online (Sandbox Code Playgroud)
我将它应用到包含图像的行中,该图像也skinny应用了类:
<td width="33%" align="center" class="skinny">
<table width="400px" height="180px" class="skinny">
<tr class="skinny">
<td class="skinny" width="60px" height="100px"><a class="skinny" href="/"><img class="skinny" width="60px" height="100px" id="snapshot" src="/images/snapshot.png"></a></td>
<td class="skinny" width="120px" height="100px"><a class="skinny" href="/"><h1 class="skinny">Product</h1></a></td>
</tr>
</table>
</td>
Run Code Online (Sandbox Code Playgroud)
我试图使图像看起来尽可能接近<h1>下一个单元格中的文本,以便它们从左到右相互向上推.
但无论我将这个skinny类应用到多少元素,似乎有一些类似于每个表格单元格周围的"填充",这会在图像和文本之间创建一个空格.
我该如何删除?
我已经在我的css中为公共边距和填充类声明了常见的css类,这样我就可以使用它们而不会使其他css声明过于具体.
例如 :
.padTB5{padding:5px 0;}
.pad10{padding:10px;}
.mTop10{margin:10px 0 0;}
.mTop5{margin:5px 0 0;}
Run Code Online (Sandbox Code Playgroud)
请指导...在此先感谢:)
到目前为止,我已经为Android开发了.在那里,您可以为几乎每个UI元素设置layoutMargin和padding(当您在xml文件中描述UI时).
如何在iOS中的UIViews代码中完成(如果有一个通用命令)?
TNX
在safari中,第二列显得更高.两列都以h4开头,但似乎div本身的顶部填充仅适用于第一个..或者其他东西.不确定发生了什么.它在Chrome中排成一行
我有一个漂浮<div>在另一个内<div>,包含div有一个黑色边框...
问题是浮动<div>实际上并没有占据它的高度(大约600px)左右,所以<div>带边框的包含最终会像20 px一样高,边框直接通过内部div.
我如何让内部div占据它应该占据的空间,同时仍然让它浮动?
这是我的来源:
<div style="border:1px solid black">
<div style="float:left;height:200px;"></div>
</div>
Run Code Online (Sandbox Code Playgroud) 我尽可能简化了代码,但仍无法将其置于中心位置.我相信我缺乏经验CSS并不能让我看到非常简单的东西.
如果有人也知道一些css的好资源,这将是伟大的.我已阅读过许多CSS书籍的部分,但都有非常基本的内容并涵盖了相同的内容.
CSS标记:
/* MAIN ––––––––––––––––––––– */
html {
/* overflow-y:scroll; */
}
body {
/* margin:0; */
/* position:relative; */
}
/* Form ––––––––––––––––––––– */
#form {
margin:0 auto;
width: 300px;
height: 200px;
display: inline-block;
border: 2px solid black;
}
Run Code Online (Sandbox Code Playgroud)
的index.html
<html>
<body>
<form id='form'></form>
</body>
</hml>
Run Code Online (Sandbox Code Playgroud) 我试图让一个多边形完全从屏幕左侧移动,穿过屏幕,然后完全离开屏幕右侧,然后再返回.
我已经开始工作了.但是,出于某种原因,只要左边距变为负值,动画就会突然减慢.一旦左边距变为正,它就会再次加速.
为什么会这样?我怎么能阻止它?
这是完整的代码,用于演示:
<Window x:Class="Geometry.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<PathGeometry x:Key="MyGeometry">
<PathGeometry.Figures>
<PathFigure>
<PathFigure.Segments>
<LineSegment Point="0.30,0" />
<LineSegment Point="0.70,1" />
<LineSegment Point="0.40,1" />
<LineSegment Point="0,0" />
</PathFigure.Segments>
</PathFigure>
</PathGeometry.Figures>
</PathGeometry>
<Storyboard x:Key="MovingAnimation">
<ThicknessAnimationUsingKeyFrames RepeatBehavior="1:0:0" FillBehavior="HoldEnd" Storyboard.TargetName="_path" Storyboard.TargetProperty="Margin" >
<DiscreteThicknessKeyFrame KeyTime="0:0:0" Value="-2.0,0,0,0" />
<LinearThicknessKeyFrame KeyTime="0:0:10" Value="1.0,0,0,0" />
<LinearThicknessKeyFrame KeyTime="0:0:20" Value="-2.0,0,0,0" />
</ThicknessAnimationUsingKeyFrames>
</Storyboard>
</Window.Resources>
<Window.Triggers>
<EventTrigger RoutedEvent="Window.Loaded">
<BeginStoryboard Storyboard="{StaticResource MovingAnimation}" ></BeginStoryboard>
</EventTrigger>
</Window.Triggers>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal">
<Label>Margin:</Label>
<TextBlock Text="{Binding …Run Code Online (Sandbox Code Playgroud) 这可能已被问过一百万次,但如果有人能向我解释div的行为,我将不胜感激.
我有一个容器div,我在页面的中心对齐,在页面的顶部和顶部之间有一个间隙.我希望它与页面顶部齐平.我假设有一些边缘或填充,我需要删除,但我不能想到它可能是什么.即使在div中没有任何东西,仍然存在差距.
<body>
<div id='mainContent'>
</div>
</body>
body
{
background-color:black;
background-image:url("img/background.jpg");
background-repeat:repeat;
}
#mainContent
{
width:1200px;
height:500px;
background-color:#FFFFFF;
margin-left:auto;
margin-right:auto;
margin-top:0px;
}
Run Code Online (Sandbox Code Playgroud)
这是一个JSFiddle,让您了解我的意思.
有人可以解释为什么div被推下来了吗?是否有一个强大的解决方案,不会影响任何放在div中的内容?
注意:如果屏幕宽度小于div宽度,则左侧也会有间隙.
我正在寻找一种简单的方法来在页面上找到边距左边和边距右边设置为自动的元素.
我有这个脚本,这有时帮助我:
(function() {
var elementsList = [];
for (var i = 0; i < document.styleSheets.length; i++) {
var styleSheet = document.styleSheets[i];
if (styleSheet.rules) {
for (var j = 0; j < styleSheet.rules.length; j++) {
var rule = styleSheet.rules[j];
if (rule && rule.style && rule.style.marginLeft == 'auto' && rule.style.marginRight == 'auto') {
var smallList = document.querySelectorAll(rule.selectorText);
if (smallList.length)
elementsList = elementsList.concat(smallList);
}
}
}
}
return elementsList
})();Run Code Online (Sandbox Code Playgroud)
虽然这个功能完成了一些工作,但它并没有抓住margin: auto我在网站上看到的大多数情况.
你能告诉我一个更好的方法吗?