How to make list and paragraph inline and float right? - html

I am having trouble making my list inline along with the Sign In to the right of it. I tried putting float for the tags since every part on my header is a link, but that isn't working. Can anyone help me put the logo float left, the list to the right, with the sign in being the farthest thing right (float right pretty much for the sign in). Thanks for any answers I get, I truly appreciate it.
html:
<header>
<nav id="header-flex">
<div>
<img src="logo.jpg" alt=logo width="30px" height="30px">
</div>
<div>
<ul>
<li>Shop</li>
<li>Products</li>
<li>FAQ</li>
<li>Blog</li>
</ul>
</div>
<div>
<p>Sign In</p>
</div>
</nav>
</header>
css:
#header-flex {
display: flex;
position: fixed;
background: rgb(0,191,255);
height: 75px;
width: 100%;
}
header a {
display: inline-block;
float: right;
}

It can be done by giving your div's a width and assigning 'float: left' to them, like this:
HTML:
<div class="left">
<img src="logo.jpg" alt="logo" width="30px" height="30px">
</div>
<div class="mid">
<ul>
<li>Shop</li>
<li>Products</li>
<li>FAQ</li>
<li>Blog</li>
</ul>
</div>
<div class="right">
<p>Sign In</p>
</div>
</nav>
</header>
CSS:
#header-flex {
display: flex;
position: fixed;
background: rgb(0, 191, 255);
height: 75px;
width: 100%;
}
header a {
display: inline-block;
float: right;
}
.left, .mid, .right {
float: left;
width: 33%;
}

<div> has display: block; by default, no need to use div for img and ul.
Also, remove the default 8px margin from body:
body {
margin: 0;
}
A nav is better to use display: block; since you want it to take the whole width.
Now you can use float: left, float: right
body {
margin: 0;
}
#header-flex {
display: block;
position: fixed;
background: rgb(0, 191, 255);
height: 75px;
width: 100%;
}
img {
float: left;
}
#header-flex>ul {
float: left;
margin: 0;
}
.sign-in {
float: right;
margin: 25px;
}
<header>
<nav id="header-flex">
<img src="logo.jpg" alt=logo width="30px" height="30px">
<ul>
<li>Shop</li>
<li>Products</li>
<li>FAQ</li>
<li>Blog</li>
</ul>
<div class="sign-in">
Sign In
</div>
</nav>
</header>

Related

HR doesn't appear in proper place

Trying to separate my header and navtab with a simple horizontal line. Nothing fancy.
Yet, it appears above the header for some reason. I know it has something to do with floating of twitter button and company logo. Before I did this the line appeared as it should. I'm stuck here.
.main_header {
background: #d0d0d0
}
.company_logo {
float: left;
text-align: left;
padding: 10px 0 10px 50px;
}
.twitter {
float: right;
margin-top: 10px;
margin-right: 10px;
}
<header class="main_header">
<div class="company_logo">
<img src="images/logo.png" width="20%">
</div>
<div class="twitter">
</div>
</header>
<hr>
<nav class="navbar">
<div class="container">
<ul>
<li>Home</li>
<li>About</li>
<li>Portfo</li>
<li>Servi</li>
<li>Contact</li>
</ul>
</div>
</nav>
You're right. Since the children of .main_header are floated, their parent has no height.
One solution is to clear the floats.
Below, I'm using group class and one of the clearfix methods.
For further reference, see What methods of ‘clearfix’ can I use?
.main_header {
background: #d0d0d0
}
.company_logo {
float: left;
text-align: left;
padding: 10px 0 10px 50px;
}
.twitter {
float: right;
margin-top: 10px;
margin-right: 10px;
}
.group::after {
content: "";
display: block;
clear: both;
}
<header class="main_header group">
<div class="company_logo">
<img src="images/logo.png" width="20%">
</div>
<div class="twitter">
</div>
</header>
<hr>
<nav class="navbar">
<div class="container">
<ul>
<li>Home</li>
<li>About</li>
<li>Portfo</li>
<li>Servi</li>
<li>Contact</li>
</ul>
</div>
</nav>
Try :
hr{
clear: both;
}
Should clear floating elements on either side.

How to get this div onto a new line

How do I get ARC onto its own line? I put them both in the same div to share a background, but I am having trouble separating the two. My menu bar is perfectly centered until I put in "ARC".
.header{
background-image: url(https://static.pexels.com/photos/204495/pexels-photo-204495.jpeg);
background-size: contain;
background-repeat: no-repeat;
background-position: center;
height: 80vh;
display: flex;
width: 100%;
}
.header ul li{
float: left;
color: white;
list-style: none;
padding: 7px 6px;
margin: 0;
text-align: center;
font-size: 15px;
display: flex;
}
.menu{
width: 100%;
text-align: center;
display: block;
justify-content: center;
margin: 0 auto;
padding: 0;
}
<div class="header">
<ul class="menu">
<li>Home</li>
<li>Services</li>
<li>Contact</li>
<li>Contact</li>
</ul>
<br>
<div class="title">
<h1>ARC</h1>
</div>
</div>
I would change the HTML
from this:
<div class="header">
<ul class="menu">
<li>Home</li>
<li>Services</li>
<li>Contact</li>
<li>Contact</li>
</ul>
<br>
<div class="title">
<h1>ARC</h1>
</div>
</div>
To this (solution):
<div class="header">
<div id="navbar-wrapper">
<ul class="menu">
<li>Home</li>
<li>Services</li>
<li>Contact</li>
<li>Contact</li>
</ul>
</div>
<div class="title">
<h1>ARC</h1>
</div>
</div>
Conclusion: it is better to use for example a div tag to make a new line than br tag as you gain much more control over your page setup and it is easier to style.
Keep on good work!
Since your li is float left they will be one next to the other.
add clear:left to the element and it will work.
.header ul li{
float: left;
clear: right;
...
}
clear
The clear CSS property specifies whether an element can be next to floating elements that precede it or must be moved down (cleared) below them.
The clear property applies to both floating and non-floating elements.
Just applied some of the CSS styles to only the links and that worked. Hope this helps!
.header{
background-image: url(https://static.pexels.com/photos/204495/pexels-photo-204495.jpeg);
background-size: contain;
background-repeat: no-repeat;
background-position: center;
height: 80vh;
width: 100%;
}
.header ul li{
float: left;
color: white;
list-style: none;
padding: 7px 6px;
margin: 0;
font-size: 15px;
}
.menu{
text-align: center;
width: 100%;
text-align: center;
display: flex;
justify-content: center;
margin: 0 auto;
padding: 0;
}
<div class="header">
<ul class="menu">
<li>Home</li>
<li>Services</li>
<li>Contact</li>
<li>Contact</li>
</ul>
<br>
<div class="title">
<h1>ARC</h1>
</div>
</div>

Can't get two divs to align horizontally

I'm pulling my hair out trying to get two div tags to align. I've read page after page of solutions on here but I've not been able to get any of them to work. I'm not sure if this is related to this being a Visual Studio project using MVC. It seems unlikely but I thought I'd mention it.
So this is for a header bar on a company website. Logo should be on the left and the menu should be on the right. It must be responsive. Here's what I've got so far:
header {
width: 100%;
position: absolute;
top: 0;
left: 0;
background-color: #ffffff;
}
logo {
float: none;
width: 215px;
}
nav {
width: 100%;
height: 100%;
float: left;
}
nav ul {
height: auto;
padding: 8px 0px;
margin: 0px;
}
nav li {
display: inline;
padding: 20px;
}
nav a {
text-decoration: none;
color: #171581;
padding: 8px 8px 8px 8px;
}
nav a:hover {
color: #D60053;
}
And here is the HTML
<div style="opacity: 1;" class="wrapper">
<header class="">
<div class="container">
<div class="logo">
<a href="/" class="glyphicon-log-out top-menu">
<img src="~/assets/images/sunwavelogo.png" alt="Sunwave Logo" />
</a>
</div>
<div class="hamburger"></div>
<nav>
<ul>
<li>About</li>
<li>Residential & Business</li>
<li>My Accounts Details</li>
<li>FAQ</li>
<li>Contact us</li>
</ul>
</nav>
</div>
</header>
By changing your CSS like this (note the added dot in .logo)
.logo {
float: left;
width: 215px;
}
nav {
margin-left: 215px;
}
header {
width: 100%;
position: absolute;
top: 0;
left: 0;
background-color: #ffffff;
}
.logo {
float: left;
width: 215px;
}
nav {
margin-left: 215px;
}
nav ul {
height: auto;
padding: 8px 0px;
margin: 0px;
}
nav li {
display: inline;
padding: 20px;
}
nav a {
text-decoration: none;
color: #171581;
padding: 8px 8px 8px 8px;
}
nav a:hover {
color: #D60053;
}
<div style="opacity: 1;" class="wrapper">
<header class="">
<div class="container">
<div class="logo">
<a href="/" class="glyphicon-log-out top-menu">
<img src="~/assets/images/sunwavelogo.png" alt="Sunwave Logo" />
</a>
</div>
<div class="hamburger"></div>
<nav>
<ul>
<li>About</li>
<li>Residential & Business</li>
<li>My Accounts Details</li>
<li>FAQ</li>
<li>Contact us</li>
</ul>
</nav>
</div>
</header>
You have many problems in your code:
logo in your css should be .logo to refer to the class of the logo.
The property float:none should be set to float:left; so it should be correctly floated.
And for the nav you shouldn't specify a width:100% because it will be forced to take the whole width of the header, you need to set it to auto for example.
This is a working snippet:
header {
width: 100%;
position: absolute;
top: 0;
left: 0;
background-color: #ffffff;
}
.logo {
float: left;
width: 215px;
}
nav {
width: auto;
height: 100%;
float: left;
}
nav ul {
height: auto;
padding: 8px 0px;
margin: 0px;
}
nav li {
display: inline;
padding: 20px;
}
nav a {
text-decoration: none;
color: #171581;
padding: 8px 8px 8px 8px;
}
nav a:hover {
color: #D60053;
}
<div style="opacity: 1;" class="wrapper">
<header class="">
<div class="container">
<div class="logo">
<a href="/" class="glyphicon-log-out top-menu">
<img src="~/assets/images/sunwavelogo.png" alt="Sunwave Logo" />
</a>
</div>
<div class="hamburger"></div>
<nav>
<ul>
<li>About
</li>
<li>Residential & Business
</li>
<li>My Accounts Details
</li>
<li>FAQ
</li>
<li>Contact us
</li>
</ul>
</nav>
</div>
</header>
1.Your code was badly formatted.I have formatted it.
2..logo should be set to "float:left".
3..container should have"overflow:hidden"
I have also made Your li straight.(I have made it in one line )
This contains your html formatted code,Css which You may need to change as well as add
<div style="opacity: 1;" class="wrapper">
<header class="">
<div class="container">
<div class="logo">
<a href="/" class="glyphicon-log-out top-menu">
<img src="~/assets/images/sunwavelogo.png" alt="Sunwave Logo" />
</a>
</div>
<div class="hamburger">
<nav>
<ul>
<li>About</li>
<li>Residential & Business</li>
<li>My Accounts Details</li>
<li>FAQ</li>
<li>Contact us</li>
</ul>
</nav>
</div>
</div>
</header>
</div>
Your css code:
* {
margin: 0px;
padding: 0px;
}
header{
width:700px;
margin:0 auto;
}
.container {
overflow: hidden;
}
.logo {
float: left;
margin-right:100px;
}
.hamburger {
/* float: left; */
overflow: hidden;
}
li {
float: left;
padding: 5px;
list-style-type: none;
}
Hope This Is what You had expected

logo and title of page floated left but the nav and part of the main content is in the way

I floated a logo image and the title of the page to the left, but then the nav gets in the way along with some of the main content. I tried to clear the nav but then when I want to display my navs inline it will throw it off. So I can't do that.
Anyone know what to do?
* {
margin: 0px;
padding: 0px;
}
header,nav,section,article,aside,footer {
display: block;
}
.container {
width: 960px;
margin: 0 auto;
}
.main_header img {
float: left;
}
.main_header h1 {
float: left;
}
<header class="main_header">
<img src="logo2.jpg" alt="logo pic">
<h1>Title of header</h1>
</header>
<nav>
<ul>
<li>Home
</li>
<li>About
</li>
<li>Contact
</li>
</ul>
</nav>
Add this to your css:
header{clear:both; overflow:hidden;}
nav ul li {display:inline;}
* {
margin: 0px;
padding: 0px;
}
header,nav,section,article,aside,footer {
display: block;
}
.container {
width: 960px;
margin: 0 auto;
}
.main_header img {
float: left;
}
.main_header h1 {
float: left;
}
header{clear:both; overflow:hidden;}
nav ul li {display:inline;}
<header class="main_header">
<img src="logo2.jpg" alt="logo pic">
<h1>Title of header</h1>
</header>
<nav>
<ul>
<li>Home
</li>
<li>About
</li>
<li>Contact
</li>
</ul>
</nav>

Centered logo with varied widths and multiple lists

I've been trying to create a navigation bar which consists of three pieces, a list to the left of the centered logo, the logo itself and a list to the right of the logo. I've tried absolutely positioning the logo and floating the lists however this leads to the logo overlaying the lists when the width of the browser is altered.
Any suggestions would be much appreciated, JSFiddle included below :-).
JSFiddle
HTML
<div class="navigation">
<div class="container-1020">
<ul>
<li>Home</li>
<li>Work</li>
<li>Contact</li>
<li>Blog</li>
</ul>
<div class="nav-logo">
<img src="http://placehold.it/200x60"/>
</div>
<ul>
<li>01234 123456</li>
</ul>
</div>
</div>
CSS
.navigation {
background: #222222;
}
.container-1020 {
max-width: 1020px;
min-width: 500px;
margin: 0 auto;
}
ul {
color: #fff;
margin: 0;
list-style-type: none;
}
li {
display: inline;
margin-right: 10px;
}
li:last-child {
margin-right: 0 !important;
}
.logo-container {
width: 200px;
height: 60px;
}
This might work for youFIDDLE
css:
* {
margin: 0;
}
a {
color: #ffffff;
text-decoration: none;
}
.navigation {
background: #222222;
}
.container-1020 {
max-width: 1020px;
min-width: 500px;
margin: 0 auto;
}
ul {
color: #fff;
list-style-type: none;
display: inline-block;
width: 30%;
}
ul:last-child {
text-align: right;
}
.nav-logo {
display: inline-block;
width: 30%;
}
html:
<div class="navigation">
<div class="container-1020">
<ul class="left">
<li>Home
</li>
<li>Work
</li>
<li>Contact
</li>
<li>Blog
</li>
</ul>
<div class="nav-logo">
<img src="http://placehold.it/200x60" />
</div>
<ul class="right">
<li>01234 123456</li>
</ul>
</div>
</div>
well for one, correct your class name for the logo, is it .nav-logo or .logo-container
then set your ul's and whichever logo container class you decide on to display:inline-block