CSS Header - Different Alignment - html

Image of Webpage
I want to add them to the same line so the header looks more tidy, what would be the correct code to use?
.header{
border-bottom:1px solid #eee;
padding:10px 0px;
width:100%;
text-align:left;
}
.header a{
color:#333;
text-decoration: none;
margin-left: 20px;
}
.phone {
text-align: right;
font-weight: bold;
padding-right: 20px;
align-content: right;
}
<div class="header">
Home
Products
<div class="phone"><a>Freephone: 0800 096 1617</a></div>
</div>

You can achieve that with float. Left for the the ones you want to go left, right for the phone number, and a overflow: hidden for the header.
.header{
border-bottom:1px solid #eee;
padding:10px 0px;
overflow: hidden;
width: 100%;
}
.header a{
color:#333;
text-decoration: none;
margin-left: 20px;
float: left;
}
.phone {
font-weight: bold;
margin-right: 20px;
float: right;
}
<div class="header">
Home
Products
<div class="phone"><a>Freephone: 0800 096 1617</a></div>
</div>

you should insert the Freephone: 0800 096 1617 to div class header and use Css position:absolute; right:(you can manipulate it to fix the freephone);
<div class="header">
Home
Products
<a class="freephone">Freephone: 0800 096 1617</a>
<div class="phone"></div>
</div>

.header{
border-bottom:1px solid #eee;
padding:10px 0px;
width:100%;
float:left;
}
.header a{
color:#333;
text-decoration: none;
margin-left: 20px;
}
.phone {
font-weight: bold;
padding-right: 20px;
float:right;
}
<div class="header">
Home
Products
<div class="phone"><a>Freephone: 0800 096 1617</a></div>
</div>
You have to add float:left; to .header class and add float:right; to .phone class

Use floating instead. The .clear class means to stop floating and it is neccessary. Also the phone does not need to be inside of a div and should have the id of phone instead of class of phone because there is only one phone element. You do not need the alignment and text-alignments at all.
.header {
border-bottom: 1px solid #eee;
padding: 10px 0px;
width: 100%;
}
.header a {
color: #333;
text-decoration: none;
margin-left: 20px;
float: left;
}
#phone {
font-weight: bold;
padding-right: 20px;
float: right !important;
}
.clear {
clear: both;
}
<div class="header">
Home
Products
<a id="phone">Freephone: 0800 096 1617</a>
<div class="clear"></div>
</div>
Hope this works as it wasn't tested because I am on mobile right now.

Related

How to make two HTML element align in single line?

