Hi, i have a problem. Im really new to html. I want the shopping cart to be in the same row as the navigation bar.
Should i create a new object? And if yes how can i create it that the cart is in the navigation bar? When i use float:right its lower than the rest of the navigation bar. What can I do?
Hi,
I would use flexbox to align the last menu item to the right side.
That will keep everything on the same line also.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flexbox Menu - Align Last Item to Right</title>
<style>
.menu {
margin:0 auto;
padding:10px;
list-style:none;
display:flex;
/*max-width:980px;/*optional max width with margin:0 auto;*/
justify-content:center;
background:#f9f9f9;
}
.menu li {margin:0 10px;}
.menu li:first-child {margin-left:auto}/*these can be grouped together*/
.menu li:last-child {margin-left:auto}
</style>
</head>
<body>
<nav>
<ul class="menu">
<li><a href="#">New</a></li>
<li><a href="#">Women</a></li>
<li><a href="#">Men</a></li>
<li><a href="#">Kids</a></li>
<li><a href="#">Shopping Cart</a></li>
</ul>
</nav>
</body>
</html>
There are missing quotation marks. Correct the syntax error and try validating the web page.
Without seeing the code I am guessing.
If you placed vertical margins on all the anchors they are likely being ignored on all but the float, since it becomes a block level element. Something like that would be a beginners mistake.
By default, anchors are inline elements, which do not accept vertical margins.
Here is a test case showing how the float will catch the vertical margins.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test Page</title>
<style>
div {
text-align:center;
overflow:auto;/*contain float*/
background:#ccc;
}
div a {margin:10px;} /*vertical margin will not apply to inline elemnts*/
div a:last-child {
float:right; /*this float will accept vertical margins*/
/* margin:0 10px; /*remove vertical margin, remove comments to see anchors line up*/
}
</style>
</head>
<body>
<div>
<a href="#">link</a>
<a href="#">link</a>
<a href="#">link</a>
<a href="#">last link</a>
</div>
</body>
</html>
In a situation like that you would correct the problem where it started rather than overriding it for the float.
By setting the vertical margins to 0 to begin with.
div a {margin:0 10px;}
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.