Positioning horizontal menu using flexbox - html

I am trying to do fixed menu using flexbox. In my navigation bar I created 2 divs. First should contain logo, and second menu(with display:flex property). I've got problem, when I want to postion the li element of my menu. I want horizontal menu, but when I add justify-content:space-between my first element should be situated in left edge of menu's div but it has a small margin and I don't know why.
https://jsfiddle.net/4Lmu08yc/
header {
height:100vh;
background-color:yellow;
width:100vw;
max-width:100%;
}
.navbar {
width:100vw;
background-color:grey;
height:7vh;
max-width:100%;
position:fixed;
border-bottom:5px solid white;
z-index:2;
}
.flex_row {
display:flex;
flex-direction:row;
}
.container{
height:100%;
width:100vw;
max-width:100%;
background-color:green;
display:flex;
}
#logo {
height:100%;
background-color:white;
flex-grow:1;
}
#menu {
height:100%;
background-color:yellow;
flex-grow:1;
}
#menu ul {
list-style-type:none;
justify-content:flex-start;
align-content:flex-end;
}
#menu ul li {
border:1px solid black;
line-height:40px;
}
<header>
<div class="container">
<div class="navbar flex_row">
<div id ="logo"></div>
<div id ="menu">
<ul class="flex_row">
<li>text1</li>
<li>text2</li>
<li>text3</li>
<li>text4</li>
</ul>
</div>
</div>
</div>
</header>

You have to add margin:0; to '#menu ul'.
HTML automatically adds a margin to unorderded lists.
#menu ul {
margin:0;
}

Related

Vertical submenu with divs

I'm trying to place submenu right below its's choosing option like this but when I set left and right attributes on 0
.sidebar_wrapper
{
position:absolute;
background-color:lightgray;
left:0;
right:0;
}
it has whole site's width. When I set them on auto it looks like this.
How do I place my submenu exactly below this div or, what would look even cooler, on it's right?
Code (whole JSFiddle in comments):
HTML:
<div id="sidebar">
<div class="sidebar_option">Strona główna</div>
<div class="sidebar_option">Galeria</div>
<div class="sidebar_option">Reżyserzy
<div class="sidebar_wrapper">
<div class="submenu" style="margin-top:10px">Quentin Tarantino</div>
<div class="submenu">Bracia Coen</div>
<div class="submenu">Wes Anderson</div>
</div>
</div>
<div class="sidebar_option">Ulubione filmy</div>
<div class="sidebar_option">Seriale</div>
<div class="sidebar_option">Kontakt</div>
</div>
CSS:
.submenu
{
text-align:center;
border-bottom:dotted 2px black;
padding-top:10px;
padding-bottom:10px;
display:none;
font-size:13px;
}
.sidebar_wrapper
{
position:absolute;
background-color:lightgray;
left:auto;
right:auto;
}
.sidebar_option:hover div
{
display:block;
}
.sidebar_option:hover
{
background-color:lightgray;
cursor:pointer;
}
.sidebar_option
{
text-align:center;
margin:10px;
padding:10px;
border-bottom:dotted 2px black;
}
I think the key is you need to set the position of the sidebar_option to relative so that the submenu_wrapper will be position in relation to the sidebar instead of the window. Then some value for left and right for the submenu. It can be anything, but if you want it centered they need to be the same.
.sidebar_option {
position: relative;
}
.sidebar_wrapper {
position: absolute;
background-color:lightgray;
left: 5%;
right: 5%;
z-index: 2;
}
Here's the updated jfiddle: https://jsfiddle.net/8d3p50hy/13/

How to make video size fills the site width

