How to change div1's image when hovering over div2? - html

I've been trying to code this tumblr page of mine and I'm currently stuck at the links section. I want my sidebar image to change when I'm hovering over my links, the "HOME", "ASK" etc. Is it possible to do this without using javascript? I've googled it but I haven't been able to come up with a solution, having tried adding different image classes, etc. All I've been able to do is have images appear UNDER the links. I've added the sidebar and links code from my page below. Thanks in advance!
#sidebar {
position:fixed;
width:203px;
top:70px;
left:70px;
height:auto;
padding:15px;
background-color:#1c1c1c;
}
#sidebarimg img {
width:203px;
padding-bottom:5px;
}
#links {
width:203px;
height:auto;
margin-left:auto;
margin-right:auto;
font-family:times;
text-align:center;
text-transform:uppercase;
opacity:2;
}
#links a {
margin-top:1px;
margin-bottom:2px;
border:1px solid #fff;
width:98px;
display:inline-block;
color:#999999;
padding-top:5px;
padding-bottom:5px;
font-size: 13px;
-moz-transition-duration:0.8s;
-webkit-transition-duration:0.8s;
-o-transition-duration:0.8s;
}
#links a:hover {
background:#fff;
color:#000;
-moz-transition-duration:0.8s;
-webkit-transition-duration:0.8s;
-o-transition-duration:0.8s;
}
<div id="sidebar">
<div id="sidebarimg"><img src="{image:sidebar}"></div>
<div id="links">
{text:Link 1 Text}
ASK
MY EDITS
{text:Link 4 Text}
</div>
EDIT: thanks for the help guys!

No, this is not possible. You can only change an element based on CSS hover behaviours based on the hover state of itself or one of the higher identifiers in your selector.
You can 'cheat' a little using the adjacent and general sibling selectors, but not to entirely different parts of the DOM tree.
Here's an example of both cases where the hovering of an element can affect another element's rendering:
div {
border:1px solid black;
padding:5px;
}
div:hover button:first-of-type {
background:red;
}
button:hover + button {
background:red;
}
<div>
<p>The first button will highlight when you mouse into the container. The second button will highlight when you hover over the first.
<button>Button 1</button><button>Button 2</button>
</div>
In all more complex cases you'll need Javascript.

You could add an :after pseudo element to the links.
The pseudo element could then be position absolutely above the links.
Then apply a different background-image for each link.
See this jsFiddle
#links a:after {
content: '';
position: absolute;
top: 15px;
left: 15px;
width: 200px;
height: 200px;
}
#links a:nth-child(1):hover:after {
background-image: url('...');
}

Related

Height Problems with CSS Child element