I have two HTML element in one row. Whoch should display something like this:
For that I made both the element display-inline and also I set float left and right respectively. But they are displaying something like this:
You can see they are not being aligned properly.
.selected-account{
display: inline;
float: right;
color: #0679ca;
}
.select-account-accordion{
display: inline;
float: left;
color: #0679ca;
}
<div id="select-account" class="col-sm-12 col-md-12 disabled-billing-accordion">
<h3 id="select-acct" class="select-account-accordion">Select Account(s)</h3>
<span id="account-selected" class="selected-account">0 of 8 account selected</span>
</div>
Can you please suggest on this?
Edit: I think because I put those two element in the div class which I put for creating accordion, so thats why its creating trouble. Please see the style below for that div which is having class "disabled-billing-accordion"
.disabled-billing-accordion h3::before{
background: url("/static/img/accordion.png") no-repeat scroll 0 0
rgba(0, 0, 0, 0);
background-position: -1px -97px;
content: " ";
width: 34px;
height: 34px;
left: 0;
position: absolute;
top: 25px;
margin-left: 1em
}
.disabled-billing-accordion h3{
padding: .2em 0 0 3em;
color: #0679ca;
font-size: 1.5em;
line-height: 2.1875em;
margin-bottom: 8px;
font-weight: 100 !important
}
.disabled-billing-accordion{
padding: 10px;
border-bottom: 1px solid #bdbdbd
}
HI now you can define margin:0; and line-height as like this
.selected-account{
float: right;
color: #0679ca;
margin:0;
line-height:20px;
}
.select-account-accordion{
float: left;
color: #0679ca;
margin:0;
line-height:20px;
}
<div id="select-account" class="col-sm-12 col-md-12 disabled-billing-accordion">
<h3 id="select-acct" class="select-account-accordion">Select Account(s)</h3>
<span id="account-selected" class="selected-account">0 of 8 account selected</span>
</div>
There is margin for h3. Try
#select-acct {
margin: 0;
}
if you use h3 it will take default some margin and line-height if u check in the image while inspect u can see ,reference https://plnkr.co/edit/3O4773wA10jV1tC92zik?p=preview
So u have to add the styles for margin and line-height
.selected-account{
display: inline;
float: right;
color: #0679ca;
margin:0;
line-height:20px;
}
.select-account-accordion{
display: inline;
float: left;
line-height:20px;
margin:0;
}
You can use position:fixed and add left:"width of first one"
Like,
div1{
position:fixed;
width:200px;
height:300px;
}
div2{
position:fixed;
left:200px;
width:200px;
height:300px;
}
Hope it will help.
Edit
I have added some inline css in your code with position:fixed Here is screen shot.
You can simply remove the float: left; property from h3 ie,
.select-account-accordion {
display: inline;
/* float: left; */ //Remove this line
color: #0679ca;
}
Either reduce margin-top: 0px; for
<h3 id="select-acct" class="select-account-accordion">Select Account(s)</h3>
or
add equivalent margin-top example margin-top: 20px for
<span id="account-selected" class="selected-account">0 of 8 account selected</span>
.selected-account{
margin-top: 0px;
display: inline;
float: right;
color: #0679ca;
}
.select-account-accordion{
margin-top: 0px;
display: inline;
float: left;
color: #0679ca;
}
<div id="select-account" class="col-sm-12 col-md-12 disabled-billing-accordion">
<h3 id="select-acct" class="select-account-accordion">Select Account(s)</h3>
<span id="account-selected" class="selected-account">0 of 8 account selected</span>
</div>

Navbar align part right part left errors

I'm trying to create a navbar with some items on the left and some items on the right (Item 1 on the left, items 2 and 3 on the right). My JSFiddle has my current code.
What I have tried to fix this issue:
float: right
text-align:right
None of them seem to work. I'm sure there is a super simple solution, but I just can't think of it.
HTML:
<div class="navbar">
<!--Create the button home -->
<p class="innav">Num1</p>
<p class="HL">|</p>
<p class="rightIn">Num2</p>
<p class="HL">|</p>
<p class="rightIn">NUM 3</p>
<p class="HL">|</p>
</div>
CSS:
div.navbar{
width:100%;
height: 30px;
background-color: #03572c;
}
p{
display: inline;
}
p.innav{
color:white;
font-size: 24px;
width: 30px;
height: 30px;
margin-left: 10px;
margin-top: 10px;
}
p.rightIn{
color:white;
font-size: 24px;
width: 30px;
height: 30px;
margin-left: 10px;
margin-top: 10px;
}
.HL{
margin-left: 10px;
color:white;
font-size:24px;
}
JSfiddle
Any help would be greatly appreciated! :)
Add these style to your css.
p.rightIn,
p:nth-child(4),
p:nth-child(6)
{
float: right;
margin: 0px 5px;
width: auto;
}
Jsfiddle
I would recommend that you use a CSS grid system for this, since you are likely to need this functionality over a over on your sites.
Here are some grid systems that I have used in the past:
Pure CSS
http://purecss.io/grids/
Foundation
http://foundation.zurb.com/docs/components/grid.html
Bootstrap
http://getbootstrap.com/css/#grid
Semantic UI
http://semantic-ui.com/collections/grid.html
Or, if you feel like creating your own grid system, here is a good article about it:
http://www.sitepoint.com/understanding-css-grid-systems/
nav {
background: #000000;
width: 100%;
display: block;
padding: 8px 0;
font-family: arial;
font-size: 13px;
}
nav span {
display:block;
width:100%;
line-height: normal;
text-align:right;
}
nav a {
color: #ffffff;
padding: 0 10px;
text-decoration: none;
display:inline-block;
border-right:1px solid #ffffff;
}
nav a:first-child{
float:left;
}
nav a:last-child{
border:none;
}
<nav>
<span>
Link 1
Link 2
Link 3
</span>
</nav>
Demo

