I have horizontally alien html -list with fix width and each list have some time text within is longer and I need to overflow text to next line but without scrollbar.
ul.horizontal-funtions-list{
list-style-type: none;
width: 100%;
padding-left: 0;
padding-top: 10px;
padding-bottom: 10px;
margin: 0;
overflow-x:auto;
white-space: nowrap;
background-color: blueviolet;
}
ul.horizontal-funtions-list li{
display: inline-block;
zoom:1;
width: 100px;
margin-left: 20px;
padding: 20px;
background-color: greenyellow;
}
ul.horizontal-funtions-list li a{
display: block;
width: 80px;
color:gray;
}
<ul class="horizontal-funtions-list">
<li><a href="#Function A">I am long function name</a></li>
<li><a href="#home">Home</a></li>
</ul>
I have tried display: block in ul.horizontal-funtions-list li a but its not working out
答案 0 :(得分:1)
尝试
ul.horizontal-funtions-list li a {
display: block;
color:gray;
white-space: pre-wrap; /* css-3 */
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
word-wrap: break-word; /* Internet Explorer 5.5+ */
/* OPTIONAL - FIXED height
overflow: hidden;
height: 50px;
*/
}
请注意,width
已被删除。
这是演示输出的代码段。
ul.horizontal-funtions-list{
list-style-type: none;
width: 100%;
padding-left: 0;
padding-top: 10px;
padding-bottom: 10px;
margin: 0;
overflow-x:auto;
white-space: nowrap;
background-color: blueviolet;
}
ul.horizontal-funtions-list li{
display: inline-block;
zoom:1;
width: 100px;
margin-left: 20px;
padding: 20px;
background-color: greenyellow;
}
ul.horizontal-funtions-list li a{
display: block;
color:gray;
white-space: pre-wrap; /* css-3 */
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
word-wrap: break-word; /* Internet Explorer 5.5+ */
overflow: hidden;
height: 50px;
}
<ul class="horizontal-funtions-list">
<li><a href="#Function A">I am long function name</a></li>
<li><a href="#home">Home</a></li>
</ul>
答案 1 :(得分:1)
ul.horizontal-funtions-list{
list-style-type: none;
width: 100%;
padding-left: 0;
padding-top: 10px;
padding-bottom: 10px;
margin: 0;
overflow-x:auto;
white-space: nowrap;
background-color: blueviolet;
}
ul.horizontal-funtions-list li{
display: inline-block;
zoom:1;
width: 100px;
margin-left: 20px;
padding: 20px;
background-color: greenyellow;
}
ul.horizontal-funtions-list li a{
display: block;
width: 80px;
color:gray;
/*new style*/
white-space: pre-wrap;
}
<ul class="horizontal-funtions-list">
<li><a href="#Function A">I am long function name</a></li>
<li><a href="#home">Home</a></li>
</ul>
仅为<a>
标签添加此CSS代码。white-space: pre-wrap;
尝试此代码。
答案 2 :(得分:1)
if (model.Dynamic_ProductsSize.Count > 0)
{
foreach (var item in model.Dynamic_ProductsSize)
{
_sizes.Add(new ProductsSize(){SizeId = item});
}
}
。white-space: nowrap
。overflow-x: auto
(也不要在其中具有width: 100px
的锚点上)。我主要删除您拥有的样式的地方,并分别设置适当的width: 80px
和padding
以使间距正确。
margin
ul.horizontal-funtions-list {
margin: 0;
padding: 0 20px 20px 0;
background-color: blueviolet;
list-style-type: none;
}
ul.horizontal-funtions-list li {
display: inline-block;
margin: 20px 0 0 20px;
padding: 20px;
background-color: greenyellow;
}
ul.horizontal-funtions-list li a {
color: gray;
}
答案 3 :(得分:1)
ul.horizontal-funtions-list {
list-style-type: none;
width: 100%;
padding-left: 0;
padding-top: 10px;
padding-bottom: 10px;
margin: 0;
overflow-x: auto;
/* white-space: nowrap; */
background-color: blueviolet;
}
ul.horizontal-funtions-list li {
display: inline-block;
zoom: 1;
/* width: 100px; */
margin-left: 20px;
padding: 15px;
background-color: greenyellow;
}
ul.horizontal-funtions-list li a {
display: block;
max-width: 100px;
color: gray;
}
<ul class="horizontal-funtions-list">
<li><a href="#Function A">I am long function name</a></li>
<li><a href="#home">I am long function name2</a></li>
</ul>
答案 4 :(得分:0)
从链接中删除width属性,然后添加white-space: pre-wrap;
就是这样。
ul.horizontal-funtions-list li a{
/* width: 80px; */
display: block;
white-space: pre-wrap;
color:gray;
}