【问题标题】:Is there a way to put border botton in same div element有没有办法将边框按钮放在同一个 div 元素中
【发布时间】:2019-02-19 22:25:14
【问题描述】:

除了将border-bottom 的div 元素放在主div 之外,还有一种方法可以将border-bottom 放在主div 元素的内部。这是我想要发生的屏幕截图https://i.imgur.com/jmAkBP7.png,因为您注意到有一条蓝线,那将是边框底部。

html,
body {
    margin: 0;
    padding: 0;
}
.wrap {
    height: 100vh;
    display: grid;
    grid-gap: 3px;
    grid-template-columns: repeat(12, 1fr);
    grid-template-rows: 100px auto 100px;
}

.headNav {
    position: relative;
    grid-column: 1 / -1;
    overflow: hidden;
    /* background: #000; */
}


.menu {
    grid-column: 1 / 3;
    grid-row: auto;
    /* background: pink; */
}

.content {
    grid-column: 3 / -1;
    /* background-color: blue; */
}

.footer {
    grid-column: 1 / -1;
    /* background: #000; */
}

.body {
    background-image: linear-gradient( 
                    rgba(0, 31, 63, 0.958), 
                    rgba(0, 31, 63, 0.958) ) 
                    ,url(./img/bgmain.jpg);
    background-size: cover;
}

.logo {
    display: inline;
}

.logo > img  {
    display: inline;
    padding-top: 10px;
    height:80px;
    padding-left: 20px;
}

.link, ul, li {
    display: inline;
    list-style-type: none;
}

.link {
    position: absolute;
    top: 45px;
    left: 32.2%;
}

 li a {
    font-family: 'Raleway', sans-serif;
    font-weight: 900;
    text-transform: uppercase;
    text-decoration: none;
    font-size: 20px;
    color: #fff;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Jury Gregorio - Homepage</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="main.css">
    <link href="https://fonts.googleapis.com/css?family=Raleway" rel="stylesheet">
</head>
<body>
    <div class="wrap body">
        <div class="headNav">
            <div class="logo"><img src="./img/logo.png" alt="Logo"></div>
            <div class="link">
                <ul><li><a href="">Home</a></li></ul>
                <ul><li><a href="">About</a></li></ul>
                <ul><li><a href="">Blog</a></li></ul>
                <ul><li><a href="">Contact</a></li></ul>
            </div>
        </div>
        <div class="menu"></div>
        <div class="content"></div>
        <div class="footer"></div>
    </div>
</body>
</html>

【问题讨论】:

  • 你的代码有codepen/fiddle吗?编辑:你可以试试border-bottom: 2px solid [color].menu
  • jsfiddle.net/bxtp73cm这位先生

标签: html css


【解决方案1】:

像这样:

html,
body {
    margin: 0;
    padding: 0;
}
.wrap {
    height: 100vh;
    display: grid;
    grid-gap: 3px;
    grid-template-columns: repeat(12, 1fr);
    grid-template-rows: 100px auto 100px;
}

.headNav {
    position: relative;
    grid-column: 1 / -1;
    overflow: hidden;
    /* background: #000; */
}


.menu {
    grid-column: 1 / 3;
    grid-row: auto;
    /* background: pink; */
}

.content {
    grid-column: 3 / -1;
    /* background-color: blue; */
}

.footer {
    grid-column: 1 / -1;
    /* background: #000; */
}

.body {
    background-image: linear-gradient( 
                    rgba(0, 31, 63, 0.958), 
                    rgba(0, 31, 63, 0.958) ) 
                    ,url(./img/bgmain.jpg);
    background-size: cover;
}

.logo {
    display: inline;
}

.logo > img  {
    display: inline;
    padding-top: 10px;
    height:80px;
    padding-left: 20px;
}

.link, ul, li {
    display: inline;
    list-style-type: none;
}

.link {
    position: absolute;
    top: 45px;
    left: 32.2%;
}

 li a {
    font-family: 'Raleway', sans-serif;
    font-weight: 900;
    text-transform: uppercase;
    text-decoration: none;
    font-size: 20px;
    color: #fff;
}

ul {
  border-bottom: 2px solid blue;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Jury Gregorio - Homepage</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="main.css">
    <link href="https://fonts.googleapis.com/css?family=Raleway" rel="stylesheet">
</head>
<body>
    <div class="wrap body">
        <div class="headNav">
            <div class="logo"><img src="./img/logo.png" alt="Logo"></div>
            <div class="link">
                <ul>
                <li><a href="">Home</a></li>
                <li><a href="">About</a></li>
                <li><a href="">Blog</a></li>
                <li><a href="">Contact</a></li>
                </ul>
            </div>
        </div>
        <div class="menu"></div>
        <div class="content"></div>
        <div class="footer"></div>
    </div>
</body>
</html>

【讨论】:

  • 谢谢先生,但是,先生的结果是它会在每个li标签上创建一行i.imgur.com/cuscD0U.png
  • 你必须删除所有的 ul 标签,ul 必须像我一样包含所有的 li
  • 哦,抱歉,我没有注意到我的 HTML 模板上有很多 ul 标签...tnx 先生
猜你喜欢
  • 2021-01-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-08
相关资源
最近更新 更多