Hi guys I'm starting to build my first site in html5+css3 beign responsive as a goal but I have a problem trying to add a video after the header. Thing is I need my video fills the total website width. I try with "width:100%" it doesn't works.
It works when I remove "display:flex;" of #body, but I think I will need this property since I'm planning to add flexible boxes inside of #body, and if I want put flexible boxes inside #body I need set it to "display:flex" right? Im new in html5&css3 so please correct me if I'm wrong.
If anybody could help me that would be great. Thanks!
HTML:
<!DOCTYPE html>
<html>
<head>
<link href="style.css" rel="stylesheet">
<link href='https://fonts.googleapis.com/css?family=Patua+One' rel='stylesheet' type='text/css'>
</head>
<body>
<header>
<div id="logo">
<img src="imagenes/logo.png"/>
</div>
<nav id="menuP">
<ul>
<li>ALL PRODUCTS</li>
<li>SERVICES</li>
<li>ABOUT</li>
<li>SAMPLES</li>
<li>QUOTE</li>
</ul>
</nav>
<nav id="menuS">
<ul>
<li id="account">ACCOUNT</li>
<li id="shop">SHOP</li>
<li id="contact">CONTACT</li>
</ul>
</header>
<section id="body">
<section id="slide">
<video loop id="videoSlide">
<source src="eu4_ost.webm" type="video/webm">
</video>
</section>
</section>
<footer>
</footer>
</body>
</html>
CSS
* {
margin:0px;
padding:0px;
}
header, section, footer, aside, nav, article, hgroup{
display:block;
}
html{
width:100%;
background:white;
height:100%;
font-family:Helvetica;
}
body {
display:flex;
background:gray;
justify-content:center;
max-width:2000px;
flex-direction:column;
}
/* -------------------------------- HEADER ------------------------------------ */
header{
width:100%;
background:#fabe06;
display: flex;
justify-content: center;
height:70px;
}
header nav ul{
list-style:none;
}
/* ----------------------------------- LOGO ------------------------------------- */
#logo{
margin:0px 0px 0px 32px;
width:260px;
display:flex;
align-items:center;
}
#logo img{
width:100%;
}
/* ----------------------------- MENU PRINCIPAL ---------------------------------- */
#menuP{
display:flex;
font-family:Patua One;
font-size:17px;
flex:2;
margin:0 50px;
justify-content:center;
align-items:center
}
#menuP ul li{
display:inline-block;
margin:0 15px;
}
#menuP ul li a{
text-decoration:none;
color:black;
}
/* ----------------------------- MENU SECUNDARIO ---------------------------------- */
#menuS{
flex:1;
display:flex;
justify-content:flex-end;
}
#menuS ul{
display:flex;
}
#menuS ul li a{
height:70px;
width:70px;
display:inline-block;
border-left:solid 1px;
border-color:#eab309;
text-indent:-99999px;
/*background:yellow;*/
}
#menuS ul li a{
}
header nav ul li#account a{
background-image:url(imagenes/account.png);
background-repeat:no-repeat;
background-size:contain;
background-position:center;
background-size:20%;
}
header nav ul li#shop a{
background-image:url(imagenes/shop.png);
background-repeat:no-repeat;
background-size:contain;
background-position:center;
background-size:25%;
}
header nav ul li#contact a{
background-image:url(imagenes/contact.png);
background-repeat:no-repeat;
background-size:contain;
background-position:center;
background-size:25%;
}
/*---------------------------- BODY -------------------------*/
#body {
width:100%;
background:yellow;
display:flex;
flex-grow:1;
}
#videoSlide{
width:100%;
}
Alright, so pretty simple, the thing is that even though the video has the width: 100% property, its parent does not. The percentage unit is used based on the parent's width or height, so if the parent is not full page width it won't work.
Just add this to your style.css:
#slide
{
width: 100%;
}
Also, just noticed you never closed the <nav> element .menuS so I'd do that if I were you to avoid further trouble.
Good luck.
Use two divs in the body and remove flex from body.
First div is video
Second is flex with main content

clearfix not working for position absolute

