I tried to make a responsive header for my website, it's all ok, but i can not set the margins of the links to 0. You cand see in the image: https://imgur.com/s5EzL6n
What i want to achieve is to make all that grey background 100% width.
I followed this youtube video: https://www.youtube.com/watch?v=lYw-FE60Dws
I probably set some things wrong, i am sure, but i am a beginner.
HTML:
<header>
<div class="container">
<div id="branding">
<img src="logo.png">
<a class="toggle">Meniu</a>
</div>
<nav>
<ul class="active">
<li class="current">Acasă</li>
<li>Despre</li>
<li>Servicii</li>
<li>Proiecte</li>
<li>Contact</li>
</ul>
</nav>
</div>
</header>
CSS:
/* responsive header*/
.toggle{
display: none;
position: absolute;
right: 10px;
top: 26px;
padding: 5px;
cursor: pointer;
text-decoration: none;
}
#media (max-width: 940px){
.toggle{
display: block;
}
header .toggle{
padding: 0 0;
font-size: 18px;
}
header ul li{
display: block;
width: 100%;
background-color: grey;
}
header ul.active{
display: block;
}
header ul li a{
display: block;
text-align: center;
}
header nav{
margin: 0;
width: 100%;
}
header ul li{
width: 100%;
}
}
/*normal page*/
header a{
color: #fcfcfc;
text-decoration: none;
text-transform: uppercase;
font-size: 16px;
padding-right: 25px;
}
header li{
float: left;
display: inline;
padding: 0 20px 0px 20px;
}
header #branding{
float: left;
height: 90px;
margin-left: 35px;
}
header a{
color: #fcfcfc;
text-decoration: none;
text-transform: uppercase;
font-size: 16px;
padding-right: 25px;
}
there is a default padding for ul, you have to remove it when you don't need it. Just add 0px to the ul and you will have a 100% div
Try to use css box models to solve such cases
https://www.youtube.com/watch?v=xF0dhepbzD8
Related
I am building a navbar with hover effects over the nav items and an inline button, however, the text in my button is not lining up with the other nav items. In addition I am having trouble figuring out how to get the red hover background to space itself evenly above and below the text of my nav items. What am I doing wrong?
<nav class="navbar">
<a id="header" href="#">Adopt <span class="me">Me</span> </a>
<ul >
<div id="rightitems">
<li>About Us</li>
<li>What we do</li>
<li>Benefits</li>
<li>Our Buddies</li>
<button class="btn">Contact Us</button>
</div>
</div>
</ul>
</nav>
.btn{
display: inline;
width: auto;
text-decoration: none;
margin: 0;
}
.btn a{
margin: 0;
}
body{
background-image: url(bulldog.jpg)
}
a{
text-decoration: none;
}
nav ul{
list-style-type: none;
margin: 0;
padding:0;
text-decoration: none;
display: flex;
position: relative;
}
nav a{
margin-right: 10px;
margin-left: 10px;
padding-top: 10px;
}
.navbar{
display: flex;
justify-content: space-between;
width: 100%;
}
#rightitems{
display: flex;
}
li{
width: auto;
}
li:hover{
width: auto;
}
li:hover {
background-color: #FF4850;
color: white;
border-radius: 10px;
}
nav li:hover{
color: white;
}
nav a:hover{
color: white;
}
Looks like some duplicate selectors and a bit of redundant styling. I've made some adjustments check out this fiddle:
nav a {
margin: 10px;
text-decoration: none;
}
nav a:not('me'):hover{
color: white;
}
.navbar #rightitems li{
padding: 10px 5px;
}
https://jsfiddle.net/cf2vd64y/2/
I'm trying to do a tab header, its a list of the titles, sometimes the titles are too long and has "-" in between. So to save space I add br to breakline.
1/The problem is the distance up & down between the "-" symbols is too big, is there any way I can fix that?
is this a correct way to do it by set br tag or should I set max-width for each li for the breakline?
This is my codepen
<div>
<ul>
<li>Real Estate, <br> Building House</li>
<li>Distribution <br>–<br> Manufacturing</li>
<li>Media <br>–<br> Broadway theater</li>
<li>Singer <br>–<br> dancer</li>
<li>Real Estate</li>
<li>Construction</li>
</ul>
div {width: 80%; margin: 0 auto;}
ul {
list-style: none;
/* display: table; */
width: 100%;
padding: 0;
margin: 0;
}
ul li {
position: relative;
font-size: 1.4rem;
/* display: table-cell; */
color: blue;
text-align: center;
display: inline-block;
margin-right: 20px;
}
Hope this helps you:
ul li {
font-size: 1.4rem;
color: red;
max-width: 120px;
padding: 10px;
vertical-align: middle;
text-align: center;
/* padding: 0 5px; */
display: inline-block;
margin-right: 14px;
}
Updated codepen
I am trying to give the tags a width of 20% inside this ul, but I am unable. Any help would be grateful. I am able to set the width of the li items, but I am looking to set the width to the <a>.
<nav>
<ul class="navigation">
<li class="main_nav_li">Home</li>
<li class="main_nav_li">About</li>
<li class="main_nav_li">Services</li>
<li class="main_nav_li">Stylist</li>
<li class="main_nav_li">Contact</li>
</ul>
</nav>
<style>
nav{
width:98%;
border: 1px solid black;
overflow:hidden;
height:3em;
}
.nav{
list-style-type:none;
margin:0;
padding:0;
overflow: hidden;
}
li{
list-style-type: none;
float: left;
padding-top: 1em;
}
a{
width: 20%;
text-align: center;
line-height: 10%;
font-size: 1em ;
text-decoration:none;
padding-top: 0.5em;
font-family: 'Happy Monkey', cursive;
}
</style>
you can't set a width to an inline element.
Add display: inline-block; and it will work
a{
width: 20%;
text-align: center;
line-height: 10%;
font-size: 1em ;
text-decoration:none;
padding-top: 0.5em;
font-family: 'Happy Monkey', cursive;
display: inline-block;
}
They are inline elements by default. You must use:
display: inline-block;
Block-level elements allow you to set width, inline ones do not.
Here's a working example:
http://jsfiddle.net/rKwkH/1/
I had to apply the width and display:inline-block to the li:
li{
list-style-type: none;
float: left;
width: 20%;
display: inline-block;
}
So I'm trying to figure out a way to make the tabs in my navigation bar clickable as well as the link text. Adding padding: 20px 30px; makes the second to last tab shift up and the text shift to the right. I'm willing to do some major alterations so please any answer is a good one.Here's my HTML.
<div id="tab_container">
<nav id="tabs">
<ul id="nav">
<li class="active">About</li>
<li class="inactive">Services</li>
<li class="inactive">Our Staff</li>
<li class="inactive">book</li>
<li class="inactive">Gift Cards</li>
<li class="inactive">Reviews</li>
</ul>
</nav>
</div>
Heres the CSS...
#tab_container
{
background-color: #222;
display: -webkit-box;
-webkit-box-flex: 1;
display: block;
position: relative;
max-width: 970px;
width: 100%;
text-align: center;
}
#tabs
{
float: left;
margin-top: 0px;
width: 100%;
max-width: 970px;
background-color: #222;
padding-top: 20px;
text-align: center;
}
#nav
{
width: 100%;
max-width: 970px;
text-align: center;
}
ul
{
float: left;
max-width: 970px;
display: -webkit-box;
-webkit-box-flex: 1;
width: 100%;
padding-left: 0px;
margin-bottom: 0px;
margin-top: 0px;
margin-right: 0px;
text-align: center;
}
ul li
{
display: inline-block;
text-align: center;
width: 158px;
height: 70px;
background-color: black;
font-size: 18px;
text-transform: uppercase;
text-align: center;
margin:0 auto;
padding: 0;
}
ul li a
{
color: #54544b;
text-decoration: none;
text-align: center;
margin: 0px auto;
line-height: 70px;
padding: 20px 30px;
}
a:hover
{
color: #CF7BA1;
}
.active a
{
text-decoration: underline;
color: #CF7BA1;
}
set display-blocks to A:
ul li a {
display:block;
height:100%;
width:100%;
line-height:XXpx;
}
opera mini / mobile behaves strange on menu links links, they are not visible (actually, as the site renders they become visible for a second, and then they are not visible anymore, but the text is selectable.). On other browsers, everything is fine. Anyone knows the reason for that?
(i tried with media queries disabled, same thing)
html code
<div id="navbox">
<nav>
<ul>
<li>Usluge</li>
<li>Cvijeće</li>
<li>Galerija</li>
<li>O nama</li>
<li>Kontakt</li>
</ul>
</nav>
</div>
css code
#navbox {
width: 620px;
float: left;
font-size: 14px;
font-family: 'Open Sans', sans-serif;
}
#navbox nav {
width: 620px;
float: left;
margin-top: 66px;
}
#navbox li {
width: 68px;
float: right;
list-style: none;
margin-left: 24px;
background: rgb(230,230,230);
}
#navbox a {
display: block;
padding: 134px 0px 0px 0px;
border: 0px solid rgb(195,195,195);
color: rgb(171,74,119);
text-decoration: none;
text-align: center;
}
Try this in your CSS:
#navbox nav {
width: 620px;
float: left;
margin-top: 66px;
}
#navbox li {
float: right;
list-style: none;
margin-left: 24px;
background: rgb(230,230,230);
}
#navbox a {
display: block;
padding: 15px 20px; //adjust to your liking
border: 0px solid rgb(195,195,195);
color: rgb(171,74,119);
text-decoration: none;
text-align: center;
}
#media screen and (max-width:767px){
#navbox nav {
width:100%;
}
}
If it doesn't work out for you, can you post a link to your page so we can take a look?