html - 内容溢出时左对齐

标签 html css

我试图让这些元素符号列表都从中心开始。我注意到,当文本的长度超过浏览器窗口的宽度时,元素符号点会对齐到页面的左侧。为什么会这样,我怎样才能让它居中对齐?这是一个溢出问题吗?我不知道如何解决这个问题。

感谢您的帮助,谢谢。

.standard-list-wrap{
    padding-top: 25px;
    display: flex;
	justify-content: center;
	align-items: center;
}

ul.standard-list{
	padding:0px 0 50px 00000;
	margin:0;
	text-align:left;
	color:#000;
	font-weight:100;
	font-family:Montserrat, Helvetica, Arial, sans-serif;
	font-size:20px;
	-webkit-font-smoothing: antialiased; /* subtley makes fonts smoother */
	line-height:28px;
}

ul.standard-list li{
	list-style-type: none;
	line-height:28px;
}
ul.standard-list li:before{
    /* Unicode bullet symbol */
    content: '\2022';
    /* Bullet color */
    color: #f0f;
    padding-right: 10px;
}
<div class="standard-list-wrap">
        
<ul class="standard-list">
          <li>shorter text is no problem</li>
          <li>shorter text is no problem</li>
    </ul>
        
    </div>
    
    
    
    <div class="standard-list-wrap">
        
<ul class="standard-list">
          <li>but when the text gets too long the problem occurs because the div is no longer centralised and list floats to the left of the page - i want the bullet points to be centralised like the above</li>
    </ul>
        
    </div>

最佳答案

当文本内容太长时,元素将占用 100% 的宽度

也许你可以为你的列表项设置一个最大宽度

.standard-list-wrap {
    padding-top: 25px;
    display: flex;
    justify-content: center;
    align-items: center;
}

ul.standard-list {
    padding: 0px 0 50px 00000;
    margin: 0;
    text-align: left;
    color: #000;
    font-weight: 100;
    font-family: Montserrat, Helvetica, Arial, sans-serif;
    font-size: 20px;
    -webkit-font-smoothing: antialiased;
    /* subtley makes fonts smoother */
    line-height: 28px;
}

ul.standard-list li {
    list-style-type: none;
    line-height: 28px;
    max-width: 400px;
    margin: auto;
}

ul.standard-list li:before {
    /* Unicode bullet symbol */
    content: '\2022';
    /* Bullet color */
    color: #f0f;
    padding-right: 10px;
}
<div class="standard-list-wrap">

    <ul class="standard-list">
        <li>shorter text is no problem</li>
        <li>shorter text is no problem</li>
    </ul>

</div>



<div class="standard-list-wrap">

    <ul class="standard-list">
        <li>but when the text gets too long the problem occurs because the div is no longer centralised and list floats to the left of the page - i want the bullet points to be centralised like the above</li>
    </ul>

</div>

:

ul.standard-list li{
    list-style-type: none;
    line-height:28px;
    max-width: 400px;
    margin: auto;
}

关于html - 内容溢出时左对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43694568/

相关文章:

javascript - 将级联数据从表单获取到 JSON 对象

javascript - 如何在 Angularjs 中使用 ng-repeat 更改选定的索引项值?

html - VSCode 不自动完成 HTML

html - 为什么图片和div之间有空格?

html - 获取元素符号元素的第二行作为第一部分缩进 - 而不是在元素符号下方?

带有图标的jquery向左滑动菜单

javascript - jQuery 悬停在图像/div 上滑动登录框示例转换

javascript - Bootstrap 3 与当前的 AngularJS Bootstrap 指令兼容吗?

css - SASS:@media 查询中的@extend

html - 格式化输入字段