My code:
#dropdown {
width: 80px;
height: 80px;
border-radius: 80px;
border-width: 0px;
transition: background-color 1s;
}
#dropdown_word {
font-size: 40px;
color: orangered;
}
#dropdown:hover {
background-color: cyan;
}
<div class="heading">
<h2>
H2 goes here
</h2>
<div class="button">
<p>
<button id="dropdown">
<span id="dropdown_word"> V </span>
</button>
</p>
</div>
</div>
<div class="content">
<h4>
H4 goes here
</h4>
<p>
Text goes here
</p>
</div>
I want to display the class .content when the mouse is hovering on the button. Before the hover, .content should not be visible to the user. What CSS code can be used to get the above output?
All you have to do is move the .content div inside the .button div and apply the following CSS:
.content{
display: none;
}
.button:hover .content{
display: block;
}
Here is the JSFiddle.
One way to do is it to add a common div parent that contains both the button and the .content div. The drawback to this method is that the .content class will show up if the user enters .parent div. so if your parent div covers half the page your button is going to show up if you hover anywhere on that area.
<div class="parent">
<div class="heading">
<h2>
H2 goes here
</h2>
<div class="button">
<p>
<button id="dropdown">
<span id="dropdown_word"> V </span>
</button>
</p>
</div>
</div>
<div class="content">
<h4>
H4 goes here
</h4>
<p>
Text goes here
</p>
</div>
</div>
#dropdown
{
width:80px;
height:80px;
border-radius: 80px;
border-width: 0px;
transition: background-color 1s;
}
#dropdown_word
{
font-size:40px;
color:orangered;
}
#dropdown:hover
{
background-color: cyan;
}
.content{
visibility: hidden;
}
.parent:hover .content{
visibility: initial;
}
Use CSS syntax visibility: visible|hidden|collapse|initial|inherit;
#dropdown {
width: 80px;
height: 80px;
border-radius: 80px;
border-width: 0px;
transition: background-color 1s;
}
#dropdown_word {
font-size: 40px;
color: orangered;
visibility: hidden;
}
#dropdown:hover #dropdown_word {
background-color: cyan;
visibility: visible;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<div class="heading">
<h2>
H2 goes here
</h2>
<div class="button">
<p>
<button id="dropdown">
<span id="dropdown_word"> V </span>
</button>
</p>
</div>
</div>
<div class="content">
<h4>
H4 goes here
</h4>
<p>
Text goes here
</p>
</div>
#content{display:none;}
#dropdown:hover + #content{display:block;}
You can do it using JS.
var element = document.getElementsByClassName('button')[0];
element.addEventListener("mouseover",function(){
document.getElementsByClassName('content')[0].style.display = "block";
});
element.addEventListener("mouseout",function(){
document.getElementsByClassName('content')[0].style.display = "none";
});
make content hide by default
.content {
display: none;
}
because the button isn't at all related with .content you can't do this accurately with css alone
you can do this with css only if .content has a relation with the button ( sibling,child,parent )
so in this case you have to use jquery.
check here jsfiddle
css code added : .content { display:none}
jquery code added :
$("#dropdown").hover(
function() {
$('.content').show()
},
function() {
$('.content').hide()
}
);
Related
I'm a guitar player, not a coder, but I have a guitar lesson site I'm trying to upgrade. (Sorry if I screw up posting the code below.) I have a tooltip positioning problem that uses HTML and CSS. I wonder if anyone can help. If you roll over it on this page, you'll see what I'm wanting it to do. (It also needs to work on mobile touchscreens.) Thanks.
https://codepen.io/Daverino/pen/zboNoQ
.toolTipDiv {
float: none;
width: 275px;
margin-left: 20px;
}
.toolTipLink a {
display: block;
color: #202020;
background-color: transparent;
width: auto;
padding: 0px 10px;
text-decoration: none;
font-size: 12px;
margin-left: 0px;
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: #878787;
line-height: 17px;
}
.toolTipLink a:hover {
background-color: #ddd;
color: #9B0E11;
padding-left: 10px;
}
a.tooltip span {
z-index: 10;
display: none;
padding: 7px 10px;
margin-top: -80px;
/* this doesn't do anything:
margin-bottom: [any value]px;
*/
margin-left: 200px;
width: 140px;
line-height: 16px;
opacity: 0.85;
}
a.tooltip:hover span {
display: inline;
position: absolute;
color: #EEE;
background: #000;
}
<body>
<p> </p><p> </p><p> </p><p> </p>
<div class="toolTipDiv">
<span class="toolTipLink">
<a href=“#” class="tooltip">
<div class="tooltipWrapper">
<div class="toolTipEdge">Medium amount of text in this line.</div>
<span>I want the bottom of every tooltip to be at the top of every line it hovers over.</span>
</div>
</a>
<a href=“#” class="tooltip">
<div class="tooltipWrapper">
<div class="toolTipEdge">This is the text that will be hovered over. Sometimes it may be this long</div>
<span>The bottom of this tooltip is too low. It should be just above the line.</span>
</div>
</a>
<a href=“#” class="tooltip">
<div class="tooltipWrapper">
<div class="toolTipEdge">Here is a shorter line of text.</div>
<span>Sometimes the text in the "tooltip" will be a couple sentences long. If the tooltip text is ong or if it is short, the bottom of the tooltip should be right above the hovered line.</span>
</div>
</a>
<a href=“#” class="tooltip">
<div class="tooltipWrapper">
<div class="toolTipEdge">Medium amount of text in this line.</div>
<span>This tooltip is way too high.</span>
</div>
</a>
</span>
</div>
</body>
For "span", you said it was absolute, but didn't give any positioning information. In this case add "bottom":
position: absolute;
bottom: 0em;
There also isn't anything for it to be relative to, so add:
.tooltipWrapper { position: relative; }
I suggest you check out Tippy.js its a cool tooltip and popover library, it's highly customizable.
A guy at a Facebook group called HTML CSS JAVASCRIPT wrote a codepen that fixed it. Apparently I'd messed up the absolute and relative positioning.
https://codepen.io/jkarkosza/pen/WmopbP
.toolTipDiv {
float: none;
width: 275px;
margin-left: 20px;
}
.toolTipLink a {
display: block;
color: #202020;
background-color: transparent;
width: auto;
padding: 0px 10px;
text-decoration: none;
font-size: 12px;
margin-left: 0px;
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: #878787;
line-height: 17px;
}
.toolTipLink a:hover {
background-color: #ddd;
color: #9B0E11;
padding-left: 10px;
}
a.tooltip {
position: relative;
}
a.tooltip span {
z-index: 10;
display: none;
padding: 7px 10px;
position:absolute;
bottom: 100%;
color:#EEE;
background:#000;
/* margin-left: 200px; */
width: 140px;
line-height: 16px;
opacity: 0.85;
}
a.tooltip:hover span{
display:block;
}
<body>
<p> </p><p> </p><p> </p><p> </p>
<div class="toolTipDiv">
<span class="toolTipLink">
<a href="_lessons/_beginner/054-Basic-Boogie-Rock.html" target="_blank" class="tooltip">
<div class="tooltipWrapper">
<div class="toolTipEdge">Medium amount of text in this line.</div>
<span>I want the bottom of every tooltip to be at the top of every line it hovers over.</span>
</div>
</a>
<a href="_lessons/_beginner/054-Basic-Boogie-Rock.html" target="_blank" class="tooltip">
<div class="tooltipWrapper">
<div class="toolTipEdge">This is the text that will be hovered over. Sometimes it may be this long</div>
<span>The bottom of this tooltip is too low. It should be just above the line.</span>
</div>
</a>
<a href="_lessons/_beginner/054-Basic-Boogie-Rock.html" target="_blank" class="tooltip">
<div class="tooltipWrapper">
<div class="toolTipEdge">Here is a shorter line of text.</div>
<span>Sometimes the text in the "tooltip" will be a couple sentences long. If the tooltip text is ong or if it is short, the bottom of the tooltip should be right above the hovered line.</span>
</div>
</a>
<a href="_lessons/_beginner/054-Basic-Boogie-Rock.html" target="_blank" class="tooltip">
<div class="tooltipWrapper">
<div class="toolTipEdge">Medium amount of text in this line.</div>
<span>This tooltip is way too high.</span>
</div>
</a>
</span>
</div>
</body>
I have an image and text below it wrapped in one "a" tag. Hovering over the white box with text in it turns the box grey. Hovering over the image and it has an opacity effect.
How can I make the box turn grey and the image opacity happen at the same time when hovered over. At the moment these happen seperately. This is not a huge problem but it'd look better if they happened together.
Here's a screenshot - https://imgsafe.org/image/ef3964b27c
This is my HTML;
<div class="w3-third w3-container w3-margin-bottom">
<a href="#" style="display:block">
<img src="Images/MCR.png" style="width:100%" class="w3-hover-opacity">
<div class="w3-container w3-white">
<p><b>PSB2 and COM4</b></p>
<p><b> </b></p>
</div>
</a>
</div>
Since your snippet is different from the image you provided, I created a simple snippet that changes the opacity of the image and changes the border color (if that is what you mean by box) to gray
.wrapper {
height: 200px;
width: 250px;
border: 3px solid green;
}
.wrapper:hover {
border: 3px solid gray;
}
.wrapper:hover img {
opacity: 0.5;
}
<div class="wrapper">
<a href="#">
<img src="http://via.placeholder.com/250x150" />
</a>
</div>
Try This:
.w3-third {
border: 5px solid lightgreen;
display: inline-block;
position: relative;
text-align: center;
}
p {
margin: 0;
}
a {
color: #000;
text-decoration: none;
}
.w3-third:hover .w3-white {
background-color: gray;
}
.w3-third:hover img {
opacity: 0.2;
}
<div class="w3-third w3-container w3-margin-bottom">
<a href="#" style="display:block"><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQEnn9dYYZlciBKfaHCw17-dUgRPX3nq5_6-kV1ua-LIsId5g43uA">
<div class="w3-container w3-white">
<p><b>PSB2 and COM4</b></p>
<p><b> </b></p>
</div></a>
</div>
now try this one with edited code
.w3-white {
margin-top: -20px;
width: 40%;
}
.w3-container:hover img {
opacity: 0.5;
}
.w3-container:hover .w3-white {
background-color: grey;
}
<div class="w3-third w3-container w3-margin-bottom">
<a href="#" style="display:block"><img src="http://webneel.com/daily/sites/default/files/images/daily/09-2013/1-diwali-greetings.preview.jpg" style="width:40%" class="w3-hover-opacity">
<div class="w3-container w3-white">
<p><b>PSB2 and COM4</b></p>
<p><b> </b></p>
</div>
</a>
</div>
Try to put you image and text into a single container and add simple transition. check below snippet.
.img-container {
width: 250px;
border: 2px solid blue;
}
.img-container p {
padding: 10px 0;
margin:0;
transition: all 0.5s ease;
}
.img-container img{
transition: all 0.5s ease;
}
.img-container:hover img {
opacity: 0.5;
}
.img-container:hover p {
background-color: grey;
}
<div class="img-container">
<a href="#">
<img src="http://via.placeholder.com/250x150" />
<p>Some text</p>
</a>
</div>
I've created a left navigation bar using buttons. I'm trying to reduce the hyperlink area to just the background image. Also, another issue I'm having is the elements overlaying the background image are taking precedence over the hyperlink, so the button is not actually clickable. Page for reference
http://www.auburn.edu/administration/facilities/home-page/index.html
Hyperlink area
Here's the background image area
.img-responsive {
display: block;
padding: 0;
margin: 0;
}
.background:hover .head {
color: #d76e08;
}
.overlay {
position: absolute;
z-index: 1;
top: 0;
left: 0;
color: white;
}
.icon {
padding-top: 15px;
padding-left: 40px;
}
.head {
margin-top: -75px;
padding-left: 120px;
}
.content {
margin-top: -5px;
padding-left: 120px;
padding-right: 35px;
}
<div class="row">
<div class="col-sm-12">
<div class="background">
<a href="../Collin/misc/issues/index.html">
<img alt="background" class="img-responsive" src="buttons/images/button.png" />
</a>
<div class="overlay">
<div class="icon">
<img alt="test" class="img-responsive" src="buttons/images/info-icon.png" />
</div>
<p class="head">Ask Facilities</p>
<p class="content">Here will be text about the button. .</p>
</div>
</div>
</div>
</div>
I'm trying to reduce the hyperlink area to just the background image.
Your markup is incredibly complex for what you are displaying.
You could have something like:
<ul>
<li>
<a>
<h2></h2>
<p></p>
</a>
</li>
<li>
<a>
<h2></h2>
<p></p>
</a>
</li>
</ul>
and add the image and the gradient using CSS.
I would use a single link tag for your button and leverage CSS gradients for the background:
* {
box-sizing: border-box;
}
body {
font-family: sans-serif;
}
.button {
background-image: linear-gradient(to bottom, #3D85C6, #07355F 50%, #07355F);
background-size: 100% 200%;
border-radius: 4px;
color: #fff;
display: block;
padding: 10px;
text-decoration: none;
transition: all 150ms ease-in-out;
}
.button:hover,
.button:focus,
.button:active {
background-position: 0 50%;
}
.button-icon {
float: left;
margin-right: 15px;
}
.button-content {
overflow: hidden;
}
.button-title {
font-size: 18px;
font-weight: bold;
}
.button-description {
font-size: 16px;
}
<a class="button" href="../Collin/misc/issues/index.html">
<div class="button-icon">
<img src="http://satyr.io/72/white?brand=github" alt=""/>
</div>
<div class="button-content">
<p class="button-title">Ask Facilities</p>
<p class="button-description">Here will be text about the button…</p>
</div>
</a>
Also here http://jsbin.com/rikisemawe/edit?html,css,output
The elements in OP were stacked in the markup, there were no nested components of the button. That would explain the unusual position coords and large padding.
Instead of <img>, background-image is used. Changed some of the tags to a real <button>, <h4> instead of <p>, etc.
SNIPPET
.button {
position: relative;
min-width: 350px;
max-width: 100%;
min-height: 95px;
height: auto;
padding: 5px 10px;
border: 0 none transparent;
border-radius: 6px;
background: url(http://www.auburn.edu/administration/facilities/home-page/buttons/images/button.png)no-repeat;
background-size: cover;
}
.background:hover .head {
color: #d76e08;
}
.text {
padding: 0 5px;
position: absolute;
left: 85px;
top: 5px;
text-align: left;
color: #def;
text-decoration: none;
}
.button:hover,
.text:hover {
text-decoration: none;
color: #def;
}
.button:hover .head {
color: gold;
}
.icon {
width: 75px;
height: 75px;
position: absolute;
top: calc(50% - 37.5px);
background: url(http://www.auburn.edu/administration/facilities/home-page/buttons/images/service-icon.png)no-repeat;
}
<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="row">
<div class="col-sm-12">
<button class="button">
<div class="icon"></div>
<a class='text'>
<h4 class="head">Ask Facilities</h4>
<p class="content">Here will be text about the button.</p>
</a>
</button>
</div>
</div>
How do I overlay a paragraph of text over the image (homepagepic.jpg) in the middle of the page.
I want to write a bunch of text over the image, I have done quite a lot of research but I haven't come across much to be honest. Thanks very much indeed in advance
HTML:
<center>
<h1>Welcome To The Kingston University Survey Page</h1>
</center>
<img src="kingstonunilogo.jpg" id="uni" alt="uni logo"/>
<br/>
<div id="buttons">
<button onclick="window.location='http://www.google.com'" type="button home-button">Home</button>
<button onclick="window.location='http://www.google.com'" type="button contact-button">Contact Us</button>
LogIn
</div>
<br/><br/><br/><br/><br/><br/>
<img src="homepagepic.jpg" alt="homepagepic" id="middlepic" />
<br/>
<div id="footer">
©
<img class="social-badge" src="facebookpic.png" alt="facebook logo" onclick="window.location.href='http://www.facebook.com'">
<img class="social-badge" src="twitterpic.jpg" alt="twitter logo" onclick="window.location.href='http://www.twitter.com'">
</div>
CSS:
h1 {
margin:0px;
padding:0px;
}
body {
background-color: #A9D0F5;
}
#middlepic {
display: block; margin: 0 auto;
}
#uni {
display: block; width: 200px; height: 175px; float:left;
}
#footer {
width: 100%; height:100px; display: inline-block; text-align: center;
}
#buttons {
display: block;
margin: 0 auto;
width: 50%;
}
button {
height: 30px;
width: 200px;
background-color: #ccc;
border-radius: 10px;
}
a {
text-decoration: none; color: #000;
}
.social-badge {
width: 40px;
}
Why dont you make a new div and put the homepagepic.jpg as its background and then write in that div.
<div id="written">
This text is over the image
</div>
and in CSS
#written
{
background-image : url(***** here comes the url of image homepagepic.jpg*****);
}
If you don't want to use background-image use position:absolute for the paragraph http://jsfiddle.net/8cup75k3/
p{
width:500px;
position:absolute;
margin-top:-100px;
color:green;
}
Use CSS
background-image: url('kingstonunilogo.jpg');
A semantic approach would be to use a figure element with an absolutely positioned figcaption.
Something like this:
figure { position: relative; }
figcaption {
position: absolute;
top: 0; left; 0;
}
<figure>
<img src="http://placehold.it/240" />
<figcaption>This is overlay text.</figcaption>
</figure>
So i have an image, I have a text box with a transparent background that is overlaid on the image (FYI it contains the price of the item and if it is onsale).
I would like the text box to "fit" the width of the image it is over.
Currently the text is wider than the image. I've tried adjusting the width but that only seems to shrink it and move the box out from being over the image.
http://jsfiddle.net/Ggqy4/
Here is what I'm aiming to create. Notice the text is only as wide as the image.
http://imgur.com/zKzjIyF
The red box inside the box is on the first item on the left, the girl in the vest.
HTML:
<div class="date-container">
<div class="date-heading" style="display: block;">Friday, Oct 11, 2013</div>
<div class="items-purchased-container">
<DIV style="position: absolute; top:10px; left:355px; width:200px; height:25px">3</span> items purchased</p>
</div>
<div class="total-spend-container">
<div class="product">
<img src="https://theory.alluringlogic.com/api/v1/productvariation/3/1058.jpg?preset=XS" alt="" />
<div class="description">
<p>Sex shirt in sparkly black <span class="price">Price $500</span>
</p>
</div>
</div>
<div class="product">
<img src="https://theory.alluringlogic.com/api/v1/productvariation/3/1058.jpg?preset=XS" alt="" />
<div class="description">
<p>Sex shirt in sparkly black <span class="price sale">Sale Price $500</span>
</p>
</div>
</div>
CSS:
body {
background:#00000;
text-align:center;
}
.product {
display:inline-block;
position:relative;
margin-right:10px;
vertical-align:top;
}
.product img {
display:block;
max-width:100%;
}
.description {
position:absolute;
background:rgba(255, 255, 255, 0.75);
top:60%;
;
text-align:center;
width:100%;
}
.description span {
display:block;
margin-top:10px;
padding:5px;
}
.sale {
background:red;
}
Here is a JSFiddle file for your review: CLICK HERE
As mentioned above by Giovanni Silveira, your images contain a large left/right border. You can either crop in your favorite image editor or you will have to manipulate your code to accommodate the added area to your liking.
I did add some changes to force the appearance you were looking for, however if you want a less intrusive set up then it would be prudent to change you images to fit your needs.
To view how the page was set up, just add
border: 1px solid #ccc;
to your product and description classes to see the flow and gain a better understanding of the images impact on flow of document.
Hope this helps.
Here is the code:
HTML:
<div class="orderinfo">
<div class="date">Friday, Oct 11, 2013</div>
<div class="purchaseitems">3 items purchased</div>
</div>
<div class="total-spend-container">
<div class="product">
<img src="https://theory.alluringlogic.com/api/v1/productvariation/3/1058.jpg?preset=XS" style="width:300px;height:250px" alt="" />
<div class="description">
<p>Sex shirt in
<br>sparkly black</br> <span class="price">Price $500</span>
</p>
</div>
</div>
<div class="product">
<img src="https://theory.alluringlogic.com/api/v1/productvariation/3/1058.jpg?preset=XS" style="width:300px;height:250px" alt="" />
<div class="description">
<p>Sex shirt in
<br>sparkly black</br> <span class="price sale">Sale Price $500</span>
</p>
</div>
</div>
CSS:
body {
background: #00000;
text-align: center;
}
.orderinfo {
position: relative;
width: 100%;
min-width: 650px;
font-family: "Courier", sans-serif;
font-size: 20px;
}
.date, .purchaseitems {
float: left;
width: 49%;
padding-bottom: 10px;
}
.total-spend-container {
min-width: 650px;
}
.product {
position: relative;
display: inline-block;
width: 300px;
height: 250px;
}
.product img {
background-position: center;
background-size: cover;
}
.description {
position: absolute;
background: rgba(255, 255, 255, 0.75);
font-family: "Courier", sans-serif;
font-style: italic;
top: 50%;
text-align: center;
left: 25%;
width: 50%;
}
.description span {
display: inline-block;
margin-top: 10px;
padding: 3px;
}
.sale {
background: red;
color: white;
}