【问题标题】:Input is offset when changing text size next to it更改旁边的文本大小时输入偏移
【发布时间】:2023-03-07 04:30:01
【问题描述】:

不知道为什么,但每当我更改导航菜单上搜索栏旁边的链接时,由于某种原因,输入会略微向下移动。不知道怎么解释....

  @import url('https://fonts.googleapis.com/css2?family=Open+Sans:wght@500&display=swap');
  body {
  margin: 0px;
}
.top-nav-bar {
  background-color: #292929;
  height: 55px;
  text-align: center;
  font-family: 'Open Sans', sans-serif;
  color: #DDDDEB;
  font-size: 50px;
}
.spacer {
  margin: 5px;
  display: inline;
  cursor: help;
}
a {
  text-decoration: none;
  color: inherit;
}
a:hover {
  color: #597BEB;
}
.searchbar {
  font-size: 16px;
  border-width: 2px;
  border-color: #CCCCCC;
  background-color: inherit;
  border-style: solid;
  border-radius: 50px;
  width: 150px;
  height: 50px;
}
<div class="top-nav-bar">
  <a href="#">Home</a>
  <div class="spacer"></div>
  <a href="#">Profile</a>
  <div class="spacer"></div>
  <input class="searchbar" type="text" placeholder="Search">
  <div class="spacer"></div>
</div>

【问题讨论】:

    标签: html css navigation inline offset


    【解决方案1】:

    vertical-align:top;怎么样?

      @import url('https://fonts.googleapis.com/css2?family=Open+Sans:wght@500&display=swap');
      body {
      margin: 0px;
    }
    .top-nav-bar {
      background-color: #292929;
      height: 55px;
      text-align: center;
      font-family: 'Open Sans', sans-serif;
      color: #DDDDEB;
      font-size: 50px;
    }
    .spacer {
      margin: 5px;
      display: inline;
      cursor: help;
    }
    a {
      text-decoration: none;
      color: inherit;
    }
    a:hover {
      color: #597BEB;
    }
    .searchbar {
      font-size: 16px;
      border-width: 2px;
      border-color: #CCCCCC;
      background-color: inherit;
      border-style: solid;
      border-radius: 50px;
      width: 150px;
      height: 50px;
      vertical-align:top;
    }
    <div class="top-nav-bar">
      <a href="#">Home</a>
      <div class="spacer"></div>
      <a href="#">Profile</a>
      <div class="spacer"></div>
      <input class="searchbar" type="text" placeholder="Search">
      <div class="spacer"></div>
    </div>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-03
      • 2016-03-16
      • 2012-05-08
      • 2022-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多