简体   繁体   English

Material2图标和标题文本CSS不能正确对齐

[英]Material2 Icons and Title Text CSS Not Aligning Properly

I am running into a styling issue while using material2 icons in my Angular app. 我在Angular应用程序中使用material2图标时遇到样式问题。 Specifically, I have a button displaying both a material2 icon and some text - next to each other, running left to right. 具体来说,我有一个按钮,它同时显示了material2图标和一些文本-从左到右,彼此相邻。 Right now the icons are aligning in the center of the button, but the text of the button is aligning below that icon, so as not to be centered on the button. 现在,图标在按钮的中心对齐,但按钮的文本在该图标下方对齐,以免不在按钮的中心。

Here's my HTML: 这是我的HTML:

<div id="wizard-container">
  <div class="intake-step-item">
    <span><i class="material-icons md-28">face</i></span><span class="intake-step-title">General</span>
  </div>
  <div class="intake-step-item">
    <span><i class="material-icons md-28">perm_contact_calendar</i></span><span class="intake-step-title">Availability</span>
  </div>
</div>

And here's the relevant css: 这是相关的CSS:

#wizard-container {
  box-sizing: border-box;
  -moz-box-sizing: border-box;
  -webkit-box-sizing: border-box;
  display: -webkit-flex;
  display: flex;
  -webkit-flex-direction: column;
  flex-direction: column;
  justify-content: space-around;
  align-items: center;
  z-index: -10;
}

.intake-step-item {
    background: #d7d7d7;
    width: 160px;
    height: 30px;
    margin: 5px;
    padding: 10px;
    border-radius: 15px;
    justify-content: space-around;
    align-items: center;
    text-align: center;
    z-index: 100;
}

.intake-step-item > .active {
  background: #46AB61;
}

.intake-step-title {
  display: inline-block;
  vertical-align: middle;
  text-align: center;
}

.material-icons.md-28 { 
  font-size: 28px; 
  padding: 4px; }

I tried using negative margin and negative padding on the title text, but that didn't make any difference. 我尝试在标题文本上使用负边距和负填充,但这没有任何区别。 What do I need to do to get the title text of each button to align in the center of the button? 我该怎么做才能使每个按钮的标题文本与按钮的中心对齐?

All you need is 所有你需要的是

#wizard-container .intake-step-item {
  display: flex;
}

Working example: 工作示例:

 #wizard-container { box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; display: -webkit-flex; display: flex; -webkit-flex-direction: column; flex-direction: column; justify-content: space-around; align-items: center; z-index: -10; } .intake-step-item { background: #d7d7d7; width: 160px; height: 30px; margin: 5px; padding: 10px; border-radius: 15px; justify-content: space-around; align-items: center; text-align: center; z-index: 100; display: flex; } .intake-step-item > .active { background: #46AB61; } .intake-step-title { display: inline-block; vertical-align: middle; text-align: center; } .material-icons.md-28 { font-size: 28px; padding: 4px; } 
 <link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.1/css/materialize.min.css"> <script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.1/js/materialize.min.js"></script> <div id="wizard-container"> <div class="intake-step-item"> <span><i class="material-icons md-28">face</i></span><span class="intake-step-title">General</span> </div> <div class="intake-step-item"> <span><i class="material-icons md-28">perm_contact_calendar</i></span><span class="intake-step-title">Availability</span> </div> </div> 

However, it feels like your CSS somewhat conflicts with Material Design guidelines . 但是,您的CSS感觉与Material Design guidelines有些冲突。

Note: Don't forget to autoprefix before you deploy to production. 注意:在部署到生产autoprefix之前, 不要忘记使用自动autoprefix

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

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