简体   繁体   English

以HTML / CSS为中心

[英]Centering something in HTML / CSS

I think I might be having a problem, not sure if it is a problem because I have been looking at it for sooooo long, I don't even know if its centered or not. 我想我可能有问题,不确定是不是一个问题,因为我已经看了很长时间了,我什至不知道它是否居中。

http://jamessuske.com/thornwood/gallery.php http://jamessuske.com/thornwood/gallery.php

What I am trying to do is center the entire gallery, to me it looks like its a bit to the right. 我想做的是将整个画廊放在中心,对我来说似乎有点像右边。 If anyone can help me figure this out, that would be great. 如果有人可以帮助我解决这个问题,那就太好了。 Thanks in advanced. 提前致谢。

CSS CODE CSS代码

.contentTextGallery{
padding:20px 0 0 0;
width:866px;
font-size:16px;
float:left;
}

.gallery{
 width:912px;
 margin-top:6px;
}

.gallery ul{
 list-style-type:none;
 text-align:center;
}

.gallery li{
 display: inline-block;
}

* html .gallery li { /* IE6 */
  display: inline;
}

*:first-child + html .gallery li { /* IE7 */
  display: inline;
}

.gallery ul a {
 display:block;
 text-decoration: none;
 color:#FFF;
 padding:5px 0 0 5px;
}

It looks like you just need to remove the left padding on the element in your .gallery: 看来您只需要删除.gallery中元素的左填充即可:

.gallery ul { padding-left: 0px; }

Depending on what web browser you're using, there is usually a default padding on lists. 根据您使用的Web浏览器,列表上通常会有默认的填充。

Update : Oh, I see what you are trying to fix now, the stuff inside the container: 更新 :哦,我知道您现在要解决的问题,容器中的内容:

All you need is 所有你需要的是

.gallery ul {
  padding: 0;
}

Original : 原件

One thing you may want to do is pick up a tool like XScope: http://iconfactory.com/software/xscope . 您可能想做的一件事就是选择一种XScope之类的工具: http ://iconfactory.com/software/xscope。 It's an application that has tools for designing (rulers, guides, browser size frames, etc.). 这是一个具有用于设计的工具(标尺,指南,浏览器大小框架等)的应用程序。 The ruler could help you with this because it measures pixels on your screen. 标尺可以帮助您解决此问题,因为它可以测量屏幕上的像素。 You can quickly measure how many pixels are on each side of your layout. 您可以快速测量布局的每一侧有多少像素。

Also here is something similar but a little less elegant: http://www.arulerforwindows.com/ 同样,这里也有一些相似之处,但不太优雅: http : //www.arulerforwindows.com/

It's not centered. 它没有居中。 (There are now three people claiming that it's centered, but I have no idea what they are looking at...) (现在有三个人声称它居中,但我不知道他们在看什么...)

You are using a list for the images, and it has a padding on the left side by default. 您正在使用图像列表,默认情况下左侧具有填充。

You are using padding in the links to get a space between them, but you are only padding on the left and top sides, so that will also add extra space on the left. 您在链接中使用填充来获得它们之间的空间,但是仅在左侧和顶部填充,因此也将在左侧添加额外的空间。

Set the left padding to zero in the list: 在列表中将左填充设置为零:

.gallery ul{
  list-style-type:none;
  text-align:center;
  padding-left: 0;
}

Make the left and right padding in the links more even: 使链接中的左右填充更加均匀:

.gallery ul a {
  display:block;
  text-decoration: none;
  color:#FFF;
  padding:5px 2px 0 3px;
}

You are right it is not centered. 您说得对,它没有居中。

I think, but am not sure, that it may be a padding issue, you set the padding left but not equally right on a couple elements in the container. 我认为但不确定,这可能是一个填充问题,您可以在容器中的几个元素上将填充设置为左但不正确地设置为右。

all left padding to 0px (or use equal padding left and right like this - padding: 5px 5px; or each image can have 0 padding and equal margin: 5px 5px; 所有的左填充都为0px(或像这样使用左右填充-填充:5px 5px;或者每个图像可以具有0填充和相等边距:5px 5px;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM