我的网站上的jQuery Nivo Slider有什么用?(What is up with jQuery Nivo Slider on my site?)
我安装了在我的网站上使用jQuery的Nivo Slider(http://nivo.dev7studios.com/),这是一个Magento电子商务网站。
我的网站是http://bikeshop.gostorego.com/
任何想法为什么在主页上可以看到滑块的位置,但加载图标仅存在不显示幻灯片?
谢谢
I have installed the Nivo Slider (http://nivo.dev7studios.com/) that uses jQuery on my site which is a Magento ecommerce site.
My site is http://bikeshop.gostorego.com/
Any ideas why on the homepage you can see where the slider goes, but the loading icon is only present not showing the slides?
Thanks
原文:https://stackoverflow.com/questions/6208910
最满意答案
沿着主轴对齐Flex项目的方法
正如问题所述:
沿着主轴对齐flex项目有一个属性:
justify-content
要沿着交叉轴对齐Flex项目,有三个属性:
align-content
,align-items
和align-self
。问题然后问:
为什么没有
justify-items
和justify-self
属性?一个答案可能是: 因为没有必要。
Flexbox规范提供了两种沿着主轴对齐柔性物品的方法:
justify-content
关键字属性,和auto
边距
证明内容
justify-content
属性将Flex项目沿着Flex容器的主轴对齐。它应用于Flex容器,但仅影响Flex项目。
有五个对齐选项:
flex-start
start〜Flex项目被打包到该行的开头。
flex-end
end〜Flex项目被打包到行尾。
center
〜Flex物品朝向线的中心。
space-between
〜Flex物品间隔均匀,第一个物品与容器的一个边缘对齐,最后一个物品与相对边缘对齐。 第一个和最后一个项目使用的边缘取决于flex-direction
和写入模式 (ltr
或rtl
)。
space-around
与space-between
相同,但两端的半角空格不同。
汽车保证金
使用
auto
边距 ,柔性物品可以居中,间隔或包装成子组。不同于适用于flex容器的
justify-content
,auto
边距继续进行flex项目。
将一组弹性项目对齐到右边,但第一个项目在左边
问题的场景:
使一组flex项目对齐(
justify-content: flex-end
),但是第一个对齐左对齐(justify-self: flex-start
)考虑一个带有一组导航项目和徽标的标题部分。 通过
justify-self
,标识可以左对齐,而导航项目保持最右边,整个事物可以平滑调整(“flexes”)到不同的屏幕尺寸。
其他有用的场景:
将flex项目放在角落里
问题的场景:
- 将flex项目放在角落里
.box { align-self: flex-end; justify-self: flex-end; }
.box { align-self: flex-end; justify-self: flex-end; }
垂直和水平放置柔性物品
margin: auto
是justify-content: center
的替代方案justify-content: center
和align-items: center
。而不是Flex容器上的这个代码:
.container { justify-content: center; align-items: center; }
您可以在flex项目上使用它:
.box56 { margin: auto; }
当定位溢出容器的flex项目时,此选项很有用。
中心一个flex项目,并在第一个和第一个边缘之间居中第二个flex项目
Flex容器通过分配可用空间来对齐弹性项目。
因此,为了创造平等的平衡 ,中间物品可以集中在容器中,同时还有一个物品,必须引入平衡物。
在下面的例子中,引入了不可见的第三个弹性项目(框61和68)来平衡“实际”项目(框63和66)。
当然,这种方法在语义上是没有什么大的。
或者,您可以使用伪元素而不是实际的DOM元素。 或者您可以使用绝对定位。 所有三种方法都在这里: 中心和底部对齐的柔性物品
注意:上面的例子只有在最外面的物品是相同的高度/宽度的情况下,才能以真实居中的方式工作。 当flex项目长度不同时,请参见下一个示例。
当相邻项目大小不同时,中心一个弹性项目
问题的场景:
在一行三个flex项目中,将中间项目粘贴到容器的中心(
justify-content: center
)并将相邻项目对齐到容器边缘(justify-self: flex-start
和justify-self: flex-end
)。请注意,如果相邻项目具有不同的宽度,则
justify-content
属性上的space-around
和space-between
值将不会使中间项目与容器相关。如上所述,除非所有柔性物品的宽度或高度相同(取决于
flex-direction
),否则中间物品不能真正居中。 这个问题使得一个justify-self
属性(设计来处理任务当然)的强大的例子。#container { display: flex; justify-content: space-between; background-color: lightyellow; } .box { height: 50px; width: 75px; background-color: springgreen; } .box1 { width: 100px; } .box3 { width: 200px; } #center { text-align: center; margin-bottom: 5px; } #center > span { background-color: aqua; padding: 2px; }
<div id="center"> <span>TRUE CENTER</span> </div> <div id="container"> <div class="box box1"></div> <div class="box box2"></div> <div class="box box3"></div> </div> <p>The middle box will be truly centered only if adjacent boxes are equal width.</p>
以下是解决这个问题的两种方法:
解决方案#1:绝对定位
flexbox规格允许对Flex项目进行绝对定位 。 这允许中间物品完美地居中,而不管其兄弟姐妹的大小如何。
请记住,像所有绝对定位的元素一样,这些项目将从文档流程中删除。 这意味着它们不占用容器中的空间,并且可以与其兄弟姐妹重叠。
在下面的示例中,中间项目以绝对定位为中心,外部项目保持流入。 但是可以以相反的方式实现相同的布局:使用
justify-content: center
中心中间的项目justify-content: center
并绝对定位外部项目。解决方案#2:嵌套Flex容器(无绝对定位)
.container { display: flex; } .box { flex: 1; display: flex; justify-content: center; } .box71 > span { margin-right: auto; } .box73 > span { margin-left: auto; } /* non-essential */ .box { align-items: center; border: 1px solid #ccc; background-color: lightgreen; height: 40px; }
<div class="container"> <div class="box box71"><span>71 short</span></div> <div class="box box72"><span>72 centered</span></div> <div class="box box73"><span>73 loooooooooooooooong</span></div> </div>
以下是它的工作原理:
- 顶级div(
.container
)是一个flex容器。- 每个小孩div(
.box
)现在都是一个flex项目。- 每个
.box
项目都被赋予了flex: 1
,以便平均分配容器空间。- 现在这些项目正在占用行中的所有空间,并且宽度相等。
- 使每个项目成为(嵌套)的Flex容器并添加
justify-content: center
。- 现在每个
span
元素都是一个居中的flex项目。- 使用柔性
auto
边距可以左右移动外span
。您也可以放弃
justify-content
并专门使用auto
边距。但是
justify-content
可以在这里工作,因为auto
边距总是优先。 从规格:8.1。 与
auto
边距对齐在通过
justify-content
和align-self
方式对齐之前,任何正的可用空间都会分配到该维度中的自动边距。
对齐内容:空格相同(概念)
回过头来
justify-content
一分钟,这是一个想法再一个选择。
space-same
〜space-between
和space-around
混合。 Flex项目均匀间隔(如space-between
),除了两端的空格(如space-around
)之外,两端都有全尺寸的空格。这个布局可以通过
::before
和::after
伪元素在flex容器上实现。(信用:代码的@oriol ,标签的@crl )
更新:浏览器已经开始实现
space-evenly
,这实现了上述。 有关详细信息,请参阅此信息: 柔性物品周围的等间距
PLAYGROUND (包括上面所有示例的代码)
Methods for Aligning Flex Items along the Main Axis
As stated in the question:
To align flex items along the main axis there is one property:
justify-content
To align flex items along the cross axis there are three properties:
align-content
,align-items
andalign-self
.The question then asks:
Why are there no
justify-items
andjustify-self
properties?One answer may be: Because they're not necessary.
The flexbox specification provides two methods for aligning flex items along the main axis:
- The
justify-content
keyword property, andauto
margins
justify-content
The
justify-content
property aligns flex items along the main axis of the flex container.It is applied to the flex container but only affects flex items.
There are five alignment options:
flex-start
~ Flex items are packed toward the start of the line.
flex-end
~ Flex items are packed toward the end of the line.
center
~ Flex items are packed toward the center of the line.
space-between
~ Flex items are evenly spaced, with the first item aligned to one edge of the container and the last item aligned to the opposite edge. The edges used by the first and last items depends onflex-direction
and writing mode (ltr
orrtl
).
space-around
~ Same asspace-between
except with half-size spaces on both ends.
Auto Margins
With
auto
margins, flex items can be centered, spaced away or packed into sub-groups.Unlike
justify-content
, which is applied to the flex container,auto
margins go on flex items.They work by consuming all free space in the specified direction.
Align group of flex items to the right, but first item to the left
Scenario from the question:
making a group of flex items align-right (
justify-content: flex-end
) but have the first item align left (justify-self: flex-start
)Consider a header section with a group of nav items and a logo. With
justify-self
the logo could be aligned left while the nav items stay far right, and the whole thing adjusts smoothly ("flexes") to different screen sizes.
Other useful scenarios:
Place a flex item in the corner
Scenario from the question:
- placing a flex item in a corner
.box { align-self: flex-end; justify-self: flex-end; }
Center a flex item vertically and horizontally
margin: auto
is an alternative tojustify-content: center
andalign-items: center
.Instead of this code on the flex container:
.container { justify-content: center; align-items: center; }
You can use this on the flex item:
.box56 { margin: auto; }
This alternative is useful when centering a flex item that overflows the container.
Center a flex item, and center a second flex item between the first and the edge
A flex container aligns flex items by distributing free space.
Hence, in order to create equal balance, so that a middle item can be centered in the container with a single item alongside, a counterbalance must be introduced.
In the examples below, invisible third flex items (boxes 61 & 68) are introduced to balance out the "real" items (box 63 & 66).
Of course, this method is nothing great in terms of semantics.
Alternatively, you can use a pseudo-element instead of an actual DOM element. Or you can use absolute positioning. All three methods are covered here: Center and bottom-align flex items
NOTE: The examples above will only work – in terms of true centering – when the outermost items are equal height/width. When flex items are different lengths, see next example.
Center a flex item when adjacent items vary in size
Scenario from the question:
in a row of three flex items, affix the middle item to the center of the container (
justify-content: center
) and align the adjacent items to the container edges (justify-self: flex-start
andjustify-self: flex-end
).Note that values
space-around
andspace-between
onjustify-content
property will not keep the middle item centered in relation to the container if the adjacent items have different widths (see demo).As noted, unless all flex items are of equal width or height (depending on
flex-direction
), the middle item cannot be truly centered. This problem makes a strong case for ajustify-self
property (designed to handle the task, of course).#container { display: flex; justify-content: space-between; background-color: lightyellow; } .box { height: 50px; width: 75px; background-color: springgreen; } .box1 { width: 100px; } .box3 { width: 200px; } #center { text-align: center; margin-bottom: 5px; } #center > span { background-color: aqua; padding: 2px; }
<div id="center"> <span>TRUE CENTER</span> </div> <div id="container"> <div class="box box1"></div> <div class="box box2"></div> <div class="box box3"></div> </div> <p>The middle box will be truly centered only if adjacent boxes are equal width.</p>
Here are two methods for solving this problem:
Solution #1: Absolute Positioning
The flexbox spec allows for absolute positioning of flex items. This allows for the middle item to be perfectly centered regardless of the size of its siblings.
Just keep in mind that, like all absolutely positioned elements, the items are removed from the document flow. This means they don't take up space in the container and can overlap their siblings.
In the examples below, the middle item is centered with absolute positioning and the outer items remain in-flow. But the same layout can be achieved in reverse fashion: Center the middle item with
justify-content: center
and absolutely position the outer items.Solution #2: Nested Flex Containers (no absolute positioning)
.container { display: flex; } .box { flex: 1; display: flex; justify-content: center; } .box71 > span { margin-right: auto; } .box73 > span { margin-left: auto; } /* non-essential */ .box { align-items: center; border: 1px solid #ccc; background-color: lightgreen; height: 40px; }
<div class="container"> <div class="box box71"><span>71 short</span></div> <div class="box box72"><span>72 centered</span></div> <div class="box box73"><span>73 loooooooooooooooong</span></div> </div>
Here's how it works:
- The top-level div (
.container
) is a flex container.- Each child div (
.box
) is now a flex item.- Each
.box
item is givenflex: 1
in order to distribute container space equally.- Now the items are consuming all space in the row and are equal width.
- Make each item a (nested) flex container and add
justify-content: center
.- Now each
span
element is a centered flex item.- Use flex
auto
margins to shift the outerspan
s left and right.You could also forgo
justify-content
and useauto
margins exclusively.But
justify-content
can work here becauseauto
margins always have priority. From the spec:8.1. Aligning with
auto
marginsPrior to alignment via
justify-content
andalign-self
, any positive free space is distributed to auto margins in that dimension.
justify-content: space-same (concept)
Going back to
justify-content
for a minute, here's an idea for one more option.
space-same
~ A hybrid ofspace-between
andspace-around
. Flex items are evenly spaced (likespace-between
), except instead of half-size spaces on both ends (likespace-around
), there are full-size spaces on both ends.This layout can be achieved with
::before
and::after
pseudo-elements on the flex container.(credit: @oriol for the code, and @crl for the label)
UPDATE: Browsers have begun implementing
space-evenly
, which accomplishes the above. See this post for details: Equal space between flex items
PLAYGROUND (includes code for all examples above)
相关问答
更多-
沿着主轴对齐Flex项目的方法 正如问题所述: 沿着主轴对齐flex项目有一个属性: justify-content 要沿着交叉轴对齐Flex项目,有三个属性: align-content , align-items和align-self 。 问题然后问: 为什么没有justify-items和justify-self属性? 一个答案可能是: 因为没有必要。 Flexbox规范提供了两种沿着主轴对齐柔性物品的方法: justify-content关键字属性,和 auto边距 证明内容 justify-con ...
-
属性justify-content:center沿着flex方向对齐flex-items - 使用align-items:center - 参见下面的演示: .container { display: flex; flex-direction: column; width: 600px; background-color: blue; justify-content: center; align-items:center;/*NEW*/ } .item { ma ...
-
只需添加flex-wrap: wrap; (下面的第二个例子包装,第一个例子没有,因为容器的宽度足以容纳两个孩子在一行中)foobar
-
如何使用弹性框将第一个按钮对齐到左侧?(How can I align the first button to the left using flex box? [duplicate])[2021-10-17]
#actions button:nth-child(1) { margin-right: auto; } #actions button:nth-child(1) { margin-right: auto; } -
好的,所有我的问题都来自骨架框架。 我的编码没有错。 我做了一些高级代码剥离来解决这个问题。 我永远不会再使用骨架了。 Ok so all of my issues sim from the skeleton framework. Nothing was wrong with my coding. Took me doing some high level code stripping to figure that out. I'll never use skeleton again.
-
只需使用text-align: justify CSS .job-description { display: flex; justify-content: space-between; } .job-description p{ text-align: justify; } 在这里演示 Just use text-align: justify CSS .job-description { display: flex; justify-content: space ...
-
我认为你只需要将这些方框折成方向即可: .boxes { background-size: cover; background-position: center center; display: flex; flex-direction:column; /* add this */ background-color: red; width: 50%; } .branding { width:100%; display: flex; fle ...
-
这是因为Flexbox的工作方式。 由于.horizontal容器本身就是一个flex子,它会自动调整到其他子.horizontal的大小。 只允许空间容纳溢出的内容,它们是.horizontal本身的孩子。 手动应用宽度将导致为项目创建空间,并且justify-content: space-between将启动。 解决方案,更改以下规则: .horizontal { flex-direction: row; background-color: red; width: 100%; } ...
-
justify-items属性通过在列(而不是整个容器)中分配可用空间来对齐网格项。 但是,在这种情况下,没有可用空间,因为每个项占据列的整个宽度。 .gridwrapper div { width: 100% } 删除该规则时, justify-items可以正常工作。 这是一个更完整的解释: CSS Grid中的justify-self,justify-items和justify-content之间的区别 修改后的codepen .gridwrapper { background: #e6e6e ...
-
如flexbox规范中所述 : 在通过justify-content和align-self进行对齐之前,任何正的可用空间都会分配到该维度中的auto边距。 换句话说, auto边距优先于justify-content 。 在您的示例中,Chrome似乎符合规范。 (Firefox,以及。) 但IE11 - 在父母有justify-content - 忽略了margin-right: auto在弹性项目上margin-right: auto 。 这似乎是一个错误。 删除justify-content后, au ...