.header {
background-color: yellow;
font-family: 'Arial';
display: inline-block;
}
.leftheader{
float: left;
}
#Logo{
font-size: 40px;
font-weight: 700;
display: inline-block;
}
#LogoLTD{
font-size: 20px;
display: inline-block;
}
.rightheader{
display: flex;
float: right;
}
.rightheader a{
color: black;
font-size: 20px;
font-weight: 700;
text-decoration: none;
}
<section class="header">
<div class="leftheader">
<div id="Logo">COMPANY NAME</div>
<div id="LogoLTD">LIMITED</div>
</div>
<div class="rightheader">
HOME
WHO
CONTACT
</div>
</section>
I have been trying to make a header for my site but I can't get the aligning right.
I want to have my links on the right of the page inside the yellow box.
The yellow colour should be inside the header class.
Then the leftheader div and the rightheader div should be inside the header class. And they should be positioned on the left and right but I cannot get this to work whatever I do :(
My HTML is:
<section class="header">
<div class="leftheader">
<div id="Logo">COMPANY NAME</div>
<div id="LogoLTD">LIMITED</div>
</div>
<div class="rightheader">
HOME
WHO
CONTACT
</div>
</section>
My CSS is:
.header {
background-color: yellow;
font-family: 'Arial';
display: inline-block;
}
.leftheader{
float: left;
}
#Logo{
font-size: 40px;
font-weight: 700;
display: inline-block;
}
#LogoLTD{
font-size: 20px;
display: inline-block;
}
.rightheader{
display: flex;
float: right;
}
.rightheader a{
color: black;
font-size: 20px;
font-weight: 700;
text-decoration: none;
}
You can do that using flex. Check out the code below.
.header {
background-color: yellow;
font-family: 'Arial';
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
}
.leftheader{
display: flex;
align-items: flex-end;
}
#Logo{
font-size: 40px;
font-weight: 700;
display: inline-block;
}
#LogoLTD{
font-size: 20px;
display: inline-block;
padding-bottom: 5px;
}
.rightheader{
display: flex;
}
.rightheader a{
color: black;
font-size: 20px;
font-weight: 700;
text-decoration: none;
}
<section class="header">
<div class="leftheader">
<div id="Logo">COMPANY NAME</div>
<div id="LogoLTD">LIMITED</div>
</div>
<div class="rightheader">
HOME
WHO
CONTACT
</div>
</section>
Just add width: 100% to your header, things will look more like you want them:
.header {
background-color: yellow;
font-family: 'Arial';
display: inline-block;
width: 100%;
}
This should do the work.
.header {
display: flex;
flex-wrap: wrap;
background: yellow;
padding: 8px;
}
.leftheader {
display: inline-block;
color: red;
width: 60%;
}
.rightheader {
display: inline-block;
width: 40%;
text-align: right;
}
Related
So for one of my school projects, we have to design a website using Html & CSS and I've encountered a problem where I don't know how to fit 2 logos (left & right) into the corners of my footer. I've tried to change the position, float, width etc and it doesn't seem to work, the logo always seems to not go in the place I want it to be. Sorry if this sounds amateur as I've only started doing Html & CSS a few weeks ago.
This is the current image where the logo is below my ul's and is in the incorrect position. -
This is what I want the footer to look like, it would be great to have the text on the left "Sponsored by HP omen gaming" to be a image as I may swap it out with another logo in the future. -
Thanks to anyone in advance who may be able to solve this problem for me, below would be my html & CSS code.
.footer {
background-color: #035642;
margin-top: 10px;
height: 60px;
color: #efe5d0;
text-align: center;
padding: 15px;
font-size: 100%;
font-family: Arial;
display: block;
}
.footer ul {
padding: 5px;
list-style-type: none;
text-align: center;
margin: 10px;
overflow: hidden;
}
.footer li {
text-decoration: none;
text-align: center;
font-family: arial;
font-weight: bold;
list-style-type: none;
display: inline-block;
}
.footer ul li {
display: inline-block;
}
.footer ul li a {
text-decoration: none;
padding: .2em 1em;
color: #efe5d0;
background-color: #5c755e;
text-align: center;
font-family: arial;
font-weight: bold;
}
.footer ul li a:hover {
color: #000;
background-color: #fff;
}
#footer-right {
height: 50px;
width: auto;
position: fixed;
float: right;
}
<div class="footer">
<li>WBHS ESPORTS</li>
<ul>
<li>Facebook</li>
<li>|</li>
<li>YouTube</li>
<li>|</li>
<li>Twitch</li>
</ul>
<img src="hp-omen-logo.png" id="footer-right">
</div>
Try look into flexbox. Here's a quick template to do what you want.
.footer {
display: flex;
justify-content: space-between;
}
.center {
text-align: center;
}
<div class="footer">
<p>Left</p>
<div class="center">
<p>Some text</p>
<p>Your list</p>
</div>
<p>Right</p>
</div>
I think a solution can be the use of display:flex
And to be more clean try to use also the widgets, you can see in this example how it works.
.footer {
background-color: #035642;
margin-top: 10px;
height: 60px;
color: #efe5d0;
text-align: center;
padding: 15px;
font-size: 100%;
font-family: Arial;
display: block;
}
.footer ul {
padding: 5px;
list-style-type: none;
text-align: center;
margin: 10px;
overflow: hidden;
}
.footer li {
text-decoration: none;
text-align: center;
font-family: arial;
font-weight: bold;
list-style-type: none;
display: inline-block;
}
.footer ul li {
display: inline-block;
}
.footer ul li a {
text-decoration: none;
padding: .2em 1em;
color: #efe5d0;
background-color: #5c755e;
text-align: center;
font-family: arial;
font-weight: bold;
}
.footer ul li a:hover {
color: #000;
background-color: #fff;
}
#footer-right {
height: 50px;
width: auto;
position: fixed;
float: right;
}
/*my-edit*/
#the-footer{
display:flex;
flex-wrap:wrap;
justify-content:space-between;
align-items:center;
height: auto;
margin: 0;
padding: 10px;
}
#the-footer .widget{
width: 30%;
}
#the-footer .widget.left{
text-align: left;
}
#the-footer .widget.right{
text-align: right;
}
#the-footer .widget.center{
text-align: center;
}
#the-footer .widget .title{
font-weight: bold;
letter-spacing: 2px;
}
#the-footer .widget .logo-link{
color:#fff;
display: inline-block;
text-decoration: none;
max-width:150px;
}
#the-footer .widget .logo-link:hover{
color:#000;
}
<div class="footer" id="the-footer">
<div class="widget left">
<a class="logo-link" href="#" target="_blank">Sponsored by HP omen gaming</a>
</div>
<div class="widget center">
<div class="title">WBHS ESPORTS</div>
<ul class="footer-nav">
<li>Facebook</li>
<li>|</li>
<li>YouTube</li>
<li>|</li>
<li>Twitch</li>
</ul>
</div>
<div class="widget right">
<a class="logo-link" href="#" target="_blank"><img class="logo-footer" src="https://via.placeholder.com/60" alt="logo"></a>
</div>
</div>
You can use the display: grid property so you can separate your footer into 3 parts
You can learn about the grid property here: https://www.w3schools.com/css/css_grid.asp
I am a beginner, and I am trying to get this to work.
How do I position the link to the right side of the connect text?
I want the text links to be inline but to the right.
.footer {
grid-area: footer;
margin-top: 38px;
margin-left: 100px;
margin-right: 100px;
height: 700px;
}
.footer-text {
padding: 200px 100px;
font-family: "Khula", sans-serif;
font-size: 80px;
color: #222222;
}
.footer-contact {
font-family: "Khula", sans-serif;
font-size: 35px;
color: #222222;
letter-spacing: -1px;
text-decoration: none;
padding: 100px 60px;
}
ul {
list-style-type: none;
text-decoration: none;
}
<div class="footer-text">Contact</div>
<ul>
<li>Email</li>
<li>LinkedIn</li>
<li>Instagram</li>
</ul>
You can add this to the .footer-text:
display:flex;
justify-content: right;
Note that this will apply to all childs of the .footer-text div.
Please update this two class properties as like the following code:
.footer-text {
padding: 200px 100px;
font-family: "Khula", sans-serif;
font-size: 80px;
color: #222222;
display: inline-block;
}
ul {
list-style-type: none;
text-decoration: none;
display: inline-block;
}
This can be solved easily by using a wrapper div. like so,
.wrapper {
overflow: auto;
}
.footer-text {
float: left;
}
.ul {
float: right;
}
<div class="wrapper">
<div class="footer-text">Contact</div>
<ul class="ul">
<li>Email</li>
<li>LinkedIn</li>
<li>Instagram</li>
</ul>
</div>
This is my Css code. I cant get my css to float the nav to the right. Any way on doing that? I attempted to use float: right; but that didn't work.
My HTML just has a header with a list holding my site navigation.
Here is my HTML if you need it as well:
body {
font-family: 'Calistoga', cursive;
background-color: #F5E9DF;
margin: 0 auto;
}
/* header */
header {
display: flex;
align-items: center;
color: #F5E9DF;
background-color: #1F2020;
height: 100px;
}
.logo {
margin-left: 20px;
margin-right: 20px;
align-items: center;
}
h1 {
text-align: center;
}
/* sitenavigation */
nav.sitenavigation {
color: #F5E9DF;
text-align: center;
}
nav.sitenavigation li {
display: inline;
color: #F5E9DF;
margin: 0.3em 0.5em;
font-size: 18px;
}
nav.sitenavigation a:link {
text-decoration: none;
color: #F5E9DF;
}
nav.sitenavigation a:visited {
color: #F5E9DF;
}
nav.sitenavigation a:hover,
nav.sitenavigation a:focus {
color: #CC422B;
}
<link href="https://fonts.googleapis.com/css?family=Calistoga&display=swap" rel="stylesheet">
<header>
<img class="logo" src="images/logo.png" width="50" height="50" alt="100">
<h1 id="title">Rust Raiding Calculator</h1>
<nav class="sitenavigation">
<ul>
<li>Home</li>
<li>Raid Calculator</li>
<li>Contact Us/Feedback</li>
</ul>
</nav>
</header>
Add margin-left: auto to the child item .sitenavigation to automatically push the element to the right. I prefer to avoid floats rules when approaching template decisions.
body {
font-family: 'Calistoga', cursive;
background-color: #F5E9DF;
margin: 0 auto;
}
/* header */
header {
display: flex;
align-items: center;
color: #F5E9DF;
background-color: #1F2020;
height: 100px;
}
.logo {
margin-left: 20px;
margin-right: 20px;
align-items: center;
}
h1 {
text-align: center;
}
/* sitenavigation */
nav.sitenavigation {
margin-left: auto;
color: #F5E9DF;
text-align: center;
}
nav.sitenavigation li {
display: inline;
color: #F5E9DF;
margin: 0.3em 0.5em;
font-size: 18px;
}
nav.sitenavigation a:link {
text-decoration: none;
color: #F5E9DF;
}
nav.sitenavigation a:visited {
color: #F5E9DF;
}
nav.sitenavigation a:hover,
nav.sitenavigation a:focus {
color: #CC422B;
}
<link href="https://fonts.googleapis.com/css?family=Calistoga&display=swap" rel="stylesheet">
<header>
<img class="logo" src="images/logo.png" width="50" height="50" alt="100">
<h1 id="title">Rust Raiding Calculator</h1>
<nav class="sitenavigation">
<ul>
<li>Home</li>
<li>Raid Calculator</li>
<li>Contact Us/Feedback</li>
</ul>
</nav>
</header>
nav.sitenavigation {
color: #F5E9DF;
text-align: right;
width: 65%;
}
You can change width according to media query.
Replace your css Code for nav.sitenavigation class.
nav.sitenavigation {
color: #F5E9DF;
width: calc(100% - 31%);
float: right;
text-align: right;
}
I want my navigation to be under my 'Acme Web Design' header whenever I view it on a mobile device. All my elements are positioned in the correct place for a laptop screen but when I check if it is responsive, they don't position at the place where I want them to be.
Here is what my header looks like in a responsive view.
This is the HTML and CSS file i used.
.headerdiv {
display: flex;
justify-content: space-between;
align-items: flex-end;
}
/* Header */
header{
background-color: #35424a;
border-bottom: 2px solid #ff6600;
color: white;
padding-top: 30px;
min-height: 70px;
}
nav {
float: right;
margin-bottom: 30px ;
}
nav a {
color: white;
text-decoration: none;
padding: 10px;
}
<header>
<div class="container">
<div class="headerdiv">
<h1>Acme Web Design</h1>
<nav>
HOME
ABOUT
SERVICES
</nav>
</div>
</div>
</header>
This is what I want my header to look like
I guess this is what you were trying to achieve. Here is the working Codepen Link
body {
font-family: sans-serif;
}
.headerdiv {
display: flex;
justify-content: space-between;
flex-direction: column;
align-items: center;
}
.headerdiv h1 {
margin-bottom: 20px;
font-size: 32px;
font-weight: bold;
}
.headerdiv h1 span {
color: #e7491c;
}
/* Header */
header {
background-color: #35424a;
border-bottom: 2px solid #ff6600;
color: white;
padding-top: 30px;
min-height: 70px;
}
nav {
margin-bottom: 30px;
}
nav a {
color: white;
text-decoration: none;
padding: 10px;
font-size: 20px;
font-weight: bold;
}
nav a.active {
color: #e7491c;
}
<header>
<div class="container">
<div class="headerdiv">
<h1><span>Acme</span> Web Design</h1>
<nav>
HOME
ABOUT
SERVICES
</nav>
</div>
</div>
</header>
Change your flex settings for the container as follows (especially flex-direction: column;), use text-align: center for the child elements of .headerdiv to center them and delete the floats to include all elements in the parent element/background
Oh, and put those extra rules in a media query to leave your desktop view untouched - the snippet below only shows the mobile view, no media queries (since you didn't have any in your code)
headerdiv {
display: flex;
flex-direction: column;
}
.headerdiv>* {
text-align: center;
}
/* Header */
header {
background-color: #35424a;
border-bottom: 2px solid #ff6600;
color: white;
padding-top: 30px;
min-height: 70px;
}
nav {
margin-bottom: 30px;
}
nav a {
color: white;
text-decoration: none;
padding: 10px;
}
<body>
<header>
<div class="container">
<div class="headerdiv">
<h1>Acme Web Design</h1>
<nav>
HOME
ABOUT
SERVICES
</nav>
</div>
</div>
</header>
Change your css property of class .headerdiv and remove nav class.
.headerdiv {
text-align: center;
margin-bottom: 30px;
}
/* Header */
header {
background-color: #35424a;
border-bottom: 2px solid #ff6600;
color: white;
padding-top: 30px;
min-height: 70px;
}
nav a {
color: white;
text-decoration: none;
padding: 10px;
}
try this.. you will get same result in any device.
if you want to increase the size of the menu u can do that using font-size..
headerdiv {
display: flex;
justify-content: space-between;
align-items: flex-end;
}
/* Header */
header{
background-color: #35424a;
border-bottom: 2px solid #ff6600;
color: white;
padding-top: 8px;
min-height: 70px;
}
nav {
/* float: right; */
text-align: center;
margin-bottom: 30px ;
}
nav a {
color: white;
text-decoration: none;
padding: 10px;
}
<header>
<div class="container">
<div class="headerdiv">
<div>
<h1 style="text-align: center;">Acme Web Design</h1>
</div>
<div>
<nav>
HOME
ABOUT
SERVICES
</nav>
</div>
</div>
</div>
</header>
I'm having some trouble making a nav menu and its sub menu to display via the pseudo checkbox toggle. I looked at some guides and tried some, but I'm not getting the result I wanted -- the menus does not appear when toggle the checkbox on.
https://codepen.io/UnorthodoxThing/pen/paMBQB
HTML
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="utf-8">
<title>Natural Pasta</title>
<link rel="stylesheet" type="text/css" href="style-index.css">
<link href="https://fonts.googleapis.com/css?family=Amatic+SC|Gloria+Hallelujah|Gorditas|Lobster|Nunito|Shadows+Into+Light|Varela+Round" rel="stylesheet">
<body>
<div class="wrapper">
<!-- Top Menu-->
<img class="top-logo" src="img/NPDesign_full-transparent-bg-1.png" alt="NP full logo" width="220px" height="220px">
<div class="nav">
<ul>
<li>Home</li>
<li>About Us</li>
<li>
<div class="dropdown-menu">
<input type="checkbox" id="A">
<label for="A">Menu</label>
<ul>
<li>Pastas To Go</li>
<li>Sauces To Go</li>
<li>
<div class="dropdown-readymeals">
<input type="checkbox" id="A-C">
<label for="A-C" style="font-size:10pt;">Ready Meals...</label>
<ul>
<li>Arancinis</li>
<li style="font-size:10pt;">Garlic Bread</li>
</ul>
</div>
</li>
</ul>
</div>
</li>
<li>Find Us</li>
</ul>
</div>
</div>
<div class="banner">
<!--
<img src="img/NPDesign_full-transparent-bg-1.png" alt="NP full logo" width="300px" height="300px">
-->
</div>
<div class="body-content">
<div class="specials-title"><h3>- SPECIALISING IN -</h3></div>
<div class="specials-content">
<div class="specials-boxes"><div class="specials-text"><h3>Freshly Hand Made Pastas</h3></div><div class="specials-img"><img src="freshlyhandmadepastas-1.jpg"></div></div>
<div class="specials-boxes"><div class="specials-text"><h3>Gourmet Pasta Meals</h3></div><div class="specials-img"><img src="gourmetpastameals-3.jpg"></div></div>
<div class="specials-boxes"><div class="specials-text"><h3>Traditional Home Made Sauces</h3></div><div class="specials-img"><img src="traditionalhomemadesauces.jpg"></div></div>
<div class="specials-boxes"><div class="specials-text"><h3>Variety of Filled Pastas</h3></div><div class="specials-img"><img src="varietyoffilledpastas-1.jpeg"></div></div>
<div class="specials-boxes"><div class="specials-text"><h3>Home Made Soups</h3></div><div class="specials-img"><img src="homemadesoups-2.jpg"></div></div>
<div class="specials-boxes"><div class="specials-text"><h3>Gourmet Rolls</h3></div><div class="specials-img"><img src="gourmetroles-1.jpg"></div></div>
</div>
</div>
<div class="footer">
<!--<div class="grid">-->
<div class="upper-footer-container">
<div class="footer-container-1">
<h4 style="font-family: 'Gloria Hallelujah', 'cursive';">Follow Us</h4>
<ul class="social-networks">
<li class="flex-items"><img src="fb-icon.png"></img></li>
<li class="flex-items"><img src="instagram-icon.png"></img></div></li>
</ul>
<div class="footer-container-1">
<h4 style="font-family: 'Gloria Hallelujah', 'cursive';">Opening Hours</h4> <br>
<ul class="contact-details">
<li>Monday: 9am-5:30pm</li>
<li>Tuesday: 9am-5:30pm</li>
<li>Wednesday: 9am-5:30pm</li>
<li>Thursday: 9am-9pm</li>
<li>Friday: 9am-5:30pm</li>
<li>Saturday: 9am-5pm</li>
<li>Sunday: 10am-5pm</li>
</ul>
</div>
<div class="footer-container-1">
<h4 style="font-family: 'Gloria Hallelujah', 'cursive';">Contact Us</h4> <br>
<ul class="contact-details">
<li>Add.: 152 Bunnerong Rd, Eastgardens NSW 2036</li>
<li>No.: (02) 8347 1988</li>
<li>Email</li>
<br>
<li>Catering Available</li>
</ul>
</div>
</div>
<div class="lower-footer-container">NaturalPasta © 2018</div>
<!--/div>-->
</div>
</body>
</html>
CSS
* {
padding: 0;
margin: 0;
box-sizing: border-box;
border: 1px solid red;
}
html {
height: 100%;
}
body {
min-height: 100%;
min-width: 100%;
}
.wrapper {
min-height: 100%;
width: 100%;
position: relative;
background: url("img/pasta-food-wallpaper-4.jpg") no-repeat;
background-size: 1350px 670px;
background-position: center;
background-attachment: fixed;
}
body {
height: 100%;
background: #ddd;
}
.nav {
height: 204px;
width: 100%;
margin: 0 auto; /* Centers navigation */
text-align: center;
text-transform: uppercase;
background: black;
display: flex;
justify-content: flex-end;
align-items: flex-end;
font-family: 'Gloria Hallelujah', cursive;
color: #ee6f20;
font-weight: bold;
font-size: 13pt;
}
.nav ul li {
height: 41px;
width: 125px;
background: #000;
}
.nav .dropdown-menu ul, .dropdown-menu .readymeals ul {
background: #000;
}
.nav a {
text-decoration: none;
color: #ee6f20;
}
.dropdown-menu ul li, .dropdown-readymeals ul li {
display: none;
}
.dropdown-menu {
position: relative;
display: inline-block;
}
.dropdown-menu ul {
position: absolute;
display: none;
}
input[type=checkbox] {
display: none;
}
input#A:checked ~ .dropdown-menu ul li {
display: block;
max-height: 100%;
}
input#A-C[type=checkbox]:checked ~ .dropdown-readymeals ul li {
display: block;
}
/*tbc */
.dropdown-menu ul li {
font-size: 11pt;
background: #000;
}
.nav ul {
list-style: none;
display: inherit;
}
.nav ul li, .nav ul ul, .nav ul ul li, .nav label {
cursor: pointer;
}
.top-logo {
margin: auto 0;
position: absolute;
left: 42%;
margin-top: -15px;
}
.body-content {
background-color: #000;
}
.specials-content {
position: relative;
display: flex;
flex-wrap: wrap;
color: orange;
justify-content: center;
}
.specials-title h3 {
width: 100%;
display: block;
margin-top: 0px;
padding-top: 75px;
color: #ee6f20;
}
.specials-boxes {
display: flex;
flex-direction: row;
flex-wrap: wrap;
margin: 35px 75px;
padding: 50px 100px;
/*adjust margin height-width*/
}
.specials-text, .specials-img {
padding: 35px;
display: flex;
align-items: center;
}
.specials-text h3 {
text-align: center;
font-family: 'Gloria Hallelujah', 'cursive';
color: #ee6f20;
}
.specials-img img {
width: 300px;
height: 300px;
border-radius: 25px 5px 25px 5px;
}
h3 {
text-align: center;
font-family: 'Gloria Hallelujah', 'cursive';
color: #eee;
}
.footer {
bottom: 280px;
padding: 150px;
width: 100%;
text-align: center;
background: rgb(0,0,0);
color: white;
font-family: sans-serif;
display: flex;
flex-flow: wrap;
}
.upper-footer-container {
width: 100%;
display: flex;
flex-direction: row;
justify-content: space-around;
display: flex;
flex-wrap: wrap;
}
.footer-container-1 {
width: 250px;
display: block;
margin: 25px;
}
.social-networks {
list-style: none;
display: flex;
flex-direction: row;
justify-content: space-around;
}
.flex-items a img {
width: 50px;
height: 50px;
border-radius: 25px;
margin: 25px;
}
.contact-details {
list-style: none;
font-family: 'ubuntu', sans-serif;
}
.lower-footer-container {
width: 100%;
justify-content: center;
display: flex;
flex-wrap: wrap;
margin-top: 45px;
}
Is it to do with the html? The CSS? What could be interfering from displaying the menu and its submenu? :/
Much appreciated for the long run.
(P.S. I have other source image used in here, though that should not conflict with what I'm trying to resolve.)
In your code the <ul> tag is the sibling of selector input#A
But you have written css code as if .dropdown-menu is the sibling of selector input#A. This is why your code at this particular point doesn't work.
You have to target <ul> when input#A is clicked. <ul> is the sibling of input#A.
Change the css code on line 81 as below
input#A:checked ~ ul li {
display: block;
max-height: 100%;
}
This code change will make your sub-menu visible when you click Menu as shown in below image.
i'm mentioning the fix only for this particular point. In your codepen i can see that you've made this same mistake in few other places. You have to fix it.
Hope this helps.