CSS Element positioning - css

I freely admit right up front that I am not blessed with even a speck of design ability. Nonetheless, I find myself hacking through CSS for a simple website. I've run into a problem and for the life of me I can't figure out the issue. The basics...
I have a <div> that contains the entire page and sets the boundaries. The width is set at 1200px. After a other elements I have a links bar that spans the width of the page. This is in a <div> with the id "pinkbar". The "pinkbar" has a width set to 100%, which would be 100% of the 1200px containing division. I created small padding on the left and larger padding on the right to properly position elements within the bar. I need to add one element to the left, a simple text telephone number, and then several links to the right. I put the telephone # in it's own <div> with the id of "pinkphone", and floated that <div> to the left. Worked perfectly. Now I start to add the links. I created a <div> named "pinktest" for the first link, added a border and the text link inside of the division and floated it to the right. And that is where thinks stopped playing nicely. The link division, "pinktest", floats to right about 50px beyond the border of it's containing division, and about 100px to the right beyond that border if you factor in the padding. I've played and tinkered with this to the best of my limited ability and have found no love at all. If someone can offer a suggestion as to how to make this work please do. I still need to add four more links, all floated right, along with the "pinktest" one. Relevant code below:
The CSS:
#pinkbar{
background-image: url(../visual/pinkMenuBar.jpg);
background-repeat: no-repeat;
padding-top: 0px;
padding-left: 30px;
padding-right: 100px;
margin-top: 0px;
margin-left: auto;
margin-right: auto;
width: 100%;
height: 25px;
}
#pinkphone{
padding-top: 3px;
padding-left: 0px;
padding-right: 0px;
padding-bottom: 0px;
margin-top: 0px;
margin-left: auto;
margin-right: auto;
margin-bottom: 0px;
float: left;
width: auto;
height:25px;
}
#pinktest{
padding-top: 3px;
padding-left: 4px;
padding-right: 0px;
padding-bottom: 0px;
margin-top: 0px;
margin-left: auto;
margin-right: auto;
margin-bottom: 0px;
border-left-width: 1px;
border-left-style: solid;
border-left-color: grey;
float: right;
width: auto;
height:25px;
}
The HTML:
<div id="pinkbar">
<div id="pinkphone">
<span class="cambria3black">Tel: 416 450 4460</span>
</div>
<div id="pinktest">
<span class="cambria3black">
Testimonials
</span>
</div>
</div>

Here is simplified example of what I think you might be looking for:
HTML:
<nav>
<ul class="links">
<li>Link 1</li>
<li>Link 2</li>
</ul>
<ul class="info">
<li>Telephone Number</li>
<li>Link 3</li>
</ul>
</nav>
CSS:
nav {
padding: 1em;
}
.links {
float: left;
}
.info {
float: right;
}
nav li {
display: inline;
padding: 1em;
}
You can add as many links as you want.
Demo

A floated element will move as far to the left or right as it can. Usually this means all the way to the left or right of the containing element.
CSS W3schools
So in fact, the pinktest div is inside the pinkbar division.
You should change the css of pinktest to:
float: left;
Because pinkbar div is using 100% of the page, pinktest would go as far right as possibl. Now it will go as far left as possible, ie. next to pinkphone.

Related

How to show a div behind navigation on rollover

I'm still trying to get the hang of this web coding thing. Lord knows there is no knowing it all. SO, I'm reaching out in hopes of some help.
I have a div containing a <nav>, and let's say this nav has a <ul> with <li>'s inside it....
How would I go about making a picture appear behind the navigation based on the li highlighted.
Say I have a vertical menu:
Home | Gallery | Contacts
and I want the images to extent freely. Lets say Mario appears in behind contacts on rollover. I want his head to overlap Gallery, but he should be behind Contacts. I do intend for these images to be to the far left so as not to interfere to badly with navigation. Can I do this with JUST CSS or will I need jQuery.
Is this what are you looking for http://jsfiddle.net/rMCMt/ ?
You can use first-child and nth-child selectors: http://jsfiddle.net/Qq9Nm/
As menu items have different widths, you have to adjust the padding and the margin individually.
The CSS code, below:
li
{
box-shadow: 4px 4px 2px grey;
margin: 10px;
list-style-type: none;
float: left;
}
li:first-child:hover,
li:nth-child(2):hover,
li:nth-child(3):hover,
li:nth-child(4):hover,
li:nth-child(5):hover
{
background-size: 200px 200px;
background-repeat: no-repeat;
padding-bottom: 180px;
margin-bottom: -170px;
}
li:first-child:hover
{
background-image: url('http://goo.gl/RqQtl');
padding-right: 145px;
margin-right: -135px;
}
li:nth-child(2):hover
{
background-image: url('http://goo.gl/TWI0t');
padding-right: 130px;
margin-right: -120px;
}
li:nth-child(3):hover
{
background-image: url('http://goo.gl/xRPiq');
padding-right: 115px;
margin-right: -105px;
}
li:nth-child(4):hover
{
background-image: url('http://goo.gl/u3Akz');
padding-right: 140px;
margin-right: -130px;
}
li:nth-child(5):hover
{
background-image: url('http://goo.gl/Em9Ij');
padding-right: 140px;
margin-right: -130px;
}
and the html:
<nav>
<ul>
<li> HOME </li>
<li> GALLERY </li>
<li> CONTACTS </li>
<li> EXTRA1 </li>
<li> EXTRA2 </li>
</ul>
</nav>

float css only menu - how to modify on section2

Hell o, I have floating menu fixed on top of the screen of my single page web site. When I click the menu item, page slowly scrolls down to appropriate section using jquery. I have this code for fixed menu on top of the screen:
<style>
.fixed_elements{ position:fixed; top:100px; }
#top-floating-bar{ background: none repeat scroll 0 0 #2D2D2D; height: 35px; position: fixed; top: 0; width: 100%; z-index: 100; }
ul{ padding: 0; margin: 0; }
.fixed-bar-buttons{ float: left;color: #fff; }
.fixed-bar-buttons ul { height: 25px; padding-right: 10px; }
.fixed-bar-buttons ul li{ display: block; float: left; font-family: sans-serif; font-size: 14px; font-weight: bold; height: 25px; padding-left: 10px; padding-right: 10px; padding-top: 10px; }
.fixed-bar-buttons ul li:hover{ background-color: #605F5F; }
#content-panel{ float: left;margin-top: 40px; }
</style>
</head>
<body>
<div id="top-floating-bar">
<div class="fixed-bar-buttons">
<ul class="nav">
<li>REFERENCIE</li>
<li>KONTAKT</li>
</ul>
</div>
</div>
<div id="section2"> Section2 content</div>
<div id="section3"> Section3 content</div>
...
The code is OK and everything works fine. The thing I need to do is to modify the menu when it's on section2 and section3 only and add "UP" button.
When I load the page, I don't need the "UP" button, because It's not possible to go up and it's confusing to be there, so I need it only if I scroll down. Is it possible with CSS(1,2,3) only? Thank you!
Not possible, because you have to fetch the vertical offset of the document to know if the user is at the top of the page, or have scrolled down. The vertical offset is needed to make the decision whether to display the up button or not.
There is a way to do it with JS, but if you're asking for a CSS-only solution, I've given you the bad news already :P

website header hiding behind content when position is fixed

I am designing a website for a school and I want the header of site to be fixed just like facebook has. I tried the fix provided by this question on stackoverflow but it was hardly of any use in the header. I have an image, basically the logo of the school, where I do position: fixed, but
the header hides behind the page.
HTML:
<body>
<div id="header" > <img src="images/iesheader_nnew1.jpg" /></div>
<div id="menu">
<ul>
<li><abbr title="Home">Home </abbr></li>
<li> <abbr title="About Us">About Us </abbr> </li>
<li><abbr title="Academics">Academics</abbr></li>
<li><abbr title="Administration">Administration</abbr></li>
<li><abbr title="News">News</abbr></li>
<li><abbr title="Contact Us">Contact Us</abbr> </li>
<li><abbr title="Photo Gallery">Photo Gallery</abbr> </li>
</ul>
<div class="cleaner"></div>
</div>
CSS:
#header {
margin-left: 0px;
width: auto;
height: 90px;
padding: 0px;
padding-left:185px;
font-size: 35px; color:#FFFFFF;
background-color: #f6c491;
position: fixed;
top: 0;
left: 0;
right: 0;
}
#menu {
position: relative;
clear: both;
width: auto;
height: 38px;
padding: 0;
padding-left:185px;
background-color:#FFFFFF;
margin-bottom: 10px;
margin-left:0px;
}
#menu ul {
float: left;
width: 960px;
margin: 0;
padding: 0;
list-style: none;
}
#menu ul li {
padding: 0px;
margin: 0px;
display: inline;
}
#menu a {
float: left;
display: block;
padding: 8px 20px;
font-size: 14px;
font-weight: bold;
text-align: center;
text-decoration: none;
color: #000;
outline: none;
border: none;
border-top: 3px solid black;
}
I tried a number of solutions to that, but whatever I do, the header goes behind the page. I want the menu bar also to be fixed but it also is the same...
Add z-index:1000 to the #header css, and add padding-top to the body css which should be a bit more than header's height. For example, if the header's height is 40px, put the padding-top: 50px to the body css and it should work.
When you add position fixed and/or absolute to a element, it means that the element will leave the natural flow and now it belongs to "layer" that is not related to the layer where all the elements are with the natural flow of the document.
This is a great feature as now you can position those elements anywhere without worring about the rest of the page.
So, about your case. You picked the right position, fixed. Now the elements above it doesn't see it and you have to manually add the height of this header element as a margin and/or padding to the top of the next element.
For example, if you had the following:
<div class="header"></div>
<div class="content"></div>
Repeating what you did add a position fixed to header and considering that it's height is 50 px the content element would get a padding-top:50px and it should do the trick.
<style>
.header{position:fixed;top:0;height:50px;}
.content{padding-top:50px;}
</style>
You can use z-index
Which element that you want to be in front of other elements, give the z-index value higher.
Like this:
z-index: 300;//navbars
z-index: 0;//contents
When you set the an element to have a fixed positioning, It assumes the other neighbouring elements don't exist. Give the element you want to be fixed a larger z-index. Then to prevent the overlapping, give the element preceded by the fixed element the same padding-top as the height of the fixed element. Hope it helps.
CSS Z-index might be your solution
http://www.w3schools.com/cssref/pr_pos_z-index.asp
#header {
margin-top:-38px; //solution
margin-left: 0px;
width: auto;
height: 90px;
padding: 0px;
padding-left:185px;
font-size: 35px;
color:#FFFFFF;
background-color: #f6c491;
position: fixed;
top: 0;
left: 0;
right: 0;
}

Text on footer Bar

My website URL is http://www.hentaireader.com
At the bottom right corner, I wish to put a small link on the red footer bar.
I have created a simple image of what I wish to do.
How can I achieve this??
The code on this page is a disaster. With that said you would have to remove the http://www.hentaireader.com/images/bar.gif image from the HTML and use CSS to create a background-image.
Something similar to this would be required...
CSS:
#footer-bar {
width:100%;
background-color:#f40000;
background-image: url(http://www.hentaireader.com/images/bar.gif);
background-position:top center;
background-repeat:no-repeat;
text-align: right;
margin-bottom: 10px;
}
#footer-bar ul {
width: 950px;
height: 30px;
margin-left: auto;
margin-right: auto;
position: relative;
left: 0px;
top: 0px;
}
#footer-bar li {
display: inline;
line-height: 30px;
margin-left: 6px;
}
#footer-bar li a {
color: #FFFFFF;
}
HTML:
<div id="footer">
<div id="footer-bar">
<ul>
<li>Contact</li>
<li>Another Link</li>
</ul>
</div>
All characters on hentaireader.com are purely fictional and 18+ years of age.
</div><!--- FOOTER --->
Look here... http://jsfiddle.net/b8Xh7/1/
Ok, well first of all. Do you see the red bar? You have a div inside of the div you have an image. You should have put the (red bar) image as a background, and put a link inside the div. Then you could haver positioned the link where you wanted it with padding/margin.
#footer a {}
Example

CSS: problem with Float property

Here is my problem with CSS when I use the Float property
My picture: http://www.sourimage.com/show-image.php?id=fb748238bf7e4ab12001e64cb543066b
It does not look good because having many blank space among the block.
My CSS code:
.listcol{
width:180px;
float:left;
margin-right:5px;
background-color:#eceff1;
margin-top: 1px;
min-height:200px;
background-image: url(../images/colbg_btm.gif);
background-repeat: no-repeat;
background-position: bottom;
margin-bottom: 0px;
}
.listcol ul{
margin-left: 0px;
padding-left: 0px;
padding-top: 0px;
margin-top: 0px;
list-style-type: none;
}
Please take a look to review and help me to correct no any blank space on the screen!
Thanks so much!
Can't see the picture, but maybe if you express the width as a percentage of the width of the page...Instead of 180px, maybe
width: 80%;
..using whatever percentage looks best to you.
I think we need to see your html markup to be sure, but what you need to do is have a structure where block1 and block3 are in a container block. The container can float, and block2 can float. Block1 and block3 do not need to float.
can you post some of the html? Or fix the image? It looks like you took care of the left margin for your UL, but there may some extra margin lying around in some of your other block elements since they tend to come with built in margin.
i also agree with Robert Harvey. Try to use percentages where reasonable instead of pixels. it'll be more consistent across any changes the user or browser makes to screen size, font size, etc.
are block1, 2, and 3 all UL's in the listcol div?
I think u can solve your problem by giving line-height to li as "0px".
ul li {
float:left;
line-height:0px;
}
ul {
width:124px;
}
<ul>
<li><img src="images.jpeg" /></li>
<li><img src="images.jpeg" /></li>
</ul>
The space can't be avoided in current solution because it's the height of the block2 that's "pushing" down block3 when it's floated to to left.
So you will probably need a completelly different html layout to solve your request...
Please show us som more samples of how you want the page to look with more li elements of different heights.
Huynh:
You need to wrap a div around each of your columns. That should allow the boxes to flow from top to bottom within their own div, and then you can float each of the div columns. Give each div a width of 25%. You might also want to wrap the whole thing in a div, and give it a width of 100%.
I try to work around on your ideas but It's not fine.
Also, I put my HTML as below:
#content02{
width:740px;
float:left;
margin-left: 10px;
}
.wrapper{
width:760px;
margin-left:auto;
margin-right:auto;
}
.main02{
width:760px;
float:left;
background-color:#FFFFFF;
padding-bottom:20px;
padding-top: 10px;
}
.listcol{
width:180px;
float:left;
--position: absolute;
margin-right:5px;
background-color:#eceff1;
margin-top: 1px;
min-height:200px;
margin-bottom: 0px;
}
.listcol ul{
margin-left: 0px;
padding-left: 0px;
padding-top: 0px;
margin-top: 0px;
list-style-type: none;
}
.listheader{
display: block;
margin-top: 0px;
background-color: #2F404A;
color: #FFFFFF;
font-weight: bold;
font-size: 10px;
width: 180px;
padding-top: 5px;
padding-bottom: 5px;
background-position: top;
text-align: center;
}
<div class="wrapper">
<div class="main02">
<div id="content02">
<div class="listcol">
<ul>
</ul>
</div>
<div class="listcol">
<ul>
</ul>
.....
.....
</div>
Please to note that the number of block increasing dynamically and use the same style "listcol". You can see the picture depicting this issue here: http://www.sourimage.com/show-image.php?id=fb748238bf7e4ab12001e64cb543066b
Please try getting rid of "min-height" in the '.listcol'. Also, get rid og the "position: absolute" in the '.listcol'.
Let me know if that worked.
If it doesn't, you can try to modify your HTML to be in columns, so for example:
<div class="column">
<div class="box"></div>
<div class="box"></div>
</div>
<div class="column">
<div class="box"></div>
<div class="box"></div>
</div>
And the CSS:
.column{
float: left;
width: 200px;
margin-right: 5px;
}
.box{
margin: 0px;
}

Resources