简体   繁体   English

如何在没有文本扭曲的情况下将文本中心与无序列表对齐?

[英]How to align text center with unordered list without text warping?

I like to show a unordered list text center of image background at top.我喜欢在顶部显示图像背景的无序列表文本中心。 But unfortunately, i am getting the text warpped.但不幸的是,我的文字扭曲了。 I don't know why it happens.我不知道为什么会这样。 Please fix my code.请修复我的代码。

My code,我的代码,

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<style>
.image {
  width:100%;
  height:200px;
}
.container {
  position: relative;
  color: white;
  height:200px;
  width:100%;
}
.title {
    font-family: Ubuntu;
    font-weight: bold;
    font-size: 30px;
    color: white;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}
.title ul li {
    display: inline-block;
    list-style:none;
    letter-spacing:0px;
}
</style>

<div class="container">     
<img src="image.jpg" class="image">
 <div class="title" >
        <ul>
            <li>S</li>
            <li>o</li>
            <li>m</li>
            <li>e</li>
            <li>T</li>
            <li>e</li>
            <li>x</li>
            <li>t</li>
            <li>H</li>
            <li>e</li>
            <li>r</li>
            <li>e</li>
        </ul>
    </div>
</div>

Expected Output, fig1预期输出,图 1

https://i.stack.imgur.com/0zHnW.jpg https://i.stack.imgur.com/0zHnW.jpg

(fig1 : This above image was edited using photo editor to show my expected output) (图 1:上图是使用照片编辑器编辑的,以显示我的预期输出)

But, Output i am getting, fig2但是,我得到的输出,图 2

https://i.stack.imgur.com/ZzMeW.jpg https://i.stack.imgur.com/ZzMeW.jpg

(fig2 : This above image is the screenshot of orginal output i am getting actually) (图2:上图是我实际得到的原始输出截图)

I don't know what i am doing wrong.我不知道我做错了什么。 Please fix my code and explain.请修复我的代码并解释。 My need is, List to be shown in center of the image background in same line without warping.我的需要是,列表显示在同一行中图像背景的中心而不会变形。

Since each letter of your word are in individual <li> tags, one thing that might fix this is the following.由于您单词的每个字母都在单独的<li>标签中,因此可以解决以下问题的一件事。

.container .title ul {
  display: flex
  flex-wrap: nowrap;
}

It would also be beneficial here to add the following css:在这里添加以下 css 也是有益的:

.title {
  display: flex;
  justify-content: center;
  width: 100%;
}

This will size the container of the title to fit the entire screen, which at the moment it isn't.这将调整标题容器的大小以适合整个屏幕,目前还不是。

Also, from your demo page, you still need to add display: flex;此外,从您的演示页面,您仍然需要添加display: flex; to your <ul> .到您的<ul>

From what I'm seeing in the inspector - doing these things should fix your problem.从我在检查员中看到的 - 做这些事情应该可以解决您的问题。

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

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