Tried to google this but didn't find anything that helped me.
So I have button-text on the left and right but I want to center an image inside the top bar.
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f3f3f3;
}
li {
float: left;
}
li a {
display: block;
color: #666;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover:not(.active) {
background-color: #ddd;
}
li a.active {
color: white;
background-color: #3744a2;
}
<ul>
<li>home</li>
<li>news</li>
<li>services</li>
<li><a class="active" href="#">prices</a></li>
<li>contat</li>
<li><a class="image" href="#"><img src="https://dummyimage.com/150X38/000/fff"></a></li>
<li style="float:right"><i class="fa fa-envelope" aria-hidden="true"></i> enter#email.here</li>
<li style="float:right"><i class="fa fa-phone" aria-hidden="true"></i> 123 123 123</li>
</ul>
so what I basicly want is the image (class="image") to be centered, but the rest as it is.
Thanks alot!
Do it like this
Remove image class from a tag and give image class to it's parent li and try this with this example. it will helps you
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f3f3f3;
text-align: center;
}
li {
float: left;
}
li a {
display: block;
color: #666;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover:not(.active) {
background-color: #ddd;
}
li a.active {
color: white;
background-color: #3744a2;
}
li.image {
float: none;
display: inline-block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul>
<li>home</li>
<li>news</li>
<li>services</li>
<li><a class="active" href="#">prices</a></li>
<li>contat</li>
<li class='image'><a class="" href="#"><img src="../image/image.png"></a></li>
<li style="float:right"><i class="fa fa-envelope" aria-hidden="true"></i> enter#email.here</li>
<li style="float:right"><i class="fa fa-phone" aria-hidden="true"></i> 123 123 123</li>
</ul>
a.image {
display: block;
margin-left: auto;
margin-right: auto
}
try adding that code in your css file . Also try have a look here
it has more info about centering things .
I used display:flex and flex property. by setting display: flex:0 I'm telling the browser I want this element take just the place he need, and with flex:1 on a single element I'm telling that I want it to take all the possible place
div.nav {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f3f3f3;
display: flex;
}
div.left-part, div.right-part {
flex: 0;
display:inline-block;
white-space: nowrap;
}
div.center-part {
flex: 1;
text-align: center;
}
div.nav-button {
display:inline-block;
}
div.nav-button a {
display: block;
color: #666;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
div.nav-button a:hover:not(.active) {
background-color: #ddd;
}
div.nav-button a.active {
color: white;
background-color: #3744a2;
}
<div class="nav">
<div class="left-part"><div class="nav-button">home</div>
<div class="nav-button">news</div>
<div class="nav-button">services</div>
<div class="nav-button"><a class="active" href="#">prices</a></div>
<div class="nav-button">contat</div>
</div>
<div class="center-part">
<div class="nav-button"><a class="image" href="#"><img src="../image/image.png"></a></div>
</div>
<div class="right-part">
<div class="nav-button"><i class="fa fa-envelope" aria-hidden="true"></i> enter#email.here</div>
<div class="nav-button"><i class="fa fa-phone" aria-hidden="true"></i> 123 123 123</div>
</div>
</div>
Related
I want to create a webpage like this.So far I have written a code in html and css like this but I cannot align the top nav bar above the nav-menu items?
HTML
<body>
<div class="top-header">
<div class="header">
<div class="logo">
<div class="logo-left">
<img src="images/logo.jpg" alt="logo-truck">
</div>
<div class="logo-right">
<h3>kuncham</h3>
<p>logistic service</p>
</div>
</div>
<div class="top-bar">
<div class="top-bar__content">
<div class="top-bar-content">call:(007)123-456-7890</div>
<div class="top-bar-content">email:enquiry#domain.com</div>
<div class="top-bar-content">mon-sun:12pm to 12am</div>
<div class="top-bar-content">
<i class="fa fa-twitter"></i>
<i class="fa fa-facebook"></i>
<i class="fa fa-linkedin"></i>
<i class="fa fa-google-plus"></i></div>
</div>
</div>
<ul class="nav__nav-bar">
<li><a class="active" href="#home">Home</a></li>
<li>about us</li>
<li>services</li>
<li>news</li>
<li>request a quote</li>
<li>contact us</li>
<li>track your item</li>
</ul>
</div>
</body>
CSS
-------------------------------------------------------------------------------------------------------
.nav__nav-bar {
flex-direction: row;
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: white;
color: black;
font-weight: bold;
margin-top: -102px;
margin-left: 184px;
}
.nav__nav-bar li {
float: left;
}
.nav__nav-bar li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
color:black;
font-weight:bold;
text-transform: uppercase;
}
.nav__nav-bar li a:hover {
background-color: yellow;
}
.top-bar__content{
display:inline-block;
}
.top-header {
border:2px solid black;
background-color: black;
}
.header {
background-color: #fff;
height: 80px;
width: 90%;
}
.logo {
padding: 17px;
}
.logo .logo-left {
float: left;
font-size:50px;
color: darkorange;
padding-right: 5px;
}
.logo .logo-right h3 {
padding: 0;
margin: 0;
font-family: serif;
}
.logo .logo-right p {
line-height: 0;
}
.top-bar {
border: 2px solid red;
display: inline-grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
width: 76%;
margin-left: 280px;
height: 52px;
margin-top: -100px;
}
.top-bar-content{
display:inline;
}
The top-nav bar is not getting aligned at the top.I tried using flex but it does not work properly. Also the menu items are not aligned properly.Can anyone help me regarding this issue?
Codepen
<div class="top-header">
<div class="header">
<div class="logo">
<div class="logo-left">
<img src="images/logo.jpg" alt="logo-truck">
</div>
<div class="logo-right">
<h3>kuncham</h3>
<p>logistic service</p>
</div>
</div>
<div class="header-right">
<div class="top-bar">
<div class="top-bar__content">
<div class="top-bar-content">call:(007)123-456-7890</div>
<div class="top-bar-content">email:enquiry#domain.com</div>
<div class="top-bar-content">mon-sun:12pm to 12am</div>
<div class="top-bar-content">
<i class="fa fa-twitter"></i>
<i class="fa fa-facebook"></i>
<i class="fa fa-linkedin"></i>
<i class="fa fa-google-plus"></i></div>
</div>
</div>
<ul class="nav__nav-bar">
<li><a class="active" href="#home">Home</a></li>
<li>about us</li>
<li>services</li>
<li>news</li>
<li>request a quote</li>
<li>contact us</li>
<li>track your item</li>
</ul>
</div>
</div>
`.top-header {
border: 2px solid black;
background: black;
}
.header {
background: white;
height: 80px;
width: 100%;
display: flex;
}
.logo {
padding: 0 17px;
flex: 0 0 400px;
align-self: center;
}
.header-right {
flex: auto;
padding: 0 0 0 20px;
}
.top-bar {
background: #000000;
color: white;
padding: 8px 18px;
border-radius: 0 0 0 8px;
}
.nav__nav-bar {
margin: 0;
float: none;
list-style: none;
text-align: right;
display: flex;
padding: 0;
}
.top-bar__content {
display: flex;
}
.top-bar-content {
padding: 0 16px 0 0;
}
.nav__nav-bar li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
color: black;
font-weight: bold;
text-transform: uppercase;
}
.nav__nav-bar li a:hover {
background: yellow;
}
.logo .logo-left {
float: left;
font-size:50px;
color: darkorange;
padding-right: 5px;
}
.logo .logo-right h3 {
padding: 0;
margin: 0;
font-family: serif;
}
.logo .logo-right p {
line-height: 0;
}`
[https://codepen.io/kinjalpatel2207/pen/MWwapLz][1]
I would like to make the same menu as on https://www.w3schools.com/css/tryit.asp?filename=trycss_dropdown_navbar.
However I would like to genereated the menu in the cshtml file here is what my menu looks like so far.
Here is my modified css
.main-menu {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
display: flex;
}
.parent-menu {
float: left;
}
li a, .menu-dropbtn {
display: inline-block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.parent-menu a:hover, .menu-li-dropdown:hover .menu-dropbtn {
background-color: red;
text-decoration: none;
}
li.menu-li-dropdown {
display: inline-block;
}
.dropdown-menu-content {
clear: both;
display: none;
position: absolute;
background-color: #f9f9f9;
text-decoration: none;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-menu-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-menu-content a:hover {
background-color: #f1f1f1;
}
.menu-li-dropdown:hover .dropdown-menu-content {
display: block;
}
Here is how I generate the html
#helper GetTreeMenus(IEnumerable<erp_colombia.Models.MenuMaster> siteMenu, Nullable<int> parentID)
{
foreach (var i in siteMenu.Where(a => a.ParentID.Equals(parentID)))
{
var submenu = siteMenu.Where(a => a.ParentID.Equals(i.MenuID)).Count();
string action = i.ActionName;
string controller = i.ControllerName;
<ul class="treeview-menu">
<li class="treeview">
<a href="/#i.ControllerName/#i.ActionName">
#i.MenuText
</a>
</li>
#GetTreeMenus(siteMenu, i.MenuID)
</ul>
}
}
#{
if (Session["MenuList"] != null)
{
<ul class="main-menu">
#GetTreeMenus(Session["MenuList"] as IEnumerable<erp_colombia.Models.MenuMaster>, 0)
</ul>
}
}
And here is part of my generated html.
<ul class="main-menu">
<ul class="treeview-menu">
<li class="treeview">
<a href="/Acceuil/Index">
Menú principal
</a>
</li>
</ul>
<ul class="treeview-menu">
<li class="treeview">
<a href="//">
Técnico
</a>
</li>
<ul class="treeview-menu">
<li class="treeview">
<a href="//">
Modulo técnico
</a>
</li>
</ul>
<ul class="treeview-menu">
<li class="treeview">
<a href="//">
Contrato técnico
</a>
</li>
</ul>
What must I change in my css or cshtml to obtain the same result as on w3school.Thank you for your help.
Excuse me, I didn't understand your question but now that I read It twice I do, try to add display: flex to your main-menu class:
.main-menu {
display: flex;
}
This should put the main-menu's li all in a row, Let me know if this works...
Use the following CSS as it is in W3Schools
<style>
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li {
float: left;
}
li a, .dropbtn {
display: inline-block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover, .dropdown:hover .dropbtn {
background-color: red;
}
li.dropdown {
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {background-color: #f1f1f1;}
.dropdown:hover .dropdown-content {
display: block;
}
</style>
Here i altered you html as below
<ul>
<li class="dropdown">
Test1
<div class="dropdown-content">
Menú principal
</div>
</li>
<li class="dropdown">
Test2
<div class="dropdown-content">
Técnico
</div>
</li>
<li class="dropdown">
Test3
<div class="dropdown-content">
Modulo técnico
</div>
</li>
<li class="dropdown">
Test4
<div class="dropdown-content">
Contrato técnico
</div>
</li>
</ul>
To do the over effect You can do It without javascript, this example is pretty unstiled so don't look at that you can adjust It after:
/*Put grey background and put all parents divs in a row*/
.main-menu {
display: flex;
background: #ccc;
}
.main-menu div a {
margin: 20px;
}
.main-menu div div p {
margin: 20px 0 20px 30px;
}
/*Hide the children divs*/
.main-menu div div {
display: none;
}
.main-menu div:hover div {
display: block;
}
<div class="main-menu">
<div>
Fruits
<div id="fruits">
<p>Apple</p>
<p>Mango</p>
<p>Orange</p>
</div>
</div>
<div>
vegetables
<div id="vegetables">
<p>Gabbage</p>
<p>Tomatoes</p>
</div>
</div>
</div>
I realize that this question was asked before by different posters, but I tried a lot of suggested answers and none of them seemed to work.
When inputting my logo into the NavBar, it keeps expanding. However, the <li class="logo"> slot is reserved in the navbar, as the left class does leave room, but only as much as their designated 8% width not 40%.
ul.navbar {
width: 100%;
height: 50px;
line-height: 50px;
list-style-type: none;
padding: 0;
background-color: #5D6576;
opacity: 0.8;
border: none;
}
li.logo {
float: left;
width: 40%;
}
li.left {
float: left;
color: white;
width: 8%;
}
li.left a {
display: block;
color: white;
text-align: center;
text-decoration: none;
}
li a:hover {
background-color: #BC80BB;
transition: 1s;
}
li.right {
float: right;
width: 4%;
}
<ul class="navbar">
<li class="logo"><img src="static/logo.png" alt="Logo"></li>
<li class="left">Home</li>
<li class="left">*** Website</li>
<li class="right"><i class="fa fa-fw fa-envelope"></i></li>
<li class="right"><i class="fa fa-fw fa-phone"></i></li>
</ul>
Extremely expanding logo:
Showing the reserved spot:
Here i am sending you code as well as link. Please check it. If any changes then let me know.
https://jsfiddle.net/np6tzxyd/16/
.header-menu {
display: flex;
background-color: #5D6576;
opacity: 0.8;
width: 100%;
height: 50px;
line-height: 50px;
align-items: center;
justify-content: space-between;
}
.navbar-left,
.navbar-right {
display: flex;
list-style-type: none;
padding: 0;
border: none;
}
.navbar-left li,
.navbar-right li {
padding-right: 15px
}
.navbar-left li a:hover,
.navbar-right li a:hover {
color: #fff;
}
.logo {
display: block;
padding-right: 20px;
}
.logo-menu{
display: flex;
align-items: center;
}
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="header-menu">
<div class="logo-menu">
<a class="logo"><img src="static/logo.png" alt="Logo"></a>
<ul class="navbar-left">
<li>Home</li>
<li>*** Website</li>
</ul>
</div>
<ul class="navbar-right">
<li><i class="fa fa-fw fa-envelope"></i></li>
<li><i class="fa fa-fw fa-phone"></i></li>
</ul>
</div>
Following #Revti Shah answer to prevent jumping outside the nav you need to add this
overflow: hidden;
in your code
ul.navbar
or in her code
header-menu
1.) When the screen is made smaller, the nav bar is not responding to being stacked on top of one another as it should do, Image shown below of what a phone screen size roughly looks like:
2.) Another thing is that the menu nav bar is not stretching to the very end of the screen, I have tried to place it 100% width, please can someone give me any advice?
<header>
<div class="row">
<div class="grid-6">
<div class="navbar">
<a class="active" href="home.php"><i class="fas fa-home"></i> Home</a>
<i class="fas fa-images"></i> Gallery
<div class="dropdown">
<button class="dropbtn"><i class="fas fa-award"></i> Competitions</button>
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</div>
<i class="fas fa-blog"></i> Blog
<i class="fas fa-envelope"></i> Contact
<i class="fas fa-check-square"></i> Signup
<i class="fas fa-sign-in-alt"></i> Login
<i class="fas fa-sign-out-alt"></i> Logout
</div>
</div>
</div>
</header>
CSS:
/* Add responsiveness - will automatically display the navbar vertically instead of horizontally on screens less than 500 pixels */
#media screen and (max-width: 500px) {
.navbar a {
float: none;
display: block;
}
}
.navbar {
width: 100%;
background-color: #555;
overflow: auto;
}
.navbar a {
float: left;
font-size: 16px;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.dropdown {
float: left;
overflow: hidden;
}
.dropdown .dropbtn {
font-size: 16px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font-family: inherit;
margin: 0;
}
.navbar a:hover, .dropdown:hover .dropbtn {
background-color: red;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {
background-color: #ddd;
}
.dropdown:hover .dropdown-content {
display: block;
}
You'll have to declare the media queries at the bottom of the css file in order to ensure smooth cascading of the styles.
Solution below.
.navbar {
width: 100%;
background-color: #555;
overflow: auto;
}
.navbar a {
float: left;
font-size: 16px;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.dropdown {
float: left;
overflow: hidden;
}
.dropdown .dropbtn {
font-size: 16px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font-family: inherit;
margin: 0;
}
.navbar a:hover,
.dropdown:hover .dropbtn {
background-color: red;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}
.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {
background-color: #ddd;
}
.dropdown:hover .dropdown-content {
display: block;
}
/* Add responsiveness - will automatically display the navbar vertically instead of horizontally on screens less than 500 pixels */
#media only screen and (max-width: 500px) {
.navbar a,
.dropdown {
float: none;
display: block;
text-align: center;
}
}
<header>
<div class="row">
<div class="grid-6">
<div class="navbar">
<a class="active" href="home.php"><i class="fas fa-home"></i> Home</a>
<i class="fas fa-images"></i> Gallery
<div class="dropdown">
<button class="dropbtn"><i class="fas fa-award"></i> Competitions</button>
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</div>
<i class="fas fa-blog"></i> Blog
<i class="fas fa-envelope"></i> Contact
<i class="fas fa-check-square"></i> Signup
<i class="fas fa-sign-in-alt"></i> Login
<i class="fas fa-sign-out-alt"></i> Logout
</div>
</div>
</div>
</header>
link to jsFiddle
When I zoom in my page, all the elements go to left side, they are not collapsed but i want the web page to be on center when I zoom. I have made a container class and added a margin:auto to it bu it does not change anymore. Hope somebody answer it exactly.
#font-face {
font-family: irsans;
src:url('../fonts/irsans.woff2');
}
body{
margin:0;
}
.container{
margin:0 auto;
max-width:100%; /* requierd width */
background:red;
}
header {
width: 100%;
margin: auto;
height: 150px;
background-color: #FCFCFC;
}
.topnav{
position: absolute;
left: 334px;
top: 2px;
width: 552px;
height: 18px;
display: inline-block;
}
.topnav_items a{
margin: 2px;
font-size: 11px;
font-family: irsans;
color: #333;
float: left;
list-style: none;
padding: 0 5px;
}
.topnav_items li a:hover, .topnav_items li a:active {
text-decoration: none;
color: #8B9498;
}
<div class="container">
<header>
<div class="topnav">
<ul class="topnav_items">
<li class="fa fa-envelope-o" style="font-size:11px;">ارتباط با برنامه</li>
<li class="fa fa-bar-chart" style="font-size:11px;">پیش بینی مسابقات</li>
<li class="fa fa-desktop" style="font-size:11px;">تبلیغات</li>
<li class="fa fa-download" style="font-size:11px;">نرم افزار مسابقات پیامکی 90</li>
</ul>
</div>
</header>
</div>
Put your container(better call it wrapper) insidw the header.
Give the Container a fixed with using the with of ur topnav.
put margin to margin: 0 auto;
tkae out all atribute related to position: absolut from ur topnav.
(If ur not happ with the result u can also try to give container a relative with. For example with: 50% margin: 0 25%;)
<header>
<div class="container">
<div class="topnav">
<ul class="topnav_items">
<li class="fa fa-envelope-o" style="font-size:11px;">ارتباط با برنامه</li>
<li class="fa fa-bar-chart" style="font-size:11px;">پیش بینی مسابقات</li>
<li class="fa fa-desktop" style="font-size:11px;">تبلیغات</li>
<li class="fa fa-download" style="font-size:11px;">نرم افزار مسابقات پیامکی 90</li>
</ul>
</div>
</div>
</header>
#font-face {
font-family: irsans;
src:url('../fonts/irsans.woff2');
}
body{
margin:0;
}
.container {
margin: 0 25%;
max-width: 552px;
}
header {
width: 100%;
margin: auto;
height: 150px;
background-color: #FCFCFC;
}
.topnav {
width: 100%;
height: 18px;
display: inline-block;
}
.topnav_items a{
margin: 2px;
font-size: 11px;
font-family: irsans;
color: #333;
float: left;
list-style: none;
padding: 0 5px;
}
.topnav_items li a:hover, .topnav_items li a:active {
text-decoration: none;
color: #8B9498;
}