简体   繁体   English

如何将我的项目符号列表移动到中心,同时让它们在 CSS 中垂直对齐?

[英]How do I move my bullet list to the center while having them vertically aligned in CSS?

I'm not sure what I did wrong but the bullet points on the unordered lists are shifted to the far left of the page while the contents remain in the center.我不确定我做错了什么,但无序列表上的项目符号点移动到页面的最左侧,而内容仍然在中心。 What's the best way to move the bullet points back to the center while having them vertically aligned so they don't look unorganized?将项目符号点移回中心同时使它们垂直对齐以使它们看起来没有组织的最佳方法是什么?

Here's a link to my codepen project:这是我的 codepen 项目的链接:

https://codepen.io/danielanggggg/pen/LYjwOer https://codepen.io/danielanggggg/pen/LYjwOer

HTML HTML

 #welcome-section { width: 100%; height: 100vh; top: 10vw; left: 2vw; display: block; margin-top: 10rem; text-align: center; } #navbar { position: fixed; top: 0px; width: 100%; display: flex; justify-content: center; font-size: 20px; background-color: grey; }
 <section id="welcome-section"> <h1>Daniel Ang</h1> <h3>Freelance Copywriter</h3> <p>Hi there. I'm Daniel. I specialize in direct-response copywriting. I believe you are looking<br> for a copywriter to increase your conversion rate and ultimately sell your products or services:</p> <p>I specialize in writing,</p> <ul> <li>Emails</li> <li>Landing Pages</li> <li>Sales Letters</li> <li>Product Descriptions</li> <li>Facebook/Instagram Ads</li> </ul> <p>If you need any of the services above, please don't hesitate to reach out!</p> </section>

I add below code and fixed!我添加下面的代码并修复!

ul{
   width: 20%;
   margin: 0 auto;
}

You can change width as much as you want or use width: max-content;您可以根据需要更改宽度或使用width: max-content; . .

 #welcome-section { width: 100%; height: 100vh; top: 10vw; left: 2vw; display: block; margin-top: 10rem; text-align: center; } #navbar { position: fixed; top: 0px; width: 100%; display: flex; justify-content: center; font-size: 20px; background-color: grey; } ul { width: 20%; margin: 0 auto; }
 <section id="welcome-section"> <h1>Daniel Ang</h1> <h3>Freelance Copywriter</h3> <p>Hi there. I'm Daniel. I specialize in direct-response copywriting. I believe you are looking<br> for a copywriter to increase your conversion rate and ultimately sell your products or services:</p> <p>I specialize in writing,</p> <ul> <li>Emails</li> <li>Landing Pages</li> <li>Sales Letters</li> <li>Product Descriptions</li> <li>Facebook/Instagram Ads</li> </ul> <p>If you need any of the services above, please don't hesitate to reach out!</p> </section>

Another aproach is to try to use Flex - Bootstrap in order to achieve this.另一种方法是尝试使用Flex - Bootstrap来实现这一点。 If you have not installed it yet, feel free to do it, because it is going to help you a lot.如果您还没有安装它,请随意安装它,因为它会对您有很大帮助。 I would include the list inside div classes, as shown below:我会将列表包含在 div 类中,如下所示:

 <div class="d-flex flex-sm-row" >

   <div class="d-flex justify-content-center d-flex align-items-end flex-fill">
      <ul>
        <li>
        ...
        </li>
      </ul>
   </div>
  </div>

You could use a flex box with column direction to get what you want without specifying a width for your bullet list.您可以使用具有列方向的弹性框来获得所需的内容,而无需为项目符号列表指定宽度。

 #welcome-section { width: 100%; /* height is changed to min-height so the actual height will still be calculated based on content when 100vh is smaller than the height of your content */ min-height: 100vh; top: 10vw; left: 2vw; margin-top: 10rem; display: flex; flex-direction: column; align-items: center; }

https://codepen.io/fredns/pen/QWqNLOb https://codepen.io/fredns/pen/QWqNLOb

wrap ul in div and use css as below:ul包装在 div 中并使用 css 如下:

 #welcome-section { width: 100%; height: 100vh; top: 10vw; left: 2vw; display: block; margin-top: 10rem; text-align: center; } #navbar { position: fixed; top: 0px; width: 100%; display: flex; justify-content: center; font-size: 20px; background-color: grey; }.wrap{ display:flex } ul{ margin:auto; }
 <section id="welcome-section"> <h1>Daniel Ang</h1> <h3>Freelance Copywriter</h3> <p>Hi there. I'm Daniel. I specialize in direct-response copywriting. I believe you are looking<br> for a copywriter to increase your conversion rate and ultimately sell your products or services:</p> <p>I specialize in writing,</p> <div class="wrap"> <ul> <li>Emails</li> <li>Landing Pages</li> <li>Sales Letters</li> <li>Product Descriptions</li> <li>Facebook/Instagram Ads</li> </ul> </div> <p>If you need any of the services above, please don't hesitate to reach out!</p> </section>

You can add following CSS for ul and li and this will solve your issue.您可以为ulli添加以下CSS ,这将解决您的问题。

ul li {
    text-align: left;
}

ul {
    width: fit-content;        
    margin: auto;
}

So your complete code will be;所以你的完整代码将是;

 #welcome-section { width: 100%; height: 100vh; top: 10vw; left: 2vw; display: block; margin-top: 10rem; text-align: center; } #navbar { position: fixed; top: 0px; width: 100%; display: flex; justify-content: center; font-size: 20px; background-color: grey; } ul li { text-align: left; } ul { width: fit-content; margin: auto; }
 <section id="welcome-section"> <h1>Daniel Ang</h1> <h3>Freelance Copywriter</h3> <p>Hi there. I'm Daniel. I specialize in direct-response copywriting. I believe you are looking<br> for a copywriter to increase your conversion rate and ultimately sell your products or services:</p> <p>I specialize in writing,</p> <ul> <li>Emails</li> <li>Landing Pages</li> <li>Sales Letters</li> <li>Product Descriptions</li> <li>Facebook/Instagram Ads</li> </ul> <p>If you need any of the services above, please don't hesitate to reach out!</p> </section>

暂无
暂无

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

相关问题 如何将元素置于容器中心,同时保持它们垂直对齐? - How do I center element within a container while keeping them vertically aligned? 如何将文字和图片垂直居中对齐 - How do I center aligned vertically the text with my image 我的标签页向左对齐...如何将它们移到中心? - My tabs are aligned left…how do I moved them to the center? 如何将文字垂直居中 <li> 不会影响列表项目符号? - How do I vertically center the text in a <li> without affecting the list bullet? 如何移动我的 h3 元素以与 span 元素垂直对齐? - How do I move my h3 elements to be vertically aligned with span elements? 中心自定义列表子弹垂直 - center custom list bullet vertically 如何垂直居中 li 导航菜单但将其水平对齐到右侧,同时保持徽标图标水平对齐左和 ctrd vert? - How do I vertically center li navigation menu but horizontally align it to the right while keeping logo icon horizontally aligned left and ctrd vert? 如何在页面上垂直排列无序列表? 身体对准中心 - How to vertically center an unordered list on a page? body is aligned center 如何使图像相对于左侧的动态div在中心垂直对齐? - How can I get my image to be vertically aligned in the center with respect to a dynamic div on it's left? 如何获得带字幕的缩略图,其缩略图与引导程序3的中心垂直对齐 - How do I get thumbnails with captions to the right vertically aligned to the center on bootstrap 3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM