简体   繁体   English

CSS负边距不起作用?

[英]CSS negative margin is not working?

All right, this should be simple. 好吧,这应该很简单。 Basically, what I'm trying to do here is create the layout for a carousel image gallery. 基本上,我在这里要做的是为旋转木马图像库创建布局。 JSFiddle is here... JSFiddle就在这里......

http://jsfiddle.net/G5Us4/1/ http://jsfiddle.net/G5Us4/1/

CSS... CSS ...

.gallery {

margin-left: auto;
margin-right: auto;
width: 600px;
background-color: #000000;
height: 300px;
overflow: hidden;
white-space: nowrap;

}

.image {

margin-right: 300px;
margin-top: 50px;
position: relative;
height: 200px;

}

#image {

margin-left: -600px;
width: 287px;

}

#image-two {

width: 231px;

}

#image-three {

width: 242px;

}

HTML... HTML ...

<div class="gallery"
    ><img src="../images/templateone.jpg" id ="#image" class="image" alt=""
    /><img src="../images/templatetwo.jpg" id="#image-two" class="image" alt=""
    /><img src="../images/templatethree.jpg" id="#image-three" class="image" alt=""/>
</div>

It's so simple, and I've been afraid to ask, for fear of missing something stupidly simple. 这很简单,我一直不敢问,因为害怕错过一些简单的东西。 I've looked around online, and I simply cannot figure out why this simple margin is not working. 我在网上看了一下,我简直无法弄清楚为什么这个简单的边距不起作用。

The effect I'm trying to get is that all of the images are in a horizontal line with large right margins separating them from the other images. 我想要得到的效果是所有的图像都是水平线,右边距很大,将它们与其他图像分开。 Now that I have that done, I need to add a negative margin on the first image so that the last image starts in the center of the stage, and the other two are outside of the hidden to the left. 现在我已经完成了这个,我需要在第一个图像上添加一个负边距,以便最后一个图像在舞台的中心开始,而另外两个图像在隐藏到左边之外。

For some strange reason the first image does not want to go outside the image to the left. 出于某种奇怪的原因,第一张图像不希望向左移出图像。 Help please! 请帮助!

Thanks in advanced! 提前致谢!

PS end of the tags are in front of the tags to prevent a small space between the images that occurs if there is a line break in the code. 标签的PS端位于标签前面,以防止在代码中存在换行符时出现的图像之间的小空间。

Firstly, change id="#image-three to id="image-three" in your HTML. Remove the # on image one and two also. 首先,在HTML中将id="#image-three更改为id="image-three" 。同时删除第一和第二图像上的#

<img src="../images/templateone.jpg" id ="image" class="image" alt=""/>
<img src="../images/templatetwo.jpg" id="image-two" class="image" alt="" />
<img src="../images/templatethree.jpg" id="image-three" class="image" alt=""/>

Secondly, to get it how you described, just increase that negative margin. 其次,为了得到你描述的方式,只需增加负余量。

#image {
margin-left: -920px;
width: 287px;
}

See - jsFiddle - jsFiddle

remove # from ids in your html Code, 从你的HTML代码中的ids中删除#,

<div class="gallery"
    ><img src="../images/templateone.jpg" id ="image" class="image" alt=""
    /><img src="../images/templatetwo.jpg" id="image-two" class="image" alt=""
    /><img src="../images/templatethree.jpg" id="image-three" class="image" alt=""/>
</div>

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

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