【问题标题】:Adding a logo while keeping the design and responsiveness same添加徽标,同时保持设计和响应能力相同
【发布时间】:2022-01-26 05:58:13
【问题描述】:

我想在导航栏中的主页链接左侧添加一个来自 font-awesome 的徽标。但是当我添加它时,整个页面的设计就被破坏了。我希望导航栏中的所有链接都在一行中,但是一旦添加了所有元素的图标位置就毁了。请有人建议进行编辑,以使图标保留在那里以及设计和响应能力发生变化。

body{
    box-sizing: border-box;
    font-family: sans-serif;
    background-color: #091118;
}
nav{
    position: relative;
    margin: 0;
    padding: 0;
    font-size: 0;
    box-shadow: 0 2px 3px 0;       
    width: 100%; 
    height: 50px; 
    border-radius: 15px;
    background-color: #04111ffa;
}
nav a{
    width: 100%;
    font-size: 15px;
    color: seashell;
    display: inline-block;
    position: relative;
    text-decoration: none;
    text-transform: uppercase;
    display: inline-block;
    line-height: 50px;
    z-index: 5;
    text-align: center;
}
.search-container{
    float: right;
}
input[type=text]{
    padding: 6px;
    margin-top: 13px;
    font-size: 17px;
    border: none;
    border-radius: 15px;
}
.search-container button{
    float: right;
    padding: 6px 10px;
    margin-top: 13px;
    margin-right: 30px;
    font-size: 17px;
    border-radius: 15px;
    background-color: rgb(58, 233, 218);
}
span.fas {
    max-width: 50px;
}
   
    <nav>
        <span class="fas fa-bars"></span>
        <a href="#">Home</a>
        <a href="#">About</a>
        <a href="#">Contact</a>
        <a href="#">Privacy Policy</a>
        <a href="#">Docs</a>
        <div class="animation start-home"></div>
        <div class="search-container">
            <form>
                <input type="text" placeholder="Search..." name="search" class="searchbar">
                <button type="submit"><i class="fas fa-search"></i><span class="text">Search</span></button>
            </form>
        </div>
    </nav>

【问题讨论】:

  • 如果你想让锚元素在一行中,为什么你给锚元素的宽度是 100% 我有点迷茫(我意识到这与添加图标无关)。请您检查您的 sn-p,以便向我们显示您所说的问题。这将包括添加 fontawesome 代码。

标签: html css


【解决方案1】:

body{
    box-sizing: border-box;
    font-family: sans-serif;
    background-color: #091118;
}
nav{
    position: relative;
    margin: 0;
    padding: 0;
    font-size: 0;
    box-shadow: 0 2px 3px 0;       
    width: 100%; 
    height: 50px; 
    border-radius: 15px;
    background-color: #04111ffa;
}
nav a{
    width: 100%;
    font-size: 15px;
    color: seashell;
    display: inline-block;
    position: relative;
    text-decoration: none;
    text-transform: uppercase;
    display: inline-block;
    line-height: 50px;
    z-index: 5;
    text-align: center;
}
.search-container{
    float: right;
}
input[type=text]{
    padding: 6px;
    margin-top: 13px;
    font-size: 17px;
    border: none;
    border-radius: 15px;
}
.search-container button{
    float: right;
    padding: 6px 10px;
    margin-top: 13px;
    margin-right: 30px;
    font-size: 17px;
    border-radius: 15px;
    background-color: rgb(58, 233, 218);
}
span.fas {
    width: 100%;
    display: block;
    color: #fff;
    font-size: 20px;
    text-align: center;
}
   
    <nav>
        <span class="fas fa-bars">bars</span>
        <a href="#">Home</a>
        <a href="#">About</a>
        <a href="#">Contact</a>
        <a href="#">Privacy Policy</a>
        <a href="#">Docs</a>
        <div class="animation start-home"></div>
        <div class="search-container">
            <form>
                <input type="text" placeholder="Search..." name="search" class="searchbar">
                <button type="submit"><i class="fas fa-search"></i><span class="text">Search</span></button>
            </form>
        </div>
    </nav>

【讨论】:

  • 图标不起作用,但我希望它在导航栏的左侧,这样导航栏中的所有其他元素都在一条水平线上
  • 您需要粘贴整个标题代码,这只是一个导航栏
  • 我没有任何标题代码。我只做了这个
猜你喜欢
  • 2020-03-21
  • 2018-11-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-21
  • 2018-02-15
  • 1970-01-01
  • 2019-11-21
相关资源
最近更新 更多