Trouble with divs as image links floated next to eachother - wordpress

ATTENTION! PROBLEM SOLVED, SOLUTION PASTED BELOW INITIAL QUESTION
on the very top of web page Im working I have on to the left corner a flag (to change language) which I have in a div. On the right I have another div for another image (shop cart) but since I floated the right div, I still go to the right divs address when clicking on the left, like the right overrides the let one. Why? How can I solve this?
Also, I am doing this by using my html/css-files and editing them to fit wordpress for a customer.
CSS
#topmenu img {
margin-left: 25px;
float:left;
position:relative;
}
#cartmenu img {
position:relative;
margin-left: 542px;
}
header.php
<div id="container">
<div id="topmenu">
<img src="wp-content/themes/blank/images/icon_en_global.png" alt="English.png" width="42" height="30">
</div>
<div id="cartmenu">
<img src="wp-content/themes/blank/images/cart.png" alt="cart.png" height="" width="">
</div>
// SOLUTION Set width (in css) to both elements as well a float:left to both elements, then position with margins to get them where you want.
#topmenu img {
margin-left: 25px;
float:left;
position:relative;
width: 42px;
height:45;
margin-top:15px;
margin-bottom:-10px;
}
#cartmenu img {
position:relative;
margin-left: 520px;
float left;
width:350px;
height:40px;
margin-top:-20px;
}

Try to define a width for #topmenu img and giving the cartmenu a float:left; as well.

Related

How to center div while keeping inside divs on same line in css?

I want to center the #nav div on the page. Inside I want the other divs to stay on the same line together separated by my 10+10px margin as is so far. I don't want the inside divs to collapse on separate lines while shrinking the page too small..
http://jsfiddle.net/tH2cc/789/
<iframe width="100%" height="300" src="http://jsfiddle.net/tH2cc/789/embedded/" allowfullscreen="allowfullscreen" frameborder="0"></iframe>
http://jsfiddle.net/tH2cc/789/embedded/result/
Try this:
Take out float:left from the embedded divs
Add white-space:nowrap; display:inline-block; to your container div
Here's modified version: http://jsfiddle.net/9e4hX/
Just set the #nav div to have a fixed width (the total width of the contained elements) and set display to block. Then clear your floats after the elements to keep the #nav div surrounding them. Don't use table-cell as the display.
CSS
#nav { display: block; width: 416px; }
HTML
<div id="nav">
<div id="bark"></div>
<div id="profile"></div>
<div id="read"></div>
<div id="write"></div>
<div style="clear: both;"></div>
</div>
Try this
#nav{
padding:10px;
background-color:rgb(77,77,77);
display: inline-table;
vertical-align:middle;
width: 70%;
margin-left: 15%;
}
check this fiddle
change your container div to display: table not table-cell and add margin: auto
http://jsfiddle.net/3j5kc/
#nav{
padding:10px;
background-color:rgb(77,77,77);
display: table;
margin: auto;
vertical-align:middle;
}

How to add a footer which always shows up at the bottom of the page

