没有javascript和没有屏幕宽度的媒体查询
我试图找到一种仅用于css的方法来实现下图所示的情况.我找不到创建以下内容的方法:
我一直在尝试几种策略无济于事,我有一种感觉,Flexbox可能会有所帮助,但我对flexbox并不是很有经验,也找不到使用它的方法.
我尝试过的一些事情:
更新: 当元素的宽度固定且相等时,我制作了一个(较少)小提琴.不幸的是固定宽度,所以还不是我想要实现的.如果你想帮助我,你可以用这个作为起点.我把内容放在:之前也许它可能溢出元素并以某种方式将元素宽度固定为auto.
目前仅限CHROME:http://jsfiddle.net/2px3b63j/7/
HTML:
<div class="pusher"></div>
<nav>
<a data-title="First" href="#"></a><a data-title="Second" href="#"></a><a data-title="Third" href="#"></a><a data-title="Fourth" href="#"></a><a data-title="Fifth" href="#"></a>
</nav>
Run Code Online (Sandbox Code Playgroud)
减:
@h: 3em;
@w:6em;
* {
margin: 0;
padding: 0;
}
body {
font: 0.9rem sans-serif;
background: #666;
}
.pusher {
float: left;
width: ~"calc(100% - " (@w * 1.01) ~")";
height: @h * 6;
-webkit-shape-outside: polygon(0 @h, 100% @h, 100% 100%, 0 100%);
}
nav {
position: relative;
text-align: right;
background: white;
height: @h;
line-height:0;
a {
position: relative;
text-align:center;
width: @w;
max-width: 100%;
display: inline-block;
background: white;
text-decoration: none;
color: #333;
font-weight: bold;
height: @h;
line-height: @h;
&:before {
content: attr(data-title);
}
}
}
Run Code Online (Sandbox Code Playgroud)
链接到答案:https://jsfiddle.net/ky83870x/1/在Internet Explorer中不起作用,但我认为它适用于Edge.如果有人能找到一种方法让它在IE中运行,我将非常有兴趣知道
使用弹性盒获得输出的一种可能性。
将弹性盒设计得足够窄,以便任何孩子都能放进去。这迫使孩子们连续前进。
在第一个子元素之前添加一个伪元素以强制提供额外的边距。
根据需要调整弯曲程度
将 Flex 放置在右侧,因为现在所有内容都在左侧。
这些元素采用颜色编码,可以轻松查看正在发生的情况
.container {
display: flex;
flex-flow: row wrap;
border: solid 1px red;
width: 10px;
left: 500px;
position: absolute;
justify-content: flex-end;
}
.container div {
font-size: 20px;
margin: 5px;
background-color: lightblue;
display: inline-block;
flex-basis: auto;
flex-shrink: 0;
}
.container:before {
content: "";
margin-left: -500px;
flex-basis: 10px;
background-color: yellow;
height: 6px;
}Run Code Online (Sandbox Code Playgroud)
<div class="container">
<div>Lorem</div>
<div>Ipsum dolor sit amet</div>
<div>Consectetur adipisicing elit</div>
<div>Unde saepe</div>
<div>Placeat neque mollitia</div>
<div>Accusamus fuga</div>
<div>Lorem</div>
<div>Ipsum dolor sit amet</div>
<div>Consectetur adipisicing elit</div>
<div>Unde saepe</div>
<div>Placeat neque mollitia</div>
<div>Accusamus fuga</div>
</div>Run Code Online (Sandbox Code Playgroud)