Positioning social icons on a navigation bar - html

This is what my page currently looks like: Here
I want the social icons to position in line with the rest of the navigation content. At the moment they are beneath the content. I thought float right would fix things. Is it because of my browser size? How can I fix this then? Here is my code:
HTML:
<div id="Nav">
<div id="NavContent">
<ul>
<li id="Title">PavSidhu.com</li>
<li>Home</li>
<li>Web Design</li>
<li>Graphic Design</li>
<li>How it Works</li>
<li>Pay</li>
<li>Contact</li>
</ul>
<img src="Images/Twitter.png" class="Social"/>
<img src="Images/Pinterest.png" class="Social"/>
</div>
</div>
CSS:
#Nav {
position:fixed;
width:100%;
background-color:#f26522;
}
#NavContent {
margin:0 auto;
width:90%;
}
ul {
margin:0;
padding:0;
}
li {
font-family: Bebas;
color:#FFF;
list-style-type:none;
margin:0;
padding:0 1%;
display:inline;
vertical-align:middle;
font-size:20px;
}
#Title {
font-size: 35px;
}
.Social {
height:35px;
float:right;
}
Thanks guys :)

The <ul> is a block element, so it wants to be 100% width by default. If you make it an inline element with display: inline; instead, there will be space for the icons to sit next to the rest of the nav bar.
ul {
margin:0;
padding:0;
display: inline;
}

You mean you want the social-media-icons higher? Next to the menu-items instead?
Try using
display: inline-block;
for your ul.

set ul to display: inline-block

As explained earlier, ul is a block element that will take 100% of the width of the parent element, so the floated elements will start on the next line.
To fix this, you can use:
ul {
margin:0;
padding:0;
border: 1px solid blue; /*for demo only */
display: inline-block;
width: inherit;
}
See demo at: http://jsfiddle.net/audetwebdesign/tAjW8/
You need to set width: inherit or else the computed width will be narrower than you might expect.

Related

How can I align these divs horizontally along the top?

Each div contains a list of varying lengths and because I'm using inline-block. I think it's causing it to align along the bottom of the div with the most height.
Is there a way I can align these div along the top or will I need to give each div a unique id and style them each accordingly?
I made a fiddle here:
http://jsfiddle.net/Bezzzo/dcqmh2g2/1/
HTML
<!-- footer -->
<div id="footer" >
<!--Community div-->
<div>
<h3>Community</h3>
<ul>
<li>Facebook</li>
<li>Twitter</li>
<li>Tumbler</li>
<li>Google plus</li>
</ul>
</div>
<!--Contact support div-->
<div>
<h3>Contact support</h3>
<ul>
<li>support#supportsupport.com.au</li>
</ul>
</div>
<!--Legal div-->
<div>
<h3>Legal</h3>
<ul>
<li>Terms and conditions</li>
<li>Refund policy</li>
<li>Privacy Policy</li>
</ul>
</div>
</div>
CSS
#footer {
position: relative;
width:1033px;
height: 160px;
margin:auto;
border-style:dashed;
}
#footer div {
display:inline-block;
position: relative;
margin-left: 150px;
border-style:dashed;
}
#footer ul {
list-style-type: none;
padding:0px;
margin:0px;
left:0px;
right:0px;
}
Thank you
Just add vertical-align: top; to your #footer div:
#footer div {
border-style: dashed;
display: inline-block;
margin-left: 150px;
position: relative;
vertical-align: top;
}
JsFiddle: http://jsfiddle.net/ghorg12110/dcqmh2g2/3/
As an alternative you can also display: table; — Really useful if you want to make use of vertical align. It may not be best for your current situation but it has it's merits.
#footer {
position: relative;
width:1033px;
height: 160px;
margin:auto;
border-style:dashed;
/* added */
display: table;
/* -- */
}
#footer div {
/* added */
display: table-cell;
vertical-align: top;
/* -- */
position: relative;
border-style:dashed;
}
Working example
Just float left all the div and specify them a width but you need to clear div for this. If you want to use inline block then you don't need to specify width and clear left. In this case you can use vertical-align:top to footer div
JsFiddle : Using float left
JsFiddle : Using inline block
remove display:inline-block from #footer div and use
#footer ul li { display:inline-block;float: left;}
or just
#footer ul li {display:inline-block;}
in your style

Proper way to bottom align text of different font sizes in adjacent blocks?

I have text in adjacent blocks where the font sizes are different, but I want the text in both to be bottom aligned with each other. More specifically, I want the section vertically centered within the header, but I want the text within h1 and nav to have their bottom edge aligned. I can tweak margins or absolute positioning to get the second block's text aligned with the first, but the alignment breaks as soon as I zoom the page. I have a codepen, and here's the code:
HTML:
<header>
<section>
<h1>SITENAME</h1>
<nav role="navigation">
<ul>
<li>home</li>
<li>about</li>
<li>stuff</li>
<li>blog</li>
</ul>
</nav>
</section>
</header>
CSS:
header { width:100%; background-color:#ddd; }
header section {
width:80%;
max-width:980px;
margin:0 auto;
position:relative;
}
header section h1, header section nav {
margin:20px 0 20px 0;
display:inline-block;
}
header section h1 { font-size:2em; }
header section nav {
position:absolute;
right:0;
text-align:right;
}
nav ul { margin:0; padding:0;}
nav li { display:inline; }
nav li a { margin-left:2em; text-decoration:none; }
body { margin:0; font-family:sans-serif; }
Ideas? Seems like this must be a common need but I'm not finding it.
Using css transform will help.
Here's a jsfiddle http://jsfiddle.net/claytonF/34wcu10e/1/
header {
width:100%;
background-color:#ddd;
}
header section {
width:80%;
max-width:680px;
margin:0 auto;
position:relative;
}
header section h1, header section nav
{
margin:20px 0 20px 0;
display:inline-block;
}
header section h1, header section nav, header section nav li a
{
height:2em;
}
header section h1 {
font-size:2em;
}
header section nav {
position:absolute;
right:0;
text-align:right;
}
nav ul { margin:0; padding:0;}
nav li {
display:block;
position:relative;
float:left;
}
nav li a {
margin-left:2em;
text-decoration:none;
display:block;
transform:translate(0%,50%);
-webkit-transform:translate(0%,50%);
-moz-transform:translate(0%,50%);
-o-transform:translate(0%,50%);
}
body { margin:0; font-family:sans-serif; }
<header>
<section>
<h1>SITENAME</h1>
<nav role="navigation">
<ul>
<li>home</li>
<li>about</li>
<li>stuff</li>
<li>blog</li>
</ul>
</nav>
</section>
</header>
I did have to set a height for the H1, nav and nav li a elements. Don't know how to avoid that. I just set them to the height of the H1 text (2em).
Then set the nav li's to display:blockand float:left then applied transform:translate(0%,50%);to the nav li a element.
Hope that helps.
If you put both h1 and <nav> to be display:inline-block you'll get along the default vertical-align: baseline; (by default) which will align the texts of your elements exactly as you need them: http://jsbin.com/zohupu/1/edit?html,css,output
Otherwise if you set an element to position:absolute you remove it from it's natural flow and all you can do is approximate:
header section nav {
position:absolute;
right:0;
line-height:3.1em; /* added */
/*text-align:right; not needed */
}

How to align floated buttons in same row

I am trying to align the button and links in floated UL list. However it seems they are not getting properly aligned. [Note: we have one link and other is form button].
Following is code and link to codepen:
<div>
<ul>
<li>
<button>Hello</button>
</li>
<li>
Delete
</li>
</ul>
</div>
div{
background:yellow;
overflow:hidden;
}
ul li{
float:right;
list-style:none;
}
a, button{
padding: 4px;
border:1px solid green;
margin-left:5px;
font-size:12px;
text-align:center;
}
The reason your li elements aren't getting aligned properly is because of what's inside them.
You have one button and one a-tag. Buttons are by default displayed as a block-element while a-tags are displayed as an inline-element.
This results in your button and your link having different padding because top/bottom padding doesn't show on inline elements.
You can easily solve this by adding display: block; or display: inline-block; to your css rule.
div{
background:yellow;
overflow:hidden;
}
ul:after{content: '.'; visibility:hidden; height:0; display:block; clear:both;}
ul li{
float:right;
list-style:none;
}
a, button{
padding: 4px;
border:1px solid green;
margin-left:5px;
font-size:12px;
display: inline-block;
}
<div>
<ul>
<li>
<button>Hello</button>
</li>
<li>
Delete
</li>
</ul>
</div>
use display:inline-block instead of float
the issue was because of float:right by using display:inline-block element adjusts to the width of its children and you can align it by adding text-align
div {
background: yellow;
overflow: hidden;
text-align:right;
}
ul li {
display: inline-block;
list-style: none;
}
a,
button {
padding: 4px;
border: 1px solid green;
margin-left: 5px;
font-size: 12px;
}
<div>
<ul>
<li>
<button>Hello</button>
</li>
<li>
Delete
</li>
</ul>
</div>
pls give display:block for a(anchor) tag.if you use padding or margin(etc..) in anchor tag.we need to use display.

Positioning and Floating aren't working?

I've tried numerous of things to fix this. I cannot seem to get the nested div inside the parent div without having to use margin. I'm trying to get it in the regular way which is position:relative on parent and position:absolute on nested. It's not working though, anybody know why?
HTML
<div class="header">
<div class="logo">
<img src="/images/logo.png" width="96" height="82">
</div>
<div id="nav">
Portfolio
About
Contact
</div>
<div id="headerPro">
</div>
</div>
CSS
.header {
position:relative;
background-color: #2C2E31;
border-bottom: #242426 2px solid;
height: 182px;
}
.logo {
text-align: center;
padding-top: 35px;
}
#nav {
position:absolute;
bottom: 0;
width: 100%;
text-align:center;
text-decoration:none;
font-size:20px;
font-family:raleway-regular;
}
#nav a {
border-bottom:#FFFFFF 2px solid;
color:#FFFFFF;
text-decoration:none;
margin-left: 8px;
margin-right:8px;
}
#headerPro {
position:absolute;
float:right;
width:100px;
height:100px;
background-color:red;
}
It's hard to tell what exactly you want it to look like, but maybe I got you right:
I revised your HTML code to use ul for the nav which is best practice:
<div class="header">
<div class="logo">
<img src="/images/logo.png" alt="logo"/>
</div>
<ul id="nav">
<li>Portfolio</li>
<li>About</li>
<li>Contact</li>
</ul>
<div id="headerPro">
</div>
</div>
With that your css code could look like that:
.logo > img {
display: inline-block;
width: 96px;
height: 82px;
}
#nav {
position:absolute;
list-style-type: none;
bottom: 0;
width: 100%;
text-align:center;
text-decoration:none;
font-size:20px;
font-family:raleway-regular;
}
#nav > li {
display: inline;
}
#headerPro {
position:absolute;
top: 35px; /* assuming you want this to line up with the logo */
right: 0;
width:100px;
height:100px;
background-color:red;
}
Here is a demo.
See this fiddle
Example
I have made two changes added a float:left to the logo css:
.logo {
float:left;
}
and removed the position:absolute from the header pro css
Your div is flowing outside the header block because of the logo div, if you make that float left (as I have done in the fiddle) the Red Div will move up.
It would help if you could explain exactly where you want the #HeaderPro div..
Apparently the browser positions your div#headerPro just below the previous(sibling) div. If you want it to be part of the parent div, add top:2% to position the red div in the top right corner of the black div.
#headerPro {
position:absolute;
float:right;
width:100px;
height:100px;
background-color:red;
top: 1%;
}

html center align not working

I am trying to align the ul to the center of the div, it's not working here is my HTML code is:
<div id="container">
<div id="footer">
<ul id="footer_links">
<li>About</li>
<li>Faq</li>
<li>How Rang De Works</li>
<li>Contact</li>
<li>Support</li>
</ul>
</div>
<div>
My CSS is:
#container {width:975px;margin:0 auto;}
#footer {text-align:center;}
ul#footer_links {margin:0px;text-align:center;}
ul#footer_links li {float:left; list-style:none; padding:10px 0px 0px 20px;}
Link to HTML code
Remove float: left from ul#footer_links li and use display: inline instead
JSFiddle: http://jsfiddle.net/Efbjv/1/
text-align:center; is just to align pure text inside an element. If you want to center a block elements, you should use margin-left: auto;margin-right: auto; in the element that will be centered.
#footer{
text-align:center;
}
ul#footer_links{
margin:0px auto;
width:90%;
}
#container{width:975px;margin:0 auto; border:1 px solid #000;}
#footer{text-align:center;}
ul#footer_links{margin:0 auto; text-align:center;}
ul#footer_links li{ list-style:none; display:inline; padding:10px 0px 0px 20px;}
Should solve the problem, changed ul#footer-links to be centered instead and the li element is now inline so it doesn't make a linebreak after each li.
The CSS property text-align only affects inline elements, not block elements. So you have to make your ul and li elements inline, like:
#container{ width:975px; margin:0 auto; }
#footer{ text-align:center; }
ul#footer_links{ margin:0px;text-align:center; display:inline; }
ul#footer_links li{ display:inline; list-style:none; padding:10px 0px 0px 20px; }