I got a problem with giving back the child height to its parent.
The code comes from the Magento OnePageCheckOut site and I guess it is an css issue.
Normally the checkout goes from up to down. With using of a modified css code, the progressbar is seperated on top of the page and the content for the current step is shown below. Sadly, the child-element, where the content is shown, is handled as an overflow element. This makes it necessary to set a defined height for its parent element, which means, all steps have the same height and it looks so bad.
Maybe you guys have an idea what I could change in the css files to give the needed height back to the parent-element. I tried to change the display values or played with position, but to be honest, I m not that deep in css to know exactly what am I doing. It was more trail and error.
An image of that problem below:
The code is:
<ol class="opc" id="checkoutSteps">
<li id="opc-billing" class="section allow active">
<div class="step-title"></div>
<div id="checkout-step-billing" class="step a-item"></div>
</li>
<li id="opc-shipping" class="section">
<div class="step-title"></div>
<div id="checkout-step-billing" class="step a-item" style="display:none;"></div>
</li>
</ol>
.opc { position:relative; overflow:hidden; height:970px; padding-top:20px; text-align:center; border:1px solid #BBAFA0;}
.opc li.section { display: inline; }
.opc .step-title,.opc .allow .step-title,.opc .active .step-title { position:relative; text-align:center; border:none; background:none; padding:0; overflow:hidden!important; height:80px; display:inline-block; vertical-align:top; }
.opc .step { padding:30px 20px; position:absolute; border:0; top:100px; left:0; z-index:1; background:#fff; width:605px; height:900px; border-bottom:1px dotted #ccc; border:none; width:643px; text-align:left;}
.opc:first-of-type .active .step{left:0; width: 100%;}
For starters, this is not going to be pretty (It's because of things like this that make me less and less of a fan of Magento). Basically what the current CSS is doing is positioning .step-title relatively and .step absolutely. Absolute positioned elements are out of flow for the document, so what ends up happening is the document renders the .step-title elements as if they were right next to each other, but the .step is out of flow, so it's just kind of hanging out 100px from the top of .opc. In order for the .steps to have their normal dimension, we need to figure out how to get them to not be position: absolute. I took the CSS and made this fiddle:
http://jsfiddle.net/31db2uma/
The first step is to remove the position:absolute and related rules and the height attributes:
http://jsfiddle.net/31db2uma/1/
.opc {
position:relative;
overflow:hidden;
padding-top:20px;
text-align:center;
border:1px solid #BBAFA0;
}
.opc li.section {
display: inline;
}
.opc .step-title,
.opc .allow .step-title,
.opc .active .step-title {
position:relative;
text-align:center;
border:none;
background:none;
padding:0;
overflow:hidden!important;
height:80px;
display:inline-block;
vertical-align:top;
}
.opc .step {
padding:30px 20px;
border:0;
background:#fff;
width:605px;
border-bottom:1px dotted #ccc;
border:none;
width:643px;
text-align:left;
}
.opc:first-of-type .active .step{
left:0;
width: 100%;
margin-top: 80px; /* same as old title height. This is for later when we make the steps `position:absolute` */
}
The trick is then to make sure all the steps stay at the top of the .opc container. For that, we need to take it out of flow and for that we use position:absolute (same bad code, different application). This will cause another major issue to arise. We have no idea where to put the elements. Our best bet would be to give them each 20% width assuming there will always be no more and no less then five steps.
http://jsfiddle.net/31db2uma/2/
#checkoutSteps li .step-title {
width: 20%;
position: absolute;
top: 20px; /* same as padding */
}
#checkoutSteps li:first-child .step-title {
left: 0;
}
#checkoutSteps li:first-child + li .step-title {
left: 20%;
}
#checkoutSteps li:first-child + li + li .step-title {
left: 40%;
}
#checkoutSteps li:first-child + li + li + li .step-title {
left: 60%;
}
#checkoutSteps li:first-child + li + li + li + li .step-title {
left: 80%;
}
This is a pretty thoroughly hacked solution, but I know from experience that Magento sometimes doesn't really give you many options.
What you can do is when user clicks next button, get the height of the next new child container to be shown in jquery and set that height to the parent container. You can use CSS but giving static height can be problematic if content goes down in different screen resolutions. Jquery will help in this

Clickable div will not show

I want the whole div clickable, but it will not show. I want it to change when hovered as well. I believe I have used this same coding before and it has worked, not sure why I am having issues.
<div class="clickable_one">
</div>
div.clickable_one {
float:right;
}
div.clickable_one a {
position:absolute;
width:120px;
height:30px;
text-decoration:none;
background-image:url("images/forums_link copy.png");
}
div.clickable_one a:hover {
position:absolute;
width:120px;
height:30px;
text-decoration:none;
background-image:url("images/forums_link_2 copy.png");
}
The problem is you are using float:right on your div and position:absolute on your <a> which forced everything to move on right corner of screen. If you use InspectElement you will have clear view. I placed a border around your div as example to check location of div
I'v updated your CSS a bit and content is showing.
div.clickable_one
{
border: 2px solid blue;
}
div.clickable_one a {
width:120px;
height:30px;
text-decoration:none;
background-image:url("images/forums_link copy.png");
}
div.clickable_one a:hover
{
width:120px;
height:30px;
text-decoration:underline;
background-image:url("images/forums_link copy.png");
}
DEMO

Style the div inside hyperlink; on hover

Actually I want to give hover to div which is inside hyperlink but I don't know how to in css.
These divs actually have background images attached to them in css.
<div class="header_menu">
<div class="foa_logo"><img src="images/FOA-Logo.jpg"/></div>
<div class="address"></div>
<div class="home"></div>
<div class="about"> </div>
<div class="services"></div>
<div class="contact"></div>
</div>
div {
width:100px;
transition: width 2s;
}
div:hover {
width:200px;
}
replace div with .foa_logo if you want to select just that class.
I've created a jsfiddle for you showing how to do the hover you want. I removed the divs in the hyperlinks, because they are not useful. You can simply set the styles for the a tags and then you get your hovers
http://jsfiddle.net/FHWb6/
.header_menu a {
display:block;
height:40px;
width:100px;
line-height:3;
text-align:center;
font-family:Arial;
font-size:14px;
text-transform:uppercase;
float:left;
position:relative;
background:url(); /*put your image here*/
background-color:#CC0;
color:#FFF;
text-decoration:none;
}
.header_menu a:hover {
background:url(); /* put your hover image or position here */
background-color:#ececec;
color:#000;
}
I added some extra code in there just to do some base level styling - color, height and width will most likely change for you.
Try this:
element:hover {
property: value;
}
By this, you can change the CSS properties of the elements when they are hovered over!
So for you, you will try it as:
.home:hover { // on the home div..
// all the changes here
}

