I need to align logo to left and navigation to right and the text in logo and navigation must be aligned bottom of the logo-nav div.
Note: Without flex box
.logo {
float: left;
}
.navigation {
float: right;
}
.clear {
clear: both;
}
<div class="logo-nav">
<div class="logo">Partners</div>
<div class="navigation">
<ul class="nav-ul">
<li class="nav-li">OUR SPIRIT</li>
<li class="nav-li">OUR OFFER</li>
<li class="nav-li">OUR VISIONARY</li>
<li class="nav-li">CONTACT</li>
</ul>
</div>
<div class="clear"></div>
</div>
You can use Flexbox for this. You just need to set margin-left: auto on navigation and align-items: flex-end for vertical-align.
.logo img {
vertical-align: top;
}
.logo-nav, .nav-ul {
display: flex;
align-items: flex-end;
list-style: none;
margin: 0;
}
.navigation {
margin-left: auto;
}
<div class="logo-nav">
<div class="logo"><img src="http://placehold.it/100x50"></div>
<div class="navigation">
<ul class="nav-ul">
<li class="nav-li">OUR SPIRIT</li>
<li class="nav-li">OUR OFFER</li>
<li class="nav-li">OUR VISIONARY</li>
<li class="nav-li">CONTACT</li>
</ul>
</div>
<div class="clear"></div>
</div>
You can also use CSS tables.
.logo img {
vertical-align: top;
}
.logo-nav {
display: table;
width: 100%;
border-bottom: 1px solid black;
}
ul {
margin: 0;
}
.logo,
.navigation {
display: table-cell;
vertical-align: bottom;
}
.navigation {
text-align: right;
}
li {
display: inline-block;
}
<div class="logo-nav">
<div class="logo">
<img src="http://placehold.it/100x50">
</div>
<div class="navigation">
<ul class="nav-ul">
<li class="nav-li">OUR SPIRIT</li>
<li class="nav-li">OUR OFFER</li>
<li class="nav-li">OUR VISIONARY</li>
<li class="nav-li">CONTACT</li>
</ul>
</div>
<div class="clear"></div>
</div>
.logo-nav{
height:40px;
border-bottom:1px solid black;
width:100%;
margin:0;
padding:0;
}
.navigation{
float:right;
margin:0;
padding:0;
height:100%;
}
.navigation ul{
margin:0;
padding:0;
height:100%;
}
.navigation ul li{
margin:0;
padding:0;
float:left;
margin:0 5px;
list-style-type:none;
display:flex;
align-items:flex-end;
height:100%;
}
.logo{
float:left;
margin:0;
padding:0;
height:100%;
display:flex;
align-items:flex-end;
}
<div class="logo-nav">
<div class="logo">+CoPartners</div>
<div class="navigation">
<ul class="nav-ul">
<li class="nav-li">OUR SPIRIT</li>
<li class="nav-li">OUR OFFER</li>
<li class="nav-li">OUR VISIONARY</li>
<li class="nav-li">CONTACT</li>
</ul>
</div>
<div class="clear"></div>
</div>
Add the following css
.nav-ul li{float:left; list-style:none;padding:0 5px;}
.nav-ul{padding:0;margin:0;}
Since this is not possible with floats, you can use display: inline-block instead. It works like a poor man's flex.
.logo-nav {
text-align: justify;
}
.logo-nav::after {
/* you can omit this by using `text-align-last` */
content: '';
width: 100%;
display: inline-block;
}
.logo {
display: inline-block;
vertical-align: middle;
text-align: left;
width: 50%;
}
.navigation {
display: inline-block;
vertical-align: bottom;
text-align: right;
width: 50%;
}
.clear {
/* this element is obsolete now */
}
Note: there must be no space between .logoand .navigation in your markup.
Are you allowed to use position absolute?
li{
float: left;
padding: 0 5px;
}
ul{
list-style: none;
position: absolute;
right: 0;
margin: 0;
bottom: 0;
}
img{
display: block;
}
.logo{
float: left;
}
.logo-nav{
background: lightblue;
position: relative;
}
.logo-nav:after{
display: block;
clear: both;
content: "";
}
<div class="logo-nav">
<div class="logo"><img src="http://placehold.it/100x50"></div>
<div class="navigation">
<ul class="nav-ul">
<li class="nav-li">OUR SPIRIT</li>
<li class="nav-li">OUR OFFER</li>
<li class="nav-li">OUR VISIONARY</li>
<li class="nav-li">CONTACT</li>
</ul>
</div>
<div class="clear"></div>
</div>
Related
In the below two screenshots, you can see the weird behavior of div.header ( parent ) and ul, li( child ) .
Due to this weird behavior, newer content(span,) in placed in the mid of the page. It's like the menu bar is not inside of header as it is supposed to be.
screenshots are below HTML and CSS codes:-
HTML:-
<body>
<div class="container">
<div class="header">
<div class="header-image"><img src="images/logo.png" alt="logo"></div>
<nav>
<ul class="left-menu">
<li> Services</li>
<li>Portfolio</li>
<li>About Us</li>
<li>Contact Us</li>
</ul>
<ul class="right-menu">
<li>+91 964941****</li>
<li>Get a Quote</li>
</ul>
</nav>
</div>
<div class="content-a">
<span>DEMO SESSIONS</span>
<h1>Get Demo Class Now</h1>
</div>
</div>
</body>
CSS:-
body{
background-color:#191C26;
color:white;
}
.header{
margin-top:20px;
}
.header-image{
width:10%;
display: inline-block;
position:relative;
top:36px;
}
.header-image img{
width:100%;
}
.left-menu, .right-menu{
list-style: none;
font-size: 200%;
}
.left-menu a, .right-menu a{
text-decoration: none;
display: inline-block;
color:white;
}
.left-menu{
float:left;
margin:0px;
margin-left:12%;
}
.left-menu li{
float:left;
}
.left-menu a{
margin-right:20px;
}
.right-menu{
float:right;
margin:0;
}
.right-menu li{
float:left;
margin-left:10px;
}
.right-menu a{
margin-left:20px;
}
2nd image:-
There are too many CSS frameworks like bootstrap, tailwind etc that can solve your problem and reduce lines of code. But if you want to create your own CSS then you can do this with flexbox and CSS grid system.
In your code adding display: inline-block; width: 100%; to your header class will fix your issue. Also use float only to main ul not li. I've made a little tweak to your code as below.
body{
background-color:#191C26;
color:white;
}
.header{
margin-top:20px;
border: 2px solid;
display: inline-block;
width: 100%;
}
.header-image{
width:10%;
display: inline-block;
position:relative;
top:36px;
}
.header-image img{
width:100%;
}
.left-menu, .right-menu{
list-style: none;
font-size: 200%;
}
.left-menu a, .right-menu a{
text-decoration: none;
display: inline-block;
color:white;
}
.left-menu{
float:left;
margin:0px;
margin-left:12%;
}
.left-menu li{
float:left;
}
.left-menu a{
margin-right:20px;
}
.right-menu{
float:right;
margin:0;
}
.right-menu li{
float:left;
margin-left:10px;
}
.right-menu a{
margin-left:20px;
}
<div class="container">
<div class="header">
<div class="header-image"><img src="images/logo.png" alt="logo"></div>
<nav>
<ul class="left-menu">
<li> Services</li>
<li>Portfolio</li>
<li>About Us</li>
<li>Contact Us</li>
</ul>
<ul class="right-menu">
<li>+91 964941****</li>
<li>Get a Quote</li>
</ul>
</nav>
</div>
<div class="content-a">
<span>DEMO SESSIONS</span>
<h1>Get Demo Class Now</h1>
</div>
<div class="content-a">
<span>DEMO SESSIONS</span>
<h1>Get Demo Class Now</h1>
</div>
</div>
I do not sure your request, but i make this, try this maybe will work for you
* {
margin: 0;
box-sizing: border-box;
}
body {
background-color: #191c26;
color: white;
}
.header {
display: flex;
justify-content: space-between;
align-items: center;
height: 10vh;
}
nav {
display: flex;
justify-content: center;
align-items: center;
margin-right: 1rem;
}
nav ul {
display: flex;
justify-content: space-between;
align-items: center;
font-size: 0.8rem;
}
nav ul li {
margin: 0 0.7rem;
list-style: none;
}
nav ul li a {
color: white;
text-decoration: none;
}
.content-a {
margin-top: 2rem;
}
<div class="header">
<div class="header-image"><img src="images/logo.png" alt="logo" /></div>
<nav>
<ul class="left-menu">
<li>Services</li>
<li>Portfolio</li>
<li>About Us</li>
<li>Contact Us</li>
</ul>
<ul class="right-menu">
<li>+91 964941****</li>
<li>Get a Quote</li>
</ul>
</nav>
</div>
<div class="content-a">
<span>DEMO SESSIONS</span>
<h1>Get Demo Class Now</h1>
</div>
I'm recreating an article I found on The Economist and I'm having trouble creating the header. Please keep in mind I'm doing this without recreating their code verbatim. I'm trying to create my own implementation.
header {
background-color: #364043;
}
.header__content {
width: 70%;
margin: auto;
}
.header__left-content {
display: inline;
width: 50%;
}
.header__nav ul {
display: inline;
}
.header__nav li {
line-height: 0px;
display: inline-block;
vertical-align: middle;
}
.header__logo {
padding-right: 25px;
}
.header__nav-link {
padding-right: 15px;
}
<html>
<body>
<header>
<div class="header__content">
<div class="header__left-content">
<div class="header__nav">
<ul>
<li class="header__logo">
<img src="http://jobs.printweek.com/getasset/2eef9541-354f-4fec-8ce2-87b008f0323d/">
</li>
<li class="header__nav-link">
Topics</li>
<li class="header__nav-link">
Print Edition
</li>
<li class="header__nav-link">
More
</li>
</ul>
</div>
</div>
<!-- <div class="header__separator"></div> -->
<div class="header__site-functions">
<p>right</p>
</div>
</div>
</header>
<div class="container"></div>
</body>
</html>
I'm having trouble getting the paragraph element, and ultimately its container to sit to the right as shown in the article.
Thoughts on this?
You can use display: flex; justify-content: space-between; on the element that wraps the the left/right portions of the header to put those in a row separated by the available space left over. And you can use align-items to align that content vertically.
header {
background-color: #364043;
}
.header__content {
width: 70%;
margin: auto;
display: flex;
justify-content: space-between;
align-items: center;
}
.header__left-content {
display: inline;
width: 50%;
}
.header__nav ul {
display: inline;
}
.header__nav li {
line-height: 0px;
display: inline-block;
vertical-align: middle;
}
.header__logo {
padding-right: 25px;
}
.header__nav-link {
padding-right: 15px;
}
<header>
<div class="header__content">
<div class="header__left-content">
<div class="header__nav">
<ul>
<li class="header__logo">
<img src="http://jobs.printweek.com/getasset/2eef9541-354f-4fec-8ce2-87b008f0323d/">
</li>
<li class="header__nav-link">
Topics</li>
<li class="header__nav-link">
Print Edition
</li>
<li class="header__nav-link">
More
</li>
</ul>
</div>
</div>
<!-- <div class="header__separator"></div> -->
<div class="header__site-functions">
<p>right</p>
</div>
</div>
</header>
<div class="container"></div>
This is happening due to your class="header__site-functions" is ablock element and is taking the 100% of the width, so it doesn't fit in a line. You can use a floating element to fix it:
header {
background-color: #364043;
}
.header__content {
width: 70%;
margin: auto;
}
.header__left-content {
display: inline-block;
width: 50%;
}
.header__nav ul {
display: inline;
}
.header__nav li {
line-height: 0px;
display: inline-block;
vertical-align: middle;
}
.header__logo {
padding-right: 25px;
}
.header__nav-link {
padding-right: 15px;
}
.header__site-functions{
float:right;
}
<html>
<body>
<header>
<div class="header__content">
<div class="header__left-content">
<div class="header__nav">
<ul>
<li class="header__logo">
<img src="http://jobs.printweek.com/getasset/2eef9541-354f-4fec-8ce2-87b008f0323d/">
</li>
<li class="header__nav-link">
Topics</li>
<li class="header__nav-link">
Print Edition
</li>
<li class="header__nav-link">
More
</li>
</ul>
</div>
</div>
<!-- <div class="header__separator"></div> -->
<div class="header__site-functions">
<p>right</p>
</div>
</div>
</header>
<div class="container"></div>
</body>
</html>
Fixed div is getting down when I give margin-top to the div below it...why?
* {
margin: 0;
padding: 0;
}
.header_bg {
width: 100%;
height: 100px;
position: fixed;
background: black
}
.container {
width: 960px;
height: auto;
margin: 0 auto
}
ul.menu {
list-style: none;
}
ul.menu li {
display: inline-block
}
ul.menu li a {
text-decoration: none;
color: white
}
.content {
margin-top: 140px
}
<div class="header_bg">
<div class="container">
<ul class="menu">
<li>Home
</li>
<li>About
</li>
<li>Service
</li>
<li>Contact
</li>
</ul>
</div>
</div>
<div class="container">
<div class="content">
/* Content Goes here*/
</div>
</div>
you need to add top:0 to your .header_bg, see more about position
* {
margin: 0;
padding: 0;
}
.header_bg {
width: 100%;
height: 100px;
position: fixed;
background: black;
top:0
}
.container {
width: 960px;
height: auto;
margin: 0 auto
}
ul.menu {
list-style: none;
}
ul.menu li {
display: inline-block
}
ul.menu li a {
text-decoration: none;
color: white
}
.content {
margin-top: 140px
}
<div class="header_bg">
<div class="container">
<ul class="menu">
<li>Home
</li>
<li>About
</li>
<li>Service
</li>
<li>Contact
</li>
</ul>
</div>
</div>
<div class="container">
<div class="content">
/* Content Goes here*/
</div>
</div>
Hello I have three columns that need a right border with a fixed height, not depending on the number of items in the column.
My code
html
<div class="col-sm-2">
<div class="footer-col">
<ul>
<li class="footer-title hidden-xs">Customer Care</li>
<li>Contact us</li>
<li>Help</li>
<li>Shipping</li>
<li>Returns</li>
<li>Size Guide</li>
</ul>
</div>
</div>
<div class="col-sm-2 hidden-xs">
<div class="footer-col">
<ul>
<li class="footer-title">About Us</li>
<li>Our Story</li>
<li>Careers</li>
</ul>
</div>
</div>
<div class="col-sm-2 hidden-xs">
<div class="footer-col">
<ul>
<li class="footer-title">Shortcuts</li>
<li>My Account</li>
<li>Store Locator</li>
<li>Gift Cards</li>
<li>Payment</li>
</ul>
</div>
</div>
.wrapper {
display: inline-block;
background-color: #000000;
width: 100%;
height: 150px;
color: #999999;
}
.col-sm-2 {
float: right;
margin: 0;
width: 32%;
display: inline-block;
height: 90%;
}
.footer-col {
float: right;
margin: 0;
width: 90%;
padding-left: 10px;
display: inline-block;
height: 90%;
}
ul {
display: inline-block;
width: 90%;
height: 100%;
border-right: 1px solid #999999;
list-style: none;
}
li a {
color: #FFFFFF;
}
https://jsfiddle.net/michaelyuen/72dc7xrd/
There are two things:
1) Set ul height to 100%
2) Set height to parent or parent's parent. In this case, it's the wrapper.
OR use table, then you have to fix width instead of height.
https://jsfiddle.net/michaelyuen/72dc7xrd/1/
.wrapper {
display: table-row;
background-color: #000000;
color: #999999;
}
.col-sm-2 {
margin: 0;
padding-left: 10px;
width: 150px;
display: table-cell;
height: 90%;
border-right: 1px solid #999999;
vertical-align: top;
}
.footer-col {
margin: 0;
width: 90%;
display: inline-block;
height: 90%;
}
ul {
display: block;
margin: 0;
padding: 0;
width: 90%;
height: 100%;
list-style: none;
}
li a {
color: #FFFFFF;
}
Try this:
<style>
.verticalLine {
border-left: thick solid #E2C4C4;
margin-top:6px;
width:5px;
height:50px;
left: 408px;
position: absolute;
}
.pull_left {
float:left;
}
.clear {
clear: both;
}
</style>
<div class="col-sm-2">
<div class="footer-col pull_left">
<ul>
<li class="footer-title hidden-xs">Customer Care</li>
<li>Contact us</li>
<li>Help</li>
<li>Shipping</li>
<li>Returns</li>
<li>Size Guide</li>
</ul>
</div>
<div class="verticalLine pull_left"></div>
</div>
<div class="clear"></div>
<div class="col-sm-2 hidden-xs">
<div class="footer-col pull_left">
<ul>
<li class="footer-title">About Us</li>
<li>Our Story</li>
<li>Careers</li>
</ul>
</div>
<div class="verticalLine pull_left"></div>
</div>
<div class="clear"></div>
<div class="col-sm-2 hidden-xs">
<div class="footer-col pull_left">
<ul>
<li class="footer-title">Shortcuts</li>
<li>My Account</li>
<li>Store Locator</li>
<li>Gift Cards</li>
<li>Payment</li>
</ul>
</div>
<div class="verticalLine"></div>
</div>
Try like this: Demo
.col .well {
margin-bottom: -99999px;
padding-bottom: 99999px;
border-right:1px solid #ddd !important;
}
.col-wrap {
overflow: hidden;
}
.well {
min-height:20px;
padding:19px;
margin-bottom:20px;
background:transparent !important;
border-right:1px solid #e3e3e3 !important;
border:none !important;
box-shadow:none !important;
}
HTML:
<div class="container">
<div class="row col-wrap">
<div class="col-sm-2 col">
<div class="footer-col well">
....
</div>
</div>
<div class="col-sm-2 hidden-xs col">
<div class="footer-col well">
....
</div>
</div>
<div class="col-sm-2 hidden-xs col">
<div class="footer-col well">
....
</div>
</div>
</div>
</div>
Try this Create a outer container and apply overflow: hidden and apply margin and padding to the bottom
http://www.bootply.com/YNUeK8I29h
You can use after/before pseudo selectors.
http://jsfiddle.net/s7w4sqLd/
.footer-col ul:after {
position:absolute;
content:" ";
left:0;
top:0;
width:100%;
height:50px;
border-right: solid 1px #2a343f;
}
.footer-col ul{
position:relative;
float:left;
padding-right:10px;
}
.footer-col ul li {
list-style:none;
}
i created a navigation bar, and while hovering i made the font larger.
but when i hover the other menu items seem to move from its position , how do i lock them in their position. Also, just started html and css, if anyone would help me, thank you :)
html:
<div class="header">
<div class="container">
<div class="header-left">
<a href="index.php">
<img src="images/hawa.png" style="width:200px;height:60px;">
</a></div>
<div class="header-right">
<ul>
<li>Home</li>
<li>About</li>
<li>Services</li>
<li>Contact Us</li>
<li>Sign Up</li>
</ul>
</div>
</div>
<div class="clear"></div>
</div>
CSS:
.header{
background-color: #003399;
width: 100%;
height: 83px;
position: fixed;
}
.container{
width:1200px;
background-color:#003399;
margin:auto;
height:83px;
}
.header-left{
float:left;
padding: 10px;
}
.header-right{
float:right;
width:900px;
height:83px;
}
.header-right ul{
margin: 0;
padding: 0;
}
.header-right li{
list-style: none;
}
.header-right li a{
text-decoration: none;
float:left;
display: block;
padding: 35px;
color:#FFFFFF;
text-transform: uppercase;
font-size: 18px;
font-family: sans-serif;
}
.header-right li a:hover{
font-size: 20px;
display: block;
}
You can add a class on your list items and set the width for these items. For example:
html:
<ul>
<li class="nav-cells">Home</li>
<li class="nav-cells">About</li>
<li class="nav-cells">Services</li>
<li class="nav-cells">Contact Us</li>
<li class="nav-cells">Sign Up</li>
</ul>
css:
.nav-cells {
width: 100px;
display: inline;
}