How to make properly such navigation bar, especially this two intersecting lines. I know that I can use transform: skewX(10deg); for rotating this vertical line, but not sure am I ok with whole html&css
HTML:
<main>
<div class="rounded-rectangle">
<ul class="top">
<li>
<button>text</button>
</li>
<li>
<button>text</button>
</li>
</ul>
<ul class="bottom">
<li>
<button>text</button>
</li>
<li>
<button>text</button>
</li>
</ul>
</div>
</main>
Fiddle
You could use pseudo elements of the container to draw the intersecting lines.
html,
body {
height: 100%;
}
body {
display: flex;
flex-direction: row;
font-family: 'Raleway', sans-serif;
background-color: #e24d3d;
}
main {
flex-grow: 1;
}
ul li {
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
list-style: none;
text-transform: uppercase;
font-size: 30px;
}
button {
background-color: transparent;
border: none;
color: white;
padding: 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 2.5em;
font-family: 'Raleway', sans-serif;
text-transform: uppercase;
}
button:focus {
outline: -webkit-focus-ring-color auto 0px;
}
ul.top {
display: flex;
justify-content: space-around;
height: 50%;
}
ul.top div:nth-last-child(1) {
border-right: 1px solid #FFF;
}
ul.bottom {
display: flex;
justify-content: space-around;
height: 50%;
}
.rounded-rectangle {
background-color: rgba(128, 213, 226, 0.4);
height: 320px;
max-width: 520px;
border-radius: 10px;
margin: auto;
position: relative;
}
.rounded-rectangle:before, .rounded-rectangle:after {
content: '';
position: absolute;
background: #fff;
}
.rounded-rectangle:before {
top: 50%;
height: 1px;
left: 0; right: 0;
}
.rounded-rectangle:after {
left: 50%;
width: 1px;
top: 0; bottom: 0;
transform: rotate(10deg);
}
ul {
padding: 0;
margin: 0;
}
<main>
<div class="rounded-rectangle">
<ul class="top">
<li>
<button>text</button>
</li>
<li>
<button>text</button>
</li>
</ul>
<ul class="bottom">
<li>
<button>text</button>
</li>
<li>
<button>text</button>
</li>
</ul>
</div>
</main>
Related
I'm trying to make this simple website and right now I'm working on the navbar. In the navbar I also have this logo that I created with font awesome and text, it also has a bigger font size than the other elements in the navbar. My problem is that the logo text isn't aligning with all the other text in the navbar.
* {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
font-size: 16px
}
body {
background-color: RGB(40, 43, 48);
margin: 0;
padding: 0;
}
nav {
background-color: RGB(30, 33, 36);
text-align: center;
justify-content: center;
justify-items: center;
}
.main-nav {
display: flex;
list-style: none;
padding: 0;
margin: 0;
}
.main-nav li {
padding: 10px;
}
.main-nav li a {
color: white;
text-decoration: none;
font-weight: bold;
}
.push {
margin-left: auto;
}
.nav-logo {
font-size: 20px;
display: inline-block;
position: relative;
color: white;
}
.nav-logo:after {
content: '';
position: absolute;
width: 100%;
transform: scaleX(0);
height: 2px;
top: 24px;
bottom: 0;
left: 0;
background-color: white;
transform-origin: center;
transition: transform 0.25s ease-out;
}
.nav-logo:hover:after {
transform: scaleX(1);
transform-origin: center;
}
nav-content {}
<script src="https://kit.fontawesome.com/df395811d0.js" crossorigin="anonymous"></script>
<nav>
<ul class="main-nav">
<li>
<i class="fa-solid fa-greater-than fa-18px"></i> Terminalize
</li>
<li> HTML </li>
<li> CSS </li>
<li> JavaScript </li>
<li> Python </li>
<li> Windows </li>
<li> Linux </li>
<li> MacOS </li>
<li class="nav-content push "> About </li>
</ul>
</nav>
What my navbar looks like
you just had to set align-items: center on your main-nav class, as shown below:
* {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
font-size: 16px
}
body {
background-color: RGB(40, 43, 48);
margin: 0;
padding: 0;
}
nav {
background-color: RGB(30, 33, 36);
text-align: center;
justify-content: center;
justify-items: center;
}
.main-nav {
display: flex;
align-items: center;
list-style: none;
padding: 0;
margin: 0;
}
.main-nav li {
padding: 10px;
}
.main-nav li a {
color: white;
text-decoration: none;
font-weight: bold;
}
.push {
margin-left: auto;
}
.nav-logo {
font-size: 20px;
display: inline-block;
position: relative;
color: white;
}
.nav-logo:after {
content: '';
position: absolute;
width: 100%;
transform: scaleX(0);
height: 2px;
top: 24px;
bottom: 0;
left: 0;
background-color: white;
transform-origin: center;
transition: transform 0.25s ease-out;
}
.nav-logo:hover:after {
transform: scaleX(1);
transform-origin: center;
}
nav-content {}
<script src="https://kit.fontawesome.com/df395811d0.js" crossorigin="anonymous"></script>
<nav>
<ul class="main-nav">
<li>
<i class="fa-solid fa-greater-than fa-18px"></i> Terminalize
</li>
<li> HTML </li>
<li> CSS </li>
<li> JavaScript </li>
<li> Python </li>
<li> Windows </li>
<li> Linux </li>
<li> MacOS </li>
<li class="nav-content push "> About </li>
</ul>
</nav>
So on this one challenge I keep getting the error: "The height of the welcome section should be equal to the height of the viewport." I have 100vh on it but im not sure how to fix it.
html:
<header>
<nav id="navbar">
<a href="#welcome-section" id="logo-link">
<h1>Welcome</h1>
</a>
<ul class="nav-list">
<a href="#projects">
<li>Projects</li>
</a>
<a href="#profile">
<li>Profile</li>
</a>
<a href="#contact">
<li>Contact</li>
</a>
</ul>
</nav>
</header>
<!--BODY-->
<body>
<section id="welcome-section">
<div class="header-text">
<h1><code>Hello World!</code></h1>
<p>My name is Nick</p>
</div>
</section>
css:
#navbar {
position: fixed;
top: 0;
height: 80px;
width: 100%;
background-color: #007cc7;
display: flex;
justify-content: space-between;
z-index: 5;
}
.nav-list {
display: flex;
margin-right: 20px;
margin-top: auto;
margin-bottom: auto;
}
.nav-list a {
display: block;
font-size: 1.5rem;
padding: 10px;
color: white;
}
.nav-list a:hover {
color: cyan;
}
#logo-link {
color: white;
margin-top: auto;
margin-bottom: auto;
margin-left: 10px;
font-size: 1.5rem;
}
#welcome-section {
height: 100vh;
margin-top: 20px;
text-align: center;
background-color: #12232e;
border-style: solid;
border-color: #203647;
border-width: 10px;
border-top: 0;
border-right: 0;
border-left: 0;
display: flex;
}
.header-text {
margin: auto;
}
#welcome-section h1 {
font-size: 5rem;
}
#welcome-section p {
font-size: 1.5rem;
}
Link to the challenge: https://www.freecodecamp.org/learn/responsive-web-design/responsive-web-design-projects/build-a-personal-portfolio-webpage
Working Demo: https://dojo.telerik.com/EkoCUneS/2
You need to add
* {
box-sizing: border-box;
}
html, body {
margin: 0;
padding: 0;
}
Remove margin-top from #welcome-section.
* {
box-sizing: border-box;
}
html, body {
margin: 0;
padding: 0;
}
#navbar {
position: fixed;
top: 0;
height: 80px;
width: 100%;
background-color: #007cc7;
display: flex;
justify-content: space-between;
z-index: 5;
}
.nav-list {
display: flex;
margin-right: 20px;
margin-top: auto;
margin-bottom: auto;
}
.nav-list a {
display: block;
font-size: 1.5rem;
padding: 10px;
color: white;
}
.nav-list a:hover {
color: cyan;
}
#logo-link {
color: white;
margin-top: auto;
margin-bottom: auto;
margin-left: 10px;
font-size: 1.5rem;
}
#welcome-section {
height: 100vh;
text-align: center;
background-color: #12232e;
border-style: solid;
border-color: #203647;
border-width: 10px;
border-top: 0;
border-right: 0;
border-left: 0;
display: flex;
}
.header-text {
margin: auto;
}
#welcome-section h1 {
font-size: 5rem;
}
#welcome-section p {
font-size: 1.5rem;
}
<header>
<nav id="navbar">
<a href="#welcome-section" id="logo-link">
<h1>Welcome</h1>
</a>
<ul class="nav-list">
<a href="#projects">
<li>Projects</li>
</a>
<a href="#profile">
<li>Profile</li>
</a>
<a href="#contact">
<li>Contact</li>
</a>
</ul>
</nav>
</header>
<!--BODY-->
<body>
<section id="welcome-section">
<div class="header-text">
<h1><code>Hello World!</code></h1>
<p>My name is Nick</p>
</div>
</section>
</body>
This question already has answers here:
Css-grid: Bleed background outside container
(2 answers)
Closed 2 years ago.
My navbar is within a container, and I was hoping I could extend the background yellow to the edge of the screen, but keep the Page Names within the container? I've included a Codepen -
https://codepen.io/blairhunter/pen/XWNRMgb
html,body {
background-color: #ededed;
margin: auto;
}
ul {
list-style-type: none;
margin: 0;
padding-top:4px;
padding-bottom:4px;
padding-left: 0px;
padding-right: 0px;
overflow: hidden;
background-color: yellow;
}
li {
float: left;
}
li a {
display: block;
color: black;
text-align: center;
padding: 14px 16px;
text-decoration: none;
border-radius: 5px;
}
li a:hover:not(.active) {
background-color: white;
}
.active {
background-color: white;
}
.container-main {
display: grid;
padding-top:50px;
margin-left: auto;
margin-right: auto;
max-width: 650px;
}
.container-main > div {
background-color: rgba(255, 255, 255, 0.8);
border: 1px solid black;
text-align: center;
font-size: 30px;
}
.container-nav {
display: grid;
margin-left: auto;
margin-right: auto;
max-width: 650px;
}
<body>
<div class="container-nav">
<ul>
<li><a class="active" href="#home">Home</a></li>
<li>About</li>
<li>Contact</li>
</ul>
</div>
<div class="container-main">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
</div>
</body>
I propose a solution using pseudo-classes :before and :after for class .container-nav. Do the following:
Add position: relative; to .container-nav.
And add these pseudo-classes with absolute positioning to your css.
html,
body {
background-color: #ededed;
margin: auto;
}
ul {
list-style-type: none;
margin: 0;
padding-top: 4px;
padding-bottom: 4px;
padding-left: 0px;
padding-right: 0px;
overflow: hidden;
background-color: yellow;
}
li {
float: left;
}
li a {
display: block;
color: black;
text-align: center;
padding: 14px 16px;
text-decoration: none;
border-radius: 5px;
}
li a:hover:not(.active) {
background-color: white;
}
.active {
background-color: white;
}
.container-main {
display: grid;
padding-top: 50px;
margin-left: auto;
margin-right: auto;
max-width: 650px;
}
.container-main > div {
background-color: rgba(255, 255, 255, 0.8);
border: 1px solid black;
text-align: center;
font-size: 30px;
}
.container-nav {
display: grid;
margin-left: auto;
margin-right: auto;
max-width: 650px;
position: relative; /*add this it*/
}
/*add this it************/
.container-nav:before {
content: "";
position: absolute;
left: -100%;
bottom: 0;
top: 0;
right: 100%;
background-color: yellow;
}
.container-nav:after {
content: "";
position: absolute;
left: 100%;
bottom: 0;
top: 0;
right: -100%;
background-color: yellow;
}
<body>
<div class="container-nav">
<ul>
<li><a class="active" href="#home">Home</a></li>
<li>About</li>
<li>Contact</li>
</ul>
</div>
<div class="container-main">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
</div>
</body>
You could wrap it in another container to extend background
<div class="yellow">
<div class="container-nav">
<ul>
<li><a class="active" href="#home">Home</a></li>
<li>About</li>
<li>Contact</li>
</ul>
</div>
</div>
.yellow{
background-color: yellow;
}
I'm kinda confused and tried out everything I'm able to try. Searching stack overflow I couldn't find the similar problem. So a little background, I'm trying to make a navigation menu with flexbox like in the picture down below, but I can't display link's border-bottom out of its parent div. Is it even possible?
This is what I want
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.wrap {
max-width: 1170px;
padding: 0 15px;
margin: 0 auto;
}
.header {
background: #44433e;
}
.header__menu {
display: flex;
justify-content: space-between;
align-items: stretch;
}
.header__logo {
padding: 10px 0;
}
.menu__list {
display: flex;
list-style: none;
align-items: center;
}
.menu__item {
margin-left: 15px;
}
.menu__item:first-child {
margin-left: 0;
border-bottom: 3px solid #18cfab;
}
.menu__link {
display: inline-block;
font-family: "Montserrat-bold";
color: #b8b8b8;
font-size: 13px;
line-height: 42px;
text-decoration: none;
text-transform: uppercase;
}
.menu__link-active {
color: #18cfab;
}
<header class="header">
<div class="header__wrap wrap">
<nav class="header__menu menu">
<div class="header__logo">
Logo
</div>
<ul class="menu__list">
<li class="menu__item">home</li>
<li class="menu__item">about</li>
<li class="menu__item">skills</li>
<li class="menu__item">service</li>
<li class="menu__item">work</li>
</nav>
</div>
</header>
You can achieve this using an :after element with a position: absolute:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.wrap {
max-width: 1170px;
padding: 0 15px;
margin: 0 auto;
}
.header {
background: #44433e;
}
.header__menu {
display: flex;
justify-content: space-between;
align-items: stretch;
}
.header__logo {
padding: 10px 0;
}
.menu__list {
display: flex;
list-style: none;
align-items: center;
}
.menu__item {
margin-left: 15px;
position: relative;
}
.menu__item:first-child {
margin-left: 0;
}
.menu__item:first-child:after {
content: "";
position: absolute;
top: 100%;
left: 0;
width: 100%;
height: 3px;
background-color: #18cfab;
}
.menu__link {
display: inline-block;
font-family: "Montserrat-bold";
color: #b8b8b8;
font-size: 13px;
line-height: 42px;
text-decoration: none;
text-transform: uppercase;
}
.menu__link-active {
color: #18cfab;
}
<header class="header">
<div class="header__wrap wrap">
<nav class="header__menu menu">
<div class="header__logo">
Logo
</div>
<ul class="menu__list">
<li class="menu__item">home</li>
<li class="menu__item">about</li>
<li class="menu__item">skills</li>
<li class="menu__item">service</li>
<li class="menu__item">work</li>
</nav>
</div>
</header>
I have a dropdown menu consists of ul nested in another ul's list item position absolute.
indeed I want the child ul that represents the dd menu to take its parent li width but it takes its grandparent's ul width instead.
changing the position to relative will disrupt the li style/order don't know why.
nav {
position: relative;
display: flex;
width: 100%;
margin: 0 auto;
justify-content: space-between;
}
nav>ul.nav_list {
position: relative;
display: flex;
justify-content: space-around;
align-items: flex-start;
height: 40px;
}
nav>ul>li {
height: 100%;
margin: 0px 4px;
padding: 0px 8px;
font-size: 18px;
}
nav>ul>li>div {
border-bottom: 2px solid #D88B1D;
padding: 8px 9.5px 2px;
transition: border-bottom .1s;
line-height: 22px;
}
nav>ul>li>div:hover {
border-bottom: 4px solid #D88B1D;
}
.first {
display: flex;
justify-content: center;
width: 242px;
}
li.dropdown {
font-size: 18px;
font-weight: bold;
}
.dropdown:hover {
display: flex;
justify-content: center;
background-color: #42526e;
border-radius: 5px 5px 0px 0px;
}
.dropdown:hover>div.first {
border: none;
}
nav>ul>li>ul.dropdown-content {
position: absolute;
top: 100%;
left: 0;
width: 100%;
display: none;
background-color: gold;
z-index: 99;
}
li.dropdown:hover>ul.dropdown-content {
display: block;
}
.dropdown:hover>div.first>a {
color: white;
}
<nav>
<ul class="nav_list">
<li class="dropdown">
<div class="first">
All Catgories
</div>
<ul class="dropdown-content">
<li> Link1</li>
<li> Link2</li>
<li> Link3</li>
</ul>
</li>
<li>
<div>Shop by brand</div>
</li>
<li>
<div>Online Exclusive</div>
</li>
</ul>
</nav>
When you need to position: absolute an element relatively to its parent, you need the parent to have it's own stacking context. So the parent becomes an offsetParent -- its offset boundaries will be used for positioning.
In your case, you have to set position: relative to li.dropdown.
Then, on ul.dropdown-content, set left: 0; right:0; to stretch it between left and right boundaries so it takes 100% of parent's width:
nav>ul.nav_list {
display: flex;
justify-content: space-around;
align-items: flex-start;
height: 40px;
}
nav>ul>li {
height: 100%;
margin: 0px 4px;
padding: 0px 8px;
font-size: 18px;
}
nav>ul>li>div {
border-bottom: 2px solid #D88B1D;
padding: 8px 9.5px 2px;
transition: border-bottom .1s;
line-height: 22px;
}
nav>ul>li>div:hover {
border-bottom: 4px solid #D88B1D;
}
.first {
text-align: center;
width: 242px;
}
li.dropdown {
font-size: 18px;
font-weight: bold;
position:relative;
}
.dropdown:hover {
background-color: #42526e;
border-radius: 5px 5px 0px 0px;
}
.dropdown:hover>div.first {
border: none;
}
nav>ul>li>ul.dropdown-content {
position: absolute;
top: 100%;
right:0; left: 0;
display: none;
background-color: gold;
}
li.dropdown:hover>ul.dropdown-content {
display: block;
}
.dropdown:hover>div.first>a {
color: white;
}
<nav>
<ul class="nav_list">
<li class="dropdown">
<div class="first">
All Catgories
</div>
<ul class="dropdown-content">
<li> Link1</li>
<li> Link2</li>
<li> Link3</li>
</ul>
</li>
<li>
<div>Shop by brand</div>
</li>
<li>
<div>Online Exclusive</div>
</li>
</ul>
</nav>