styling of links applies to images?

i'm having this really frustrating problem where a thin silver of the color that i'm applying as the a:hover,a:active is appearing outside of where it should. i have an image in absolute positioning right above the menu that is exhibiting this....i could just move the image up one but i want to solve it the correct way....here is my css
.logo
{
width:200px;
height:108px;
position:absolute;
left:5px;
top:10px;
}
#menu
{
position:relative;
top:110px;
padding-top:0px;
clear:both;
}
ul
{
list-style-type:none;
overflow:hidden;
padding:0px;
width:900px;
}
a
{
text-decoration:none;
}
li
{
float:left;
}
a:link,a:visited
{
display:block;
font-weight:bold;
text-align:center;
background-color:#ffffff;
padding:3px;
width:120px;
height:auto;
color:#000000;
float:left;
}
a:hover,a:active
{
background-color:#804000;
color:#ffffff;
}
here is my corresponding html:
Sorry, your browser doesn’t support JavaScript!
U4U Test Page
<div class="header">
<img class="logo" src="linktofilehere" alt="U4U Logo" />
</div>
<div id="menu">
<ul>
<li><a href="/" >Home</a></li>
<li>About Us</li>
<li>Programs</li>
<li>US Movement</li>
<li>Sponsorship</li>
<li>Donate</li>
</ul>
</div>
</body>
</html>
i've searched through the help knowledge and couldn't find anything related really....i'm sure it is something simple....any help would be appreciate, i think it might have to do with positioning or not defining the hover area correctly but i'm not sure....i just started learning html and css last week so please be kind!
You will need to create a new style for the 'a' of your image. If you don't, it will use the standard 'a' stylings of your CSS.
Like this :
a.imglink:hover
{
background:none;
}
I'd add a style to remove the background color from linked images - that way you won't run into issues with transparent PNGs etc:
.imglink:hover {
background-color:transparent;
}
I just specifically targetted links inside the list for the background color on hover..
CSS:
#menu > ul > li > a:hover,a:active
{
background-color:#804000;
color:#ffffff;
}
http://jsfiddle.net/cSSU7/
Did this solve your problem?
/* remove the background */
.imglink:hover { background: none; }
/* if you run into specificity issues, be more selective! :) */
a.imglink:hover { background: none; }
/* or remove the padding from just the first a */
a:first-of-type{ padding: 0; }
/* or remove the background from the first link */
a:first-of-type{ background: none; }
DEMO

Facebook-like friend selection checkbox

I'm trying to code a selection like the Facebook "invite friends" selection. I like it because it uses the default checkboxes and not a background simulating the selection of each item.
The problem is that I cannot figure out how can they make the text (friend's name) break into two lines if needed (text is too big)!
I have a simplified example of what I'm trying to achieve. Here's the HTML:
<div class="modal">
<div class="modal-body">
<ul class="unstyled">
<li class="store_selectable">
<input class="checkbox" type="checkbox">
<a href="#">
<div class="store-text">
<div class="iblock"><img alt="Missing" src="http://placehold.it/30x30"></div>
<div class="text"><div>This is the store</div></div>
</div>
</a>
</li>
</ul>
​
And here's the CSS:
body {
padding: 20px;
}
li.store_selectable {
width:161px;
float:left;
margin:0 0px 6px 0px;
overflow:hidden;
font-size:0.9em;
}
li.store_selectable .checkbox {
float:left;
display:inline-block;
margin:12px 6px 0;
}
li.store_selectable .store-text {
display:block;
height:30px;
}
li.store_selectable img {
float:left;
display:block;
width:30px;
height:30px
}
li.store_selectable a {
display:block;text-decoration:none;
padding:2px;
outline:none;
color:#333;
border:1px solid #fff;
border-width:1px 0;
}
li.store_selectable a:hover {
background:cyan;
border:1px solid blue;
border-width:1px 0;
}
li.store_selectable .iblock {
display:inline-block;
vertical-align:middle;
overflow:hidden;
text-align:left;
}
For an easier testing and understanding I've created a jsfiddle here: http://jsfiddle.net/rikas/tpqHd/1/
Now, what I'm trying to do is breaking the text in two lines if the width of the list item is small enough, changing this line: width:161px;. Messing with facebook "invite friends" modal window CSS I can see that they do it, but I can't!
Thanks for your help!
Not quite sure of the interface you are trying to achieve, but the reason for text not wrapping is the css
overflow:hidden;
after removing that consider putting your checkbox and
the text its own div element with class .fl
.fl { display:block; }
to line them side by side
directly under the two create another empty div element with the class of .clear
.clear { display:block; clear:both; line-height:0; }
to prevent the next element inheriting the float:left