html - 将 LI 的文本与其他元素对齐

标签 html css alignment html-lists

我们的平面设计师向我发送了下图,说明我们的页面应该是什么样子:

enter image description here

因此 <li> 的文本元素应与顶部的 Logo 和列表上方的标题对齐。我似乎无法找到一种方法来精确指定这种关系。我最终调整了 margin-left li的风格直到它们看起来与我的浏览器中的标题一样,但这似乎在不同的设备和浏览器中都不可靠。 padding-left: 1em; 之间没有直接关系在 #image-header 上和 #instruction-header包含前两个元素的 DIV,以及 margin-left: 1.3em#instructions li .

有没有办法设置这些样式以确保对齐?

如果我排列文本,我能确定数字不会超出页面边界吗?

#image-header {
  background-color: #fcfb91;
  padding-top: 5px;
  padding-left: 1em;
}
.image-container {
  display: inline-block;
  text-align: center;
  vertical-align: middle;
}
#instructions li {
  margin-bottom: 1em;
  margin-left: -1.3em;
}
#instruction-header {
  background-color: #336699;
  color: white;
  width: 20em;
  padding-bottom: 2px;
  padding-top: 2px;
  padding-left: 1em;
}
<div id="image-header">
  <div class="image-container">
    <img src="//dev.bridgebase.com/barmar_test/mp/acbl/bbo.png" alt="BBO Logo">
  </div>
  <div class="image-container">
    <img src="//dev.bridgebase.com/barmar_test/mp/acbl/invitetext.png" alt="Invite some friends">
  </div>
</div>
<div style='font-family: "Ariel", sans-serif'>
  <h3 id="instruction-header">How it works</h3>
  <ol id="instructions">
    <li>Every friend you invite who has not played an ACBL tournament on BBO is eligible for the promotion.</li>
    <li>Each of you will earn BB$5 when your friend creates a BBO username (if he's not already a BBO user) and registers a valid ACBL number. The bonus will be automatically deposited in each of your BBO accounts.
    </li>
    <li>There is no limit to the number of bonuses you can earn within the deadline of the promotion.</li>
    <li>Once you refer, each friend will receive an email from BBO.</li>
    <li>The deadline is Nov 1, 2015. Your friend must use that referral email to successfully create a BBO username and register his ACBL number by that date for both of you to earn the bonuses.
    </li>
  </ol>
</div>

最佳答案

我认为您应该从#instructions li 中删除左边距,而是定义#instructions ol 的左填充。如果将它设置为 1em,它会与 Logo 完美对齐

编辑:给你:

#image-header {
  background-color: #fcfb91;
  padding-top: 5px;

}
.image-container {
  display: inline-block;
  text-align: center;
  vertical-align: middle;
}    

#instructions, #image-header {
  padding-left: 1em;
}

#instructions li {
  margin-bottom: 1em;
}

#instruction-header {
  background-color: #336699;
  color: white;
  width: 20em;
  padding-bottom: 2px;
  padding-top: 2px;
  padding-left: 1em;
}
<div id="image-header">
  <div class="image-container">
    <img src="//dev.bridgebase.com/barmar_test/mp/acbl/bbo.png" alt="BBO Logo">
  </div>
  <div class="image-container">
    <img src="//dev.bridgebase.com/barmar_test/mp/acbl/invitetext.png" alt="Invite some friends">
  </div>
</div>
<div style='font-family: "Ariel", sans-serif'>
  <h3 id="instruction-header">How it works</h3>
  <ol id="instructions">
    <li>Every friend you invite who has not played an ACBL tournament on BBO is eligible for the promotion.</li>
    <li>Each of you will earn BB$5 when your friend creates a BBO username (if he's not already a BBO user) and registers a valid ACBL number. The bonus will be automatically deposited in each of your BBO accounts.
    </li>
    <li>There is no limit to the number of bonuses you can earn within the deadline of the promotion.</li>
    <li>Once you refer, each friend will receive an email from BBO.</li>
    <li>The deadline is Nov 1, 2015. Your friend must use that referral email to successfully create a BBO username and register his ACBL number by that date for both of you to earn the bonuses.
    </li>
  </ol>
</div>

关于html - 将 LI 的文本与其他元素对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33298698/

相关文章:

jquery - Qtip 不显示图标?

html - 在 DIV 中对齐图像

java - JTable所有列右对齐

javascript - onmouseover 事件行为不当

html - Bootstrap 列以 img 为中心但不以 div 为中心

html - CSS - Div 不居中

html - 图像旁边的多行文本 (CSS-HTML)

css - 三个表并排溢出div容器?

CSS-背景颜色不会填充到滚动 div 的顶部

django 模板中的 css