Getting Div tag to extend to the bottom of the Page w/out covering elements already on the page

I have tried absolute to my footer to stay on the bottom of the page but it covers up the elements that are already at the bottom instead of going underneath them. Fixed does the similar thing except if the page is longer it will cover up elements in the center of the page. I literally just want the backgound color of my div to extend to the bottom of the page and have my logo and text stay in between the div at a set height. Here's what I've got.
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="main.css"/>
<title>
</title>
<div class="heading">
<img src="Images/Redbird.gif" alt="Redbird" style="float:left; padding-left:15px; padding-top:15px; width:150px;height:90px">
<form>
Search:
<input type="search" name="Search" style="float:right;">
</form>
<br></br>
<button type="button" id="Login">Login</button>
<button type="button" id="Login">Create New Account</button>
<h1>Technology Blog</h1>
<a href="index.html">
<img src="Images/House.png" alt="Home" style="width:35px; height:35px;">
</a>
</div>
<div class="table">
<table style+"width:100%">
<tr>
<td>Phones & Tablets</td>
<td>Computers & Laptops</td>
<td>Internships</td>
<td>Troubleshooting</td>
<td>Product Ratings & Reviews</td>
</tr>
</table>
</div>
</head>
<body>
<div class="Welcome">
<h2>Welcome</h2>
<p>Welcome to Illinois State University's Technology Blog. Here you can view and post questions, answers, reviews, and other information that is related to technology. This website is for Illinois State University Students ONLY! You must sign in or create an account to view or post on this website.</p>
</div>
<div class="Slideshow">
<img src="Images/DellComps.jpg" alt="Computers" style="width: 397px; height: 298px">
</div>
</body>
<div class="Footer">
<img src="Images/Seal.png" alt="ISU Seal" style="width: 40px; height: 40px; padding-bottom: 10px; padding-top: 10px">
Copyright 2014 # TEC 319 Group <br/> Illinois Sate University
</div>
</html>
heres the CSS. I only need to edit the .Footer tag i believe
html{
height: 100%;
position: relative;
}
h1{
text-align: center;
font-family: impact;
font-style: italic;
}
.heading{
background-color: #CA0000;
height:150px;
}
td{
border:5px solid black;
text-align:center;
background-color:#790000;
color:white;
padding:10px;
font-family: helvetica;
font-style: italic;
font-size: 15px;
}
table{
width:100%
}
.table{
background-color:black;
height:53px;
}
form{
float:right;
}
button{
float:right;
}
.Slideshow img{
display: block;
position: center;
margin-left: auto;
margin-right: auto;
}
.Footer img{
display: block;
position: center;
margin-left: auto;
margin-right: auto;
}
.Footer{
margin-top: 40px;
text-align: center;
background-color: #D8D8D8;
padding-bottom: 20px;
width: 100%;
}
.Preview td{
display: block;
text-align: left;
color: black;
background-color: white;
}
.Blog td{
display: block;
text-align: left;
color: black;
background-color: white;
border: 0px;
}
.newPost h2{
display: block;
position: center;
margin-left:auto;
margin-right: auto;
vertical-align: middle;
color: white;
background-color: #790000;
border: 5px solid black;
border-collapse: collapse;
width: 250px;
text-align: center;
}
h3 {
color: white;
background-color: #790000;
border: 5px solid black;
}
h4{
text-align: left;
font-size: 14pt;
color:#790000
}
.back h2{
display: block;
position: left;
border:5px solid black;
background-color:#790000;
color:white;
padding:10px;
font-family: helvetica;
font-style: italic;
font-size: 15px;
width: 100px;
}
form.comment{
float:left;
size
}
a.blogTitle:link {
color: #790000;
text-decoration: none;
}
a.blogTitle:visited{
color: #790000;
text-decoration: none;
}
a.blogTitle:active{
color: #790000;
text-decoration: none;
}
a.blogTitle:hover{
color: #CA0000;
text-decoration: none;
}
a:link {
color: white;
text-decoration: none;
}
a:visited{
color: white;
text-decoration: none;
}
a:active{
color: white;
text-decoration: none;
}
a:hover{
color: #CA0000;
text-decoration: none;
}
You need to set the footer position to relative to have it respect other elements on the page. Both absolute and fixed remove the element from the page flow, which causes overlapping.
Demo
Change position:relative to fixed in the demo CSS and then uncomment bottom to see the difference. You can also play with height on the body tag to see how behavior changes.
<div id="content">
<p>Content</p>
</div>
<div id="footer">
<p>Footer stuff</p>
</div>
body {
margin:0;
padding:0;
}
#content {
height:1200px;
width:100px;
background-color:#eee;
position:relative;
margin:0;
padding:0;
border:1px solid black;
}
#footer {
width:100px;
position:relative;
/* bottom:0; */
background-color:#eee;
margin:0;
padding:0;
border:1px solid black;
}

Need help containing text within divs in Chrome

What i have looks splendid in firefox, but for some reason all of the text won't seem to stay contained within their respective div's in Chrome. Chrome seems to be assigning random height values to the ul and h1 elements, but for the life of me I can't seem to figure out why. EDIT: Okay, I am going crazy with rage. I mean it even works in explorer............ What is Chrome's (read "my") issue!?!?!?!?!?!
I deleted the screen shot, since i've made some changes. I've simply just uploaded it to the site musingsofamachiavellian.com you should be able to see the issue in all its glory there.
THANK YOU SO MUCH, the fix was as easy as adding html { height:100%;}
This is quite literally the first code i've ever written from scratch, so be gentle :|
CSS:
body {
background-color: #a5e2a8; /*A light green*/
min-width: 960px;
}
#Foundation {
width:960px;
height:100%;
background-color: #3b3b3b; /*Milk White*/
background-color: rgba(59,59,59,0.9);
/* background-color: #212121; /*A light black*/
}
#Header {
height:80px;
width:940px;
margin-left: 10px;
margin-right: 10px;
margin-top: 10px;
margin-bottom: 10px;
padding: 0px;
background-color: #FEFCFF; /*Milk White*/
background-color: rgba(254,252,255,0.9);
}
#TitleText{
height:80px;
width:940px;
font-family: Cambria math;
font-size: 48px;
padding: 16px;
color: #F70D1A;
vertical-align: top;
}
#ButtonBar{
height:32px;
width:940px;
margin-left: 10px;
margin-right: 10px;
margin-top: 10px;
margin-bottom: 0px;
padding: 0px;
background-color: #FEFCFF; /*Milk White*/
background-color: rgba(254,252,255,0.9);
}
#ButtonBarUL{
height:32px;
width:940px;
margin:0px;
padding: 6px;
}
.Button {
text-align: center;
font-family: Cambria math;
font-size: 16px;
padding-top: 0px;
padding-left: 0px;
color: #F70D1A;
display: inline-block;
list-style-type: none;
vertical-align: top;
}
#SidebarContainer {
height:100%;
width:160px;
margin-left: 10px;
margin-right: 10px;
margin-top: 10px;
margin-bottom: 10px;
padding: 0px;
background-color: #FEFCFF; /*Milk White*/
background-color: rgba(254,252,255,0.9);
float:left;
}
.SideBarContent {
width:140px;
margin-left: 10px;
margin-right: 10px;
margin-top: 10px;
margin-bottom: 10px;
padding: 0px;
background-color: #FEFCFF; /*Milk White*/
background-color: rgba(254,252,255,0.9);
float:left;
text-align: center;
font-family: Cambria math;
font-size: 12px;
color: #212121;
}
#MainContainer {
height:100%;
width:770px;
margin-right:10px;
margin-top:10px;
margin-bottom:10px;
margin-left:0px;
padding: 0px;
background-color: #FEFCFF; /*Milk White*/
background-color: rgba(254,252,255,0.9);
float:left;
}
.ArticleContainer {
height:100%;
width:750px;
margin: 10px;
padding: 0px;
background-color: #FEFCFF; /*Milk White*/
background-color: rgba(254,252,255,0.9);
float:left;
}
.ArticleHead {
height:100%;
width:750px;
margin: 10px;
padding: 0px;
background-color: #FEFCFF; /*Milk White*/
background-color: rgba(254,252,255,0.9);
float:left;
border-bottom:1px solid;
font-family: Cambria math;
font-size: 14px;
color: #F60D1B;
}
.ArticleContent {
height:100%;
width:750px;
margin: 10px;
padding: 0px;
background-color: #FEFCFF; /*Milk White*/
background-color: rgba(254,252,255,0.9);
float:left;
font-family: Cambria math;
font-size: 12px;
color: #212121;
}
#Footer {
height:32px;
width:940px;
margin-left: 10px;
margin-right: 10px;
margin-top: 10px;
margin-bottom: 10px;
padding: 0px;
background-color: #FEFCFF; /*Milk White*/
background-color: rgba(254,252,255,0.9);
float:left;
font-family: Cambria math;
font-size: 12px;
color: #212121;
clear: both;
list-style-type: none;
text-align: center;
}
ul, li {
list-style-type: none;
}
site:
<!DOCTYPE html>
<head>
<link rel='stylesheet' type='text/css' href='core.css' />
<script type='text/javascript' src='script.js'></script>
<title>Musings</title>
</head>
<body>
<div id='Foundation'>
<header id='Header'>
<h1 id='TitleText'>Musings of a Machiavellian</h1>
</header>
<div id='ButtonBar'>
<ul id='ButtonBarUL'>
<li class='Button'>About |</li>
<li class='Button'>Past |</li>
<li class='Button'>Future |</li>
<li class='Button'>FAQ |</li>
</ul>
</div>
<section id='SidebarContainer'>
<div class='SideBarContent'>
<p>Chronicles</p>
</div>
</section>
<section id='MainContainer'>
<div class='ArticleContainer'>
<div class='ArticleHead'>
<h1>Hey! Thanks for stopping by. We're currently under construction...</h1>
</div>
<article class='ArticleContent'>
<p>This will be blog 2.0 - A webspace for own personal experimentation, and to chronicle (err.... blog) some musings.</p>
<p>They'll range in topic from politics, to science, to strategy, to economics. Stay tuned, or simply send me a message.</p>
<p>I'm by no means a web-development expert. If you see something that should be improved, I more than welcome your suggestions. Feel free to shoot me an e-mail!</p>
</article>
</div>
<div class='ArticleContainer'>
<div class='ArticleHead'>
<h1>I hate chrome...</h1>
</div>
<article class='ArticleContent'>
<p>If you're viewing this page in Chrome, chances are it looks jumbled. The reason, no clue... but the search for an answer is quickly turning intot he bane of of my existance.</p>
<p>Frustration level.... over 9000! I mean, it even works in internet exploder...</p>
</article>
</div>
</section>
<footer id='Footer'>
<ul id='ContactInfo'>
<li>info'at'Musings...</li>
</ul>
</footer>
</div>
</body>
</html>
I did alot of tuning up. Take a look here http://codepen.io/anon/pen/Ezham
Noticeable I used %'s instead of pixels and added correct positioning.
I see two things:
1. The Cambria math font is causing problems.
2. You should add this css: html { height: 100% }
I believe this is because the div Foundation needs to match its css. Foundation and foundation. One is capitalized and one is not.

HTML/CSS float left issue

I have been recently designing some content which needs to be side by side and have the height automatically resize, but the height doesn't resize. The div doesn't expand to the size of the items inside of it. Is there a way to allow the div to expand to the size of the elements inside of it?
CSS
* {
padding: 0px;
margin: 0px;
}
body {
font-family: 'Metrophobic', sans-serif;
background-color: #c5c5c5;
background-image: url('../images/noise.png');
}
#container {
width:900px;
background-color: #dbdbdb;
margin-top: 20px;
margin-left: auto;
margin-right: auto;
margin-bottom: 20px;
box-shadow: 0px 0px 5px black;
}
.center_align {
display: inline-block;
margin-left: auto;
margin-right: auto;
}
#header {
height:80px;
font-size: 60px;
padding: 10px;
text-align: center;
}
#menu {
width:900px;
height:50px;
margin-top: 10px;
margin-bottom: 10px;
background-color: #cacaca;
}
.menu_link {
width:224px;
height:50px;
text-align: center;
font-size: 35px;
float: left;
opacity: 0.3;
background-color: #cacaca;
}
.menu_divider {
width: 1px;
height: 50px;
background-color: #dbdbdb;
float:left;
}
#content {
width: 900px;
height: auto;
padding: 10px;
font-size: 20px;
height: auto;
}
.line_container {
margin-top:5px;
margin-bottom:5px;
}
#footer {
width:900px;
height:22px;
padding-top:2px;
text-align: center;
font-size: 14px;
color:black;
}
a:link {
color:black;
text-decoration: none;
}
a:visited {
color:black;
text-decoration: none;
}
a:hover {
color:black;
text-decoration: none;
}
a:active {
color:black;
text-decoration: none;
}
a.link:link {
color:#21525e;
}
a.link:visited {
color:#21525e;
}
a.link:hover {
color:#307f91;
text-decoration: underline;
}
a.link:active {
color:#307f91;
text-decoration: underline;
}
HTML
<html>
<head>
<title>Home</title>
<link rel="shortcut icon" href="../images/favicon.ico" />
<link href="http://fonts.googleapis.com/css?family=Metrophobic" rel="stylesheet" type="text/css" />
<link href="../css/style.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.icon {
width:100px;
height:100px;
border: 3px solid white;
border-radius:25px;
margin-left:10px;
margin-right:10px;
background-position: center center;
background-size: 100px 100px;
}
</style>
</head>
<body>
<div id="container">
<div id="header">
<div class="center_align">
<img src="../images/header_icon.png" alt="header_icon" width="80" height="80" style="margin-right:20px;float:left;" />
<div style="height:80px;float:left;">Title</div>
</div>
</div>
<div id="menu">
Home
<div class="menu_divider"></div>
Tutorials
<div class="menu_divider"></div>
About
<div class="menu_divider"></div>
Contact
</div>
<div id="content">
<div style="width:900px;">
<div class="icon" style="background-image:url('image.jpg');float:left;"></div><div style="float:left;margin-top:20px;">I'm a freelance Web, Iphone, and Game developer.</div>
</div>
</div>
<div id="footer">
© Cameron
</div>
</div>
</body>
</html>
Looks like the problem is that the #footer element isn't properly cleared. Add clear: both; to #footer. This pushes the cleared element below the floated elements, and should functionally result in the same visual fix.
The "container div" basically "forgets" that it is the container for them, so simply add an overflow:auto; to make it remember.
I also tend to add zoom:1 for IE.
The problem is that you are floating elements, and that causes problems with wrapping divs per default (pretty much...).
Here is a working solution, where overflow:hidden is added to the wrapping div: http://jsfiddle.net/s2dxw/2/
The float issue is pretty confusing, and has had a couple of solutions in the past. Here's a good read regarding floats in HTML: http://css-tricks.com/all-about-floats/
Alternatively, you can put some element with the rule clear: both; inside and at the end of the wrapping div.