I have a div containing position absolute and float left and right. Now i want to place an image below the first div.
Now the problem is the image overlapping below the first div. I want the image to display below first div without overlapping.
https://jsfiddle.net/jv7afgn1/
<div class="top">
<div class="left" align="center">
<p>Sell</p>
<p>Download App</p>
<p>24x7 Customer Care</p>
</div>
<div class="right" align="center">
<p>Track Order</p>
<p>Help</p>
<p>About</p>
<p>Contact</p>
</div>
</div>
<div class="clearfix"></div>
<div class="logo_menu">
<p><img src="assets/images/logo.png" alt="" title="" /></p>
</div>
.clearfix {
clear:both;
}
/* Top */
.top {
width:100%;
height:auto;
background:#E9E9E9;
position:absolute;
padding:10px;
}
.top .left {
float:left;
}
.top .left p {
display:inline-block;
margin:0 10px 0 10px;
font-size:12px;
}
.top .left p a {
text-decoration:none;
color:#B5B5B5;
}
.top .left p a:hover {
text-decoration:underline;
color:#FD6123;
}
.top .right {
float:right;
}
.top .right p {
display:inline-block;
margin:0 10px 0 10px;
font-size:12px;
}
.top .right p a {
text-decoration:none;
color:#B5B5B5;
}
.top .right p a:hover {
text-decoration:underline;
color:#FD6123;
}
/* Menu and Logo */
.logo_menu {
width:100%;
height:auto;
}
Do you even have to absolute position the logo?
An absolute positioned element is on "it's own layer" of the homepage,
so trying to clear floats wont work.
My clearfix usually looks like this:
.clearfix:after {
clear:both;
display:block;
content: "";
}
Fiddle: https://jsfiddle.net/jv7afgn1/4/
Add padding top value equal to height of your navigation bar fixed at the top
Demo
.logo_menu {
width:100%;
height:auto;
padding-top:30px;
}

When browser window is resized my text in navigation gets overlaped with header

HTML
<!--Head-->
<div class="header_image">
<!-- <div class="leftImage"> -->
<img class="center_image" src="Final_Logo.png"/>
<!-- </div> -->
<!-- <div class="rightText"> --> <!-- I have commented these div so as to see if by chance they work in one div but i Both case problem is occurring.-->
<p>text<br>Contact Us</p>
<!-- </div> -->
</div>
<!--Navigation Bar-->
<div class="header" id="change">
<ul>
<li>Home</li>
<li>How It Works</li>
<li>Experts</li>
<li>Ask</li>
<li>Blog</li>
<li>Login</li>
<li>Register</li>
</ul>
</div>
CSS Code
body
{
background-image:url("LivingRoom.jpg");
background-repeat:no-repeat;
background-attachment:fixed;
width:100%;
}
.header
{
display:inline-block;
background-color:#000000;
width:100%;
height:6%;
position:fixed;
top:0;
left:0;
z-index:99;
margin:4% auto;
text-align:center;
white-space:nowrap;
}
#change.header2 /*this css is used for scrolling purpose. Its code is in javascript*/
{
display:inline-block;
background-color:#000000;
width:100%;
height:6%;
position:fixed;
top:0;
left:0;
z-index:99;
margin:0 auto;
text-align:center;
white-space:nowrap;
}
ul
{
list-style:none;
display:inline-block;
width:100%;
margin:0 auto;
white-space:nowrap;
}
li
{
padding-top:.5%;
display:inline-block;
text-align:center;
white-space:nowrap;/*When I add width then when browser is resized text in menu overlaps*/
}
a:link, a:visited
{
display:inline-block;
width:150px;
text-align:center;
padding-left:1.5%;
padding-right:1.5%;
text-decoration:none;
color:white;
font-size:150%;
margin:0 auto;
}
a:hover,a:active
{
background-color:white;
color:black;
}
.header_image/*This is the header above menu when browser is resized the menu scrolls to the top of header*/
{
float:left;
top:0;
left:0;
right:0;
background-color:white;
height:8.5%;
width:100%;
}
When I resize the browser windows the navigation bar moves upwards overlapping with the logo and other information in the header.Also I am facing one problem that when I resize the browser the text gets overlapped with one another if I add width to <li> tag. How to avoid overlapping by using width? Please suggest.

CSS: Position problem

Hey guys. Im setting a position:absolute to my UL to make it appear on the bottom of div #destaques, but isnt work. Whats going on?
<div id="destaques">
<ul>//stuff</ul>
<div class="banner"><img src="images/001.jpg"/></div>
<div class="banner"><img src="images/002.jpg"/></div>
<div class="banner"><img src="images/003.jpg"/></div>
<div class="banner"><img src="images/004.jpg"/></div>
</div>
Its currently appearing on the page bottom.
#destaques {
margin:0;
padding:0;
width:1000px;
height:250px;
float:left;
overflow:hidden;
}
#destaques .banner {
position:absolute;
}
#destaques ul {
float:left;
border:1px solid #777;
background:#fff;
position:absolute;
margin:0;
color:#333;
padding:0;
right:0px;
}
What im doing wrong?
Thanks!
You need to add:
position:relative;
to your #destaques div