Need help on css header float - html

When i do my web design, meet a problem when i need to do
[LEFT LOGO] then [TITLE(CENTER)] then [RIGHT LOGO]
The problem appear at RIGHT LOGO there, it doesn't align with LEFT LOGO.
The right logo is under the line of TITLE(CENTER)
here is my code sample, thanks:
<div class="navigation">
<div id="left">
<a title="Multimedia" href="#">
<img src="images/logo.png"/>
</a>
</div>
<div id="title">Tutor Program</div>
<div id="right">
<a href="#" title="Inspire and Innovate">
<img src="images/tagline_alt.png"/>
</a>
</div>
css:
.navigation{
height:auto;
background-color:#666;
width:85%;
margin:auto;
min-width:800px;
}
#title{
text-align:center;
margin: auto;
font-family:‘Arial Black’, Gadget, sans-serif;
font-size: 20px;
color: #FFF;
}
#left {
float: left;text-align:left;
margin: auto;
}
#right {
float: right;text-align:right;
margin: auto;
}
a img { border: 0; }

simply move the right container above the left container check below
<div class="navigation">
<div id="right">
<a href="#" title="Inspire and Innovate">
<img src="images/tagline_alt.png"/>
</a>
</div>
<div id="left">
<a title="Multimedia" href="#">
<img src="images/logo.png"/>
</a>
</div>
<div id="title">Tutor Program</div>
</div>

I thing its work an another way i have some changes in style width depends of logo width. if it is not set in center then change the width %.
#title{
text-align:center;
margin: auto;
font-family:'Arial Black', Gadget, sans-serif;
font-size: 20px;
color: #FFF;
width:59%;
float:left;
}
.clear {
clear:both;
margin:0px;
font-size:0px;
}
and add a div after the last div with class clear.
<div id="right"> .... </div>
<div class="clear"> </div>

You could also display your divs as a table and table-cells, like this:
HTML
<div class="navigation">
<div id="left">
left
</div>
<div id="title">
title
</div>
<div id="right">
right
</div>
</div>
CSS
.navigation {
width: 100%;
display: table;
table-layout: fixed;
}
.navigation > div {
display: table-cell;
}
.navigation div:nth-child(1) {
background: lightgray;
}
.navigation div:nth-child(2) {
background: gray;
text-align: center;
}
.navigation div:nth-child(3) {
background: lightgray;
text-align: right;
}
Also check the JSFiddle Demo

Related

Fixed navbar overlaps <div> element, causes Navbar to stop working

So I've created the Navbar which jumps to sections on the page via clicking. It works for my 'projects' and 'contact' sections but when I click 'about' the navbar jumps to it, but becomes transparent and unclickable. I tried adding a padding-top X px; to the 'about' element, but it still doesn't work.
Code is as follows in Codepen:
HTML:
<body>
<div class="fluid-container">
<h2> My Web Portfolio</h2>
<!--Creates the Navigation bar -->
<div class="navbar">
About
Projects
Contact
</div>
<!-- this creates the About section-->
<div class="main">
<div id=about>
<h3>Blank</h3>
</div>
<!-- This creates the 'project' section of the webpage-->
<div id=projects>
<h3><pre>My tribute page to Neil Armstrong<pre></h3>
<a href="#"><img border="0" alt="My Tribute page" align="center" src="#"/>
</a>
</div>
<!--contact section-->
<div id=contact>
<h3>Contact me via Facebook, Twitter, and Instagram!<h3>
<a href="#" class="fa fa-facebook" ></a>
</div>
</div>
</div>
</body>
CSS:
body {
background-color:turquoise;
padding-top:25px;
}
h2 {
text-align:center;
}
.navbar {
overflow:hidden;
background-color:#333;
position:fixed;
top:0px;
width:100%;
}
.navbar a {
float:left;
display:block;
color:#f2f2f2;
text-align:center;
padding:14px 16px;
text-decoration:none;
font-size:17px;
}
.main {
padding:16px;
margin-top:65px;
}
#projects {
position:relatve;
width:150px;
height:100px;
margin-top:200px;
margin-left:150px;
}
#contact {
position:relatve;
text-align:center;
margin-top:800px;
}
#about{
position:relative;
text-align:center;
padding-top:25px;
}
What am I doing wrong here?
When the page jumps to about, the sections obscure the nav bar. If you set a z-index to #main and the nav bar, you can ensure the navbar is always above the sections. I hope this helps.
body {
background-color: turquoise;
padding-top: 25px;
}
h2 {
text-align: center;
}
.navbar {
overflow: hidden;
background-color: #333;
position: fixed;
top: 0px;
width: 100%;
z-index: 10;
}
.navbar a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.main {
padding: 16px;
position: relative;
z-index: 0
margin-top: 65px;
}
#projects {
position: relatve;
width: 150px;
height: 100px;
margin-top: 200px;
margin-left: 150px;
}
#contact {
position: relatve;
text-align: center;
margin-top: 800px;
}
#about {
position: relative;
text-align: center;
padding-top: 25px;
}
<body>
<div class="fluid-container">
<h2> My Web Portfolio</h2>
<!--Creates the Navigation bar -->
<div class="navbar">
About
Projects
Contact
</div>
<!-- this creates the About section-->
<div class="main">
<div id=about>
<h3>Blank</h3>
</div>
<!-- This creates the 'project' section of the webpage-->
<div id=projects>
<h3><pre>My tribute page to Neil Armstrong<pre></h3>
<a href="#"><img border="0" alt="My Tribute page" align="center" src="#"/>
</a>
</div>
<!--contact section-->
<div id=contact>
<h3>Contact me via Facebook, Twitter, and Instagram!<h3>
<a href="#" class="fa fa-facebook" ></a>
</div>
</div>
</div>
</body>

how to center a div inside the header from the top

I have a header it contains two divs [ left div and right div ] and offset 4-cols before them . What i want is to make the right div at the middle of the header .
.header
{
background-color: #FFF;
padding: 15px;
}
.header .left img { width: 90%; }
.header .right > div { display: inline-block; }
.header .right span { color: #0095AE }
.header .right > span:first-child { font-size: 22px; }
.header .right > div p
{
font-weight: bold;
font-size: 13px;
margin:0;
padding: 0;
color: #0095AE
}
.header .right > div p:first-child { text-align: right }
<div class="header">
<div class="row">
<div class="col-md-4 col-md-offset-4 ">
<div class="left">
<img class ="logo" src="images/logo.png">
</div>
</div>
<div class="col-md-4 ">
<div class="right">
<span>By</span>
<img src="images/crescent.png" >
<div>
<p> الهلال الأحمر الأردني </p>
<p> JORDAN RED CRESCENT </p>
</div>
</div>
</div>
</div>
</div>
This how it looks , I tried padding 50% but doesn't work as what i want.
enter image description here
Not sure how exactly you want it. But from what i understand ,you can make use of display:flex here
check this snippet
.header {
background-color: #FFF;
padding: 15px;
}
.row {
display: flex;
justify-content: center;
}
.col-md-4 {
display: flex;
}
.col-md-4:last-child {}
<div class="header">
<div class="row">
<div class="col-md-4 col-md-offset-4 ">
<div class="left">
<img class="logo" src="images/logo.png">
</div>
</div>
<div class="col-md-4 ">
<div class="right">
<span>By</span>
<img src="images/crescent.png">
<div>
<p>الهلال الأحمر الأردني</p>
<p>JORDAN RED CRESCENT</p>
</div>
</div>
</div>
</div>
</div>
Hope this helps

Centering images with text as menu

Im trying to put together some images together with an text under the images which will work as an menu, which should be centered horizontal under an header. The website is supposed to work as an responsive website. The HTML and CSS code is currently looking like this:
Edited
I want 5 images, each one of them shall have a text under them. And I want the my images together with the text to be centered.
HTML
<nav>
<div id="content">
<img src="ikoner/icon_90_2.png"/>
<div class="text">Utvecklingen sedan 90-talet</div>
</div>
<div id="content">
<img src="ikoner/icon_html5.png"/>
<div class="text">HTML5</div>
</div>
<div id="content">
<img src="ikoner/icon_html5video.png"/>
<div class="text">HTML5 Video</div>
</div>
<div id="content">
>img src="ikoner/icon_responsive.png"/>
<div class="text">Responsive Webdesign</div>
</div>
<div id="content">
<img src="ikoner/icon_heart.png"/>
<div class="text">Emotional Design</div>
</div>
</nav>
CSS
#content {
position: relative;
width: 15%;
display: inline-block;
text-align: center;
margin-left: auto;
margin-right: auto;
}
#content img {
padding-top: 370px;
width: 100px;
}
.text {
font-size: 12px;
font-family: 'ciclethin';
text-decoration: none;
}
You're not aligning your "Nav" div anywhere.
So, I've changed the id="content" to classes, because IDs should be unique to the page.
Set nav element to text-align:center. Here's a fiddle, and the relevant code:
http://jsfiddle.net/cw16tkdn/2/
<nav>
<div class="content">
<img src="http://placekitten.com/g/200/200" />
<div class="text">Utvecklingen sedan 90-talet
</div>
</div>
<div class="content">
<img src="http://placekitten.com/g/200/200" />
<div class="text">HTML5
</div>
</div>
<div class="content">
<img src="http://placekitten.com/g/200/200" />
<div class="text">HTML5 Video
</div>
</div>
<div class="content">
<img src="http://placekitten.com/g/200/200" />
<div class="text">Responsive Webdesign
</div>
</div>
<div class="content">
<img src="http://placekitten.com/g/200/200" />
<div class="text">Emotional Design
</div>
</div>
</nav>
and CSS:
nav {
text-align:center;
}
.content {
display: inline-block;
text-align: center;
}
.content img {
width: 100px;
}
.text {
font-size: 12px;
font-family:'ciclethin';
text-decoration: none;
}
maybe you want this: (i have changed id=content with class=content in html code!)
.content {
position: relative;
width: 100px;
display: inline-block;
height: 520px;
text-align: center;
vertical-align:bottom;
}
.content img {
padding-top: 370px;
width: 100px;
display:block;
margin: auto;
}
.text a {
font-size: 12px;
font-family: 'ciclethin';
text-decoration: none;
}
.text {
height: 3em;
}

Why is the div not aligning correctly, vertically?

I want to achieve this (link to full size image):
And I have achieved this (link to full size image):
If you notice, the div that is in right to the left navigation, is not displaying at top, but at bottom. It should start displaying right below the top navigation.
Here is the HTML:
<div id="container">
<div id="header">
<div id="logo">
<img src="images/parislane-ebay-listing-template2_02.png" alt="">
</div>
<div id="top-nav">
<img src="images/parislane-ebay-listing-template2_05_01.png" alt="">
<img src="images/parislane-ebay-listing-template2_05_02.png" alt="">
<img src="images/parislane-ebay-listing-template2_05_03.png" alt="">
<img src="images/parislane-ebay-listing-template2_05_04.png" alt="">
<img src="images/parislane-ebay-listing-template2_05_05.png" alt="">
<img src="images/parislane-ebay-listing-template2_05_06.png" alt="">
<img src="images/parislane-ebay-listing-template2_05_07.png" alt="">
</div>
</div>
<div id="content">
<div id="left-nav">
<div id="left-nav-head">STORE CATEGORIES</div>
<div class="left-nav-link">Category Name</div>
<div class="left-nav-link">Category Name</div>
<div class="left-nav-link">Category Name</div>
<div class="left-nav-link">Category Name</div>
<div class="left-nav-link">Category Name</div>
<div class="left-nav-link">Category Name</div>
<div class="left-nav-link">Category Name</div>
<div class="left-nav-link">Category Name</div>
</div>
<div id="content-right">
item title may go here item title may go here
</div>
</div>
</div>
Here is the CSS:
img{ display:block; }
#container { background-color: #000; width: 100%; overflow:hidden; }
#header { width: 1010px; margin:0 auto 65px auto; }
#logo { width: 1010px; margin-bottom: 13px; }
#top-nav img { float:left; }
#content { width: 1010px; margin:0 auto; }
#left-nav { border: solid 1px #e56bae; width: 188px; }
#left-nav-head { background-image:url(images/parislane-ebay-listing-template2_15.png); height: 22px; padding-left:9px; vertical-align:middle; font-family:Arial, Helvetica, sans-serif; font-size: 13px; color:#000; font-weight:bold; padding-top: 10px; }
.left-nav-link { background-color:#292929; border-bottom: solid 1px #4b4b4b; padding:9px 9px 7px 9px; font-family:Arial, Helvetica, sans-serif; font-size: 12px; color:#fff; }
#content-right { width:805px; margin-left:15px; float:right; color:#fff; text-align:center; }
You need to make the divs float left.
#nav-left, #content-right{
float:left;
}
see fiddle: http://jsfiddle.net/3EJ6k/
block elements take up a full row even if 2 in succession have widths that should theoretically fit side by side, they wont do so unless floated.

CSS padding only displays correctly when element is floated

I'm having issues with a button not displaying correctly, when the element is floated left or right the button displays fine, however if no float is applied the button doesn't display correctly.
I've prepared the following example to demonstrate:
http://codepen.io/anon/pen/xHvyt
My HTML and CSS are as follows:
<div class="section">
<div class="textbox">
<div class="text">
<h1>Woop, title</h1>
<p>content content content</p>
</div>
<div class="buttons">
<span>Find out more</span>
<div class="clear"></div>
</div>
</div>
</div>
<div class="section">
<div class="textbox">
<div class="text">
<h1>Woop, title</h1>
<p>content content content</p>
</div>
<div class="buttons">
<span>Find out more</span>
<div class="clear"></div>
</div>
</div>
</div>
<div class="section">
<div class="textbox">
<div class="text">
<h1>Woop, title</h1>
<p>content content content</p>
</div>
<div class="buttons">
<span>Find out more</span>
<div class="clear"></div>
</div>
</div>
</div>
CSS:
.section .textbox
{
width:25%;
z-index:2;
padding:2.5%;
text-align: center;
background: #4a8237;
}
.section .textbox h1
{
font-weight: 800;
font-size: 275%;
margin:0;
color:#FFF;
}
.section .textbox .text p
{
margin:10% 0;
color:#FFF;
}
.section .textbox .button
{
width: 45%;
text-align: center;
background: url('http://i.imgur.com/dUYP3sP.png');
border-radius: 5px;
display: block;
color:#FFF;
white-space: nowrap;
}
.section .textbox .button.left
{
float:left;
}
.section .textbox .button.right
{
float:right;
}
.section .textbox .button.middle
{
margin:0 auto;
}
.section .textbox .button span
{
display: block;
min-height: 40px;
padding:10%;
margin-bottom:10%;
background: url('http://i.imgur.com/NvJtuDL.png') no-repeat center bottom;
}
As you can see there are three .section divs. In each the ones where the button is floated left/right it displays properly, however when no float is applied it's almost as is the span is not displaying:block;
Thanks in advance for any help.
Changing from "display:block" to "display:inline-block" seems to fix your problem without concerns about the floats.
.section .textbox .button span
{
display: inline-block;
min-height: 40px;
padding:10%;
margin-bottom:10%;
background: url('http://i.imgur.com/NvJtuDL.png') no-repeat center bottom;
}