I'm looking for a way to add a footer to my page which will always show up at the bottom. The problem is, a lot of the content on the page is set via position: absolute;, so at the moment, unless I manually give the footer a margin-top: 900px; value, its simply hidden by one of the absolute positioned content. But on some pages where the content is less than 900px, there is an unnecessary gap at the bottom between the end of the page, and the footer.
How can I resolve this in such a way that there's no gap between the end of content and footer?
In the new jquery, you can just use this:
<div data-role="footer" data-position="fixed">
<h1>Fixed Footer!</h1>
</div>
from http://jquerymobile.com/demos/1.2.0/docs/toolbars/bars-fixed.html
Put everything before the footer in a div with position relative. This div will flex vertically to the content in it and will provide the buffer to keep anything after it right below it. No margin needed.
You also can put indexes.
z-index: 1;
http://www.fiveminuteargument.com/fixed-position-z-index
In your case, put z-index in css for footer at 10 or more.
Let's suppose a <footer>, styled with display: block and height: 250px.
So all you have to do to achieve what you want is add:
position: fixed;
top: 100%;
margin-top: -250px;
That's it. It'll be permanently aligned at the bottom. :)
Sticky footer. No javascript required:
http://www.cssstickyfooter.com/
After doing some fiddling I was reminded that absolute positioning removes the element from the document flow. You cannot depend on an absolute positioned element to affect the other elements because it will not. Because you do not know the height of the content then using margin-top is clearly not option.
So I came up with this: basically do a normal layout with floats then use position relative to move the items where you want them. This way the elements still affect the document flow, however, now you have total control over the position. This is precisely what relative positioning is for: You want total control over the position of an element but you still want they element to affect the layout normally.
<html>
<head>
<style>
body {
text-align:center;
}
#container {
position:relative;
margin:0 auto;
width: 1000px;
text-align:left;
}
#header {
position:relative;
top:0px;
left:0px;
width:1000px;
height: 100px;
border:solid 1px #000;
}
#sidebar {
position:relative;
top:10px;
left:0px;
width:300px;
height: 500px; /* for demo */
float:left;
margin-bottom: 20px;
border:solid 1px #000;
}
#main {
position:relative;
top:10px;
left:310px;
width:690px;
height: 200px; /* for demo */
margin-bottom:20px;
border:solid 1px #000;
}
#footer {
margin:0 auto;
top:20px;
width: 1000px;
text-align:left;
height: 100px;
clear:both;
border:solid 1px #000;
}
</style>
</head>
<body>
<div id="container"> <!-- Holds all the content except the footer -->
<div id="header">Header content here</div>
<div id="sidebar">Sidebar content here</div>
<div id="main">Main content here</div>
</div>
<div id="footer">Footer content here</div>
</body>
</html>

CSS center layered dynamic divs

This css has been somewhat difficult to figure out...Basically what I want is what is in this picture, but with dynamically changing content.
so I set up my html like this, basically all the elements are piled into the wrapper, the pictures and titles will be dynamically rotating and will be different widths and heights:
<div id="wrapper">
<div id="title"><h2></div>
<div id="image"><img></div>
<div id="leftbutton" class="but"><img></div>
<div id="rightbutton" class="but"><img></div>
</div>
Everything I have tried Hasn't worked out. how should I go about this?
The closest I have got is this, but the title field can change heights and that makes this method not work, since, I have to position the image relatively and its relative position changes with the title element growing and shrinking:
#wrapper{
position:relative;
text-align: center;
}
.but{
z-index:20;
position:absolute;
}
#leftbutton{
left:0px;
}
#rightbutton{
right:0px;
}
#title{
z-index: 3;
display: inline-block;
width:auto;
min-width: 80px;
max-width: 340px;
}
#image{
z-index: 1;
position: relative;
top:-21px;
}
If you mean the Title in the center use this way:
#title {
margin: 0 auto;
width: /* your width */
}
the position should be relative at the wrapper.
JsFiddle UP
I just reorganized the body structure, adding one more div and floating everything.
Then inside the central section I added title and image that you can style to be centered to the relative div.
If you provided some example code we would better be able to assist you. In the meantime, the following code should take care of what you're looking for:
HTML
<div id="wrapper">
<div id="title"><h2>Article Headline</h2></div>
<div id="image"><img></div>
<div id="leftbutton"><img></div>
<div id="rightbutton"><img></div>
</div>​
CSS
​#wrapper {
background:#6cb6d9;
display:inline-block;
position:relative;}
#title {
position:absolute;
top:0;
width:100%;
text-align:center;}
#title h2 {
background:green;
color:white;
padding:10px 15px 10px 15px;
display:inline-block;
max-width:200px}
#image {}
#image img {
min-width:200px;
height:300px;
width:500px; }
#leftbutton {
position:absolute;
left:0;
top:0;
height:100%;
width:75px;
background:black;}
#rightbutton {
position:absolute;
right:0;
top:0;
height:100%;
width:75px;
background:black;}
Though instead of hardcoding the img size, just remove those lines of CSS to have the div automatically adjust to the default size of the img.
http://jsfiddle.net/b7c7c/
None of these solutions worked correctly, ultimately the way to get it to work is with this trick: How to center absolutely positioned element in div?
Then you just position all elements absolutely within the wrapper and the sub elements relatively as seen in the post

Make the image inside a div appear behind its div background

I have a div that has background that is partly transparent with a watermark. Inside of the div I'm calling an image but I want that image to appear behind the background of the div so I can have the watermarked transparent div background appear over the image. Is that possible? Here's the css that I have that isn't working...
.artist-container {
background:url(images/artist-back.png);
width:310px;
height:376px;
margin-left:-9px;
z-index:331;
position:relative;
}
.artist-container img {
width:300px;
height:300px;
margin-left:5px;
z-index:330;
position:relative;
}
By giving .artist-container a higher z-index, you are placing it higher in the stacking order than the child image, though children always have a higher z-index than their parents.
If you want to give the effect of a watermark, you can:
Make the image the background of the div and place an image watermark inside it.
Position another div within .artist-container absolutely, with the same dimensions as that of the image and with a higher z-index of the image, with the watermark as the background.
I whipped up a small sample using some spans, which won't add any semantic content to your document and will still maintain the semantic meaning of your image.
HTML:
<span class="cover_contain">
<img src="http://i.imgur.com/hla4q.jpg" alt="[image]" width="128" height="128" />
<span class="cover_image"></span>
</span>
CSS:
span.cover_contain {
display: inline-block;
position: relative;
}
span.cover_image {
display: block;
background: url('http://i.imgur.com/5BtFV.png') center center no-repeat;
width: 128px;
height: 128px;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
jsFiddle Live Preview
make the image as the background-image of the div and the watermark as the img
it's not possible to put a background in front of an image of the image is in that element. You can simply use the main image as background, or:
what you could do
<div class="holder">
<img src=".." class="main_image">
<img src=".." class="watermark">
</div>
.holder {
width:100px;
height:100px;
position:relative;
display:block;
}
.main_image {
position:absolute;
top:0;
left:0;
z-index:0;
}
.watermark {
position:absolute;
top:0;
left:0;
z-index:9;
}
You can use the negative z-index, but in that case you must have the wrapper not to have any z-index. It's one of the features of stacking context.
Here is a demo fiddle: http://dabblet.com/gist/1731538
And the code for you would be something like this:
.artist-container {
background:url(images/artist-back.png);
width:310px;
height:376px;
margin-left:-9px;
position:relative;
}
.artist-container img {
width:300px;
height:300px;
margin-left:5px;
z-index:-1;
position:relative;
}

Placing a div sidebar next to a centered div

I've found a lot of variations to this question within SO, but it seems no matter what I try I can't get this (seemingly very simple!) thing working!
What I'm trying to do is to keep the 'centered' div in the center of the viewport and to place the 'sidebar' div directly to its right (i.e. not right-aligned to the viewport) without affecting the centering of the 'centered' div.
Here's some test code on jsfiddle:
http://jsfiddle.net/6wCyr/13/
Everything I've read seems to imply that the float property is exactly what I'm looking for, but the results in the link show that I get weird results wherein the right sidebar is placed below the 'centered' div rather than beside it. That's what's shown in the link.
I've also seen a solution involving using a negative value for the right property, and setting the width of the sidebar exactly, but I couldn't get that one going either.
Hopefully this question is as easy to solve as I think it should be! Just can't seem to find the right set of div inside div and so forth. Hard to debug these alignment issues!
Thanks!
Live Demo
I moved div.sidebar inside div.centered.
I added position: relative to div.centered.
We're using this technique.
You don't have to declare a fixed width on div.sidebar.
CSS:
div.centered {
margin-left: auto;
margin-right: auto;
border: dashed;
width: 100px;
height: 100px;
position: relative
}
div.sidebar {
border: dotted;
position: absolute;
top: 0;
left: 100%
}
HTML:
<div class="holder">
<div class="centered">
CENTERED
<div class="sidebar">
RIGHT SIDEBAR
</div>
</div>
</div>
Try this.
http://jsfiddle.net/DOSBeats/6wCyr/16/
.holder {
margin:0 auto;
width:100px;
}
.centered {
border: dashed;
float:left;
height: 100px;
}
.sidebar {
border: dotted;
float:left;
margin-right:-100px;
width:100px;
}
If you do not set a width to your holder and center it, the sidebar will float to the edge of the window.
Try this:
HTML:
<div id="holder">
<div id="sidebar">Sidebar</div>
<div id="centered">Centered</div>
</div>
CSS:
#holder{
margin:auto;
width:500px;
}
#sidebar{
border:dotted;
float:left;
width:100px;
}
#centered{
border:dashed;
margin-left:110px;
width:380px;
}

Resources