how to enlarge a div on hover without moving other div - html

I'm looking to achieve a hover effect like this hover where the image enlarges but does not displace the surrounding divs. I have seen this done by assigning relative and absolute positioning and a z-index but that isn't working for me. Perhaps I assigned those values to the wrong classes. My code is below...any help is appreciated
I wasn't totally sure how to post the code here so...my site (and code problem) can be viewed here
It's my first time posting here. Thanks for the instruction. Here is the code...
HTML:
<div class="products-container">
<div class="products-container-inner">
<div class="item">
<div class="item">
<div class="item">
<div class="item">
CSS:
div.item {
height: 135px;
width: 150px;
margin: 10px;
display: inline-block;
float: left;
}
div.item:hover {
border: none; float: left;
height: 280px;
width: 280px;
background-color: #ffffff;
-moz-box-shadow: 0 0 5px rgba(0,0,0,0.5);
-webkit-box-shadow: 0 0 5px rgba(0,0,0,0.5);
box-shadow: 0 0 5px rgba(0,0,0,0.5);
-webkit-transition: .2s ease;
-moz-transition: .2s ease;
-o-transition: .2s ease;
-ms-transition: .2s ease;
transition: .2s ease;
}
div.products-container-inner {
margin: auto;
width: 100%;
border: none;
padding: 10px;
overflow: hidden;
}
div.item .product-name {
text-align: center;
display: none;
}
div.item:hover .product-name {
text-align: center;
display: block;
}
div.item .price-box {
text-align: center;
display: none;
}
div.item:hover .price-box {
text-align: center;
display: block;
}
div.item .btn {
background-color: #EE432E;
background-image: -moz-linear-gradient(center top , #EE432E 0%, #C63929 50%, #B51700 50%, #891100 100%);
border: 1px solid #951100;
border-radius: 5px 5px 5px 5px;
box-shadow: 0 0 0 1px rgba(255, 115, 100, 0.4) inset, 0 1px 3px #333333;
color: #FFFFFF;
font: normal 16px/1 "helvetica neue",helvetica,arial,sans-serif;
padding: 3px 0;
float: left;
margin-left: 65px;
text-shadow: 0 -1px 1px rgba(0, 0, 0, 0.8);
text-decoration: none;
width: 150px;
display: none;
}
div.item:hover .btn {
text-align: center;
display: block;
background-color: #F37873;
background-image: -moz-linear-gradient(center top , #F37873 0%, #DB504D 50%, #CB0500 50%, #A20601 100%);
cursor: pointer;
}
div.item:active .btn {
background-color: #D43C28;
background-image: -moz-linear-gradient(center top , #D43C28 0%, #AD3224 50%, #9C1500 50%, #700D00 100%);
box-shadow: 0 0 0 1px rgba(255, 115, 100, 0.4) inset;
}

In your example of what you want to achieve... There is two divs for the same pic.
One "regular" and one "hover" that only appears on hover.
This hidden one as a z-index of 2 and is shown over the first... Wich give that impression of a resising div. But it's not the case.
;)
===
EDIT:
ok Ryh, see this start I've done for you here...
Without jQuery, you will not have any "shiny effects" like fadein/fadeout...
But, it may be a choice to do it like this :
CSS:
div.item {width:200px;}
div.hover {display:none; position:relative; z-index:2; top:-200px; width:300px;}
// The top:-200px is to move the big image up... depends on the small pic height.
// And the width are in fonction of the pics width.
HTML:
<div class="item" id="img1" onmouseover="showbigger(this.id);">
<img src="something.jpg" style='width;200px; height:200px; border:1px solid black;'>
</div>
<div class="hover" id="img1big" onmouseout="shownormal(this.id);">
<img src="something-bigger.jpg" style='width;300px; height:300px; border:1px solid black;'>
</div>
<script>
function showbigger(ref){
document.getElementById(ref+'big').style.display='inline';
}
function shownormal(ref){
document.getElementById(ref).style.display='none';
}
</script>
You'll have to play a little with positioning and pic sizes.
And this may not a perfect solution... but it's a start if you want to do it with JavaScript.

I was able to achieve this without using two divs by "zooming in" on the element using
element:hover {
transform: scale(1.5);
}
https://www.w3schools.com/howto/howto_css_zoom_hover.asp

Html for a hyperlink:
Click Here
Css
a{text-decoration: none;
position: fixed;
color: #0000ff;
}
a:hover { text-decoration: initial;
color: #ff0000;
}
a:visited {color: #b200ff;}

Related

How to reverse the way divs stack when window is resized?

When the screen width is resized 700px and below the photo stacks on top of the text as it should. I would like the text to sit on top instead, without reversing the order when the screen width is larger than 700px.
.section-a {
background: #eaeaea;
color: #333;
padding: 3em .5em;
.section-a h2 {
padding: .5em .5em 0 .5em;
}
.section-a p {
padding: .5em 2em;
text-align: left;
}
.img-a {
display: block;
margin: auto;
width: 100%;
height: auto;
}
#ceo-sig {
font-family: 'Seaweed Script', cursive;
font-size: 1.5em;
float: left;
padding-left: 35px;
}
.learn-more-btn {
appearance: none;
border: 0;
border-radius: 5px;
color: #fff;
cursor: pointer;
display: inline-block;
font-size: 14px;
font-weight: bold;
padding: .45em .5em .25em .5em;
width: 30%;
text-shadow: 0 2px 4px rgba(0,0,0,0.30);
background: #2FBC3D;
margin: 2em 0;
background-image: linear-gradient(-180deg, #1EB52A 0%, #0D941C 100%);
border: 1px solid #0C6B16;
box-shadow: 0 1px 5px 0 rgba(9,116,21,0.50), inset 0 -1px 6px 0 rgba(0,0,0,0.20), inset 0 1px 0 0 rgba(255,255,255,0.50), inset 0 2px 4px 0 rgba(255,255,255,0.50);
opacity: 1;
transition: color .2s ease-out;
-moz-transition: color .2s ease-out;
-webkit-transition: color .2s ease-out;
-o-transition: color .2s ease-out;
}
.learn-more-btn:hover {
color: #333;
}
<section class="section-a grid">
<div class="box">
<img class="img-a" src="https://static.wixstatic.com/media/0141bb700ad54cf2b0457ae50b0704c5.jpg/v1/fill/w_453,h_220,al_c,q_80,usm_0.66_1.00_0.01/Brainstorming.webp" alt="people watching presentation">
</div>
<div class="box">
<h2 class="content-title">How We Work</h2>
<div class="content-text">
<p>Every client engagement, every recommendation and every implementation is based on decades of experience managing leading global enterprises. Rest assured, you will be getting leading edge decisions that solve today’s challenges and have a vision of tomorrow. We work as closely as you need to develop the right hosting and infrastructure decisions for your business, no matter how big or small.</p>
</div>
</div>
</section>
I just want to add that there are three rows, each with text on one side of the page and a photo on the other. When I resize I want the text on top of the corresponding photo. The other two rows don't have this problem due to their initial order.
The section element could be styled like this
section {
display: flex;
flex-direction: column-reverse;
}
#media (min-width: 700px) {
section {
flex-direction: column;
}
}
You'd give yourself an easier job if you added ids to the boxes. Then you could do something like the following media query, without too much difficulty.
#media only screen and (min-width: 700px) {
#box1 {
top: 230px;
}
#box2 {
top: 0;
}
.box {
display: inline-block;
position: fixed;
}
}
<section class="section-a grid">
<div id="box1" class="box">
<img class="img-a" src="https://static.wixstatic.com/media/0141bb700ad54cf2b0457ae50b0704c5.jpg/v1/fill/w_453,h_220,al_c,q_80,usm_0.66_1.00_0.01/Brainstorming.webp" alt="people watching presentation">
</div>
<div id="box2" class="box">
<h2 class="content-title">How We Work</h2>
<div class="content-text">
<p>Every client engagement, every recommendation and every implementation is based on decades of experience managing leading global enterprises. Rest assured, you will be getting leading edge decisions that solve today’s challenges and have a vision
of tomorrow. We work as closely as you need to develop the right hosting and infrastructure decisions for your business, no matter how big or small.</p>
</div>
</div>
</section>
You can use media querie to set your breakpoint then reorder your div with flex or grid
You may use order that works with flex :
About flex, see this tutorial among others https://css-tricks.com/snippets/css/a-guide-to-flexbox/
Below working snippet/demo with following update
#media screen and (min-width: 701px) {
.grid {
display: flex;
flex-direction: column;
}
.grid .box:first-child {
order: 1
}
}
#media screen and (min-width: 701px) {
.grid {
display: flex;
flex-direction: column;
}
.grid .box:first-child {
order: 1
}
}
.section-a {
background: #eaeaea;
color: #333;
padding: 3em .5em;
}
.section-a h2 {
padding: .5em .5em 0 .5em;
}
.section-a p {
padding: .5em 2em;
text-align: left;
}
.img-a {
display: block;
margin: auto;
width: 100%;
height: auto;
}
#ceo-sig {
font-family: 'Seaweed Script', cursive;
font-size: 1.5em;
float: left;
padding-left: 35px;
}
.learn-more-btn {
appearance: none;
border: 0;
border-radius: 5px;
color: #fff;
cursor: pointer;
display: inline-block;
font-size: 14px;
font-weight: bold;
padding: .45em .5em .25em .5em;
width: 30%;
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.30);
background: #2FBC3D;
margin: 2em 0;
background-image: linear-gradient(-180deg, #1EB52A 0%, #0D941C 100%);
border: 1px solid #0C6B16;
box-shadow: 0 1px 5px 0 rgba(9, 116, 21, 0.50), inset 0 -1px 6px 0 rgba(0, 0, 0, 0.20), inset 0 1px 0 0 rgba(255, 255, 255, 0.50), inset 0 2px 4px 0 rgba(255, 255, 255, 0.50);
opacity: 1;
transition: color .2s ease-out;
-moz-transition: color .2s ease-out;
-webkit-transition: color .2s ease-out;
-o-transition: color .2s ease-out;
}
.learn-more-btn:hover {
color: #333;
}
<section class="section-a grid">
<div class="box">
<img class="img-a" src="https://static.wixstatic.com/media/0141bb700ad54cf2b0457ae50b0704c5.jpg/v1/fill/w_453,h_220,al_c,q_80,usm_0.66_1.00_0.01/Brainstorming.webp" alt="people watching presentation">
</div>
<div class="box">
<h2 class="content-title">How We Work</h2>
<div class="content-text">
<p>Every client engagement, every recommendation and every implementation is based on decades of experience managing leading global enterprises. Rest assured, you will be getting leading edge decisions that solve today’s challenges and have a vision
of tomorrow. We work as closely as you need to develop the right hosting and infrastructure decisions for your business, no matter how big or small.</p>
</div>
</div>
</section>
or you may use grid:row that works with grid :
About grid , see this tutorial among others https://css-tricks.com/snippets/css/complete-guide-grid/
Below working snippet/demo with following update
#media screen and (min-width: 701px) {
.grid {
display: grid;
}
.grid .box:nth-child(2) {
grid-row:1
}
}
#media screen and (min-width: 701px) {
.grid {
display: grid;
}
.grid .box:nth-child(2) {
grid-row:1
}
}
.section-a {
background: #eaeaea;
color: #333;
padding: 3em .5em;
}
.section-a h2 {
padding: .5em .5em 0 .5em;
}
.section-a p {
padding: .5em 2em;
text-align: left;
}
.img-a {
display: block;
margin: auto;
width: 100%;
height: auto;
}
#ceo-sig {
font-family: 'Seaweed Script', cursive;
font-size: 1.5em;
float: left;
padding-left: 35px;
}
.learn-more-btn {
appearance: none;
border: 0;
border-radius: 5px;
color: #fff;
cursor: pointer;
display: inline-block;
font-size: 14px;
font-weight: bold;
padding: .45em .5em .25em .5em;
width: 30%;
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.30);
background: #2FBC3D;
margin: 2em 0;
background-image: linear-gradient(-180deg, #1EB52A 0%, #0D941C 100%);
border: 1px solid #0C6B16;
box-shadow: 0 1px 5px 0 rgba(9, 116, 21, 0.50), inset 0 -1px 6px 0 rgba(0, 0, 0, 0.20), inset 0 1px 0 0 rgba(255, 255, 255, 0.50), inset 0 2px 4px 0 rgba(255, 255, 255, 0.50);
opacity: 1;
transition: color .2s ease-out;
-moz-transition: color .2s ease-out;
-webkit-transition: color .2s ease-out;
-o-transition: color .2s ease-out;
}
.learn-more-btn:hover {
color: #333;
}
<section class="section-a grid">
<div class="box">
<img class="img-a" src="https://static.wixstatic.com/media/0141bb700ad54cf2b0457ae50b0704c5.jpg/v1/fill/w_453,h_220,al_c,q_80,usm_0.66_1.00_0.01/Brainstorming.webp" alt="people watching presentation">
</div>
<div class="box">
<h2 class="content-title">How We Work</h2>
<div class="content-text">
<p>Every client engagement, every recommendation and every implementation is based on decades of experience managing leading global enterprises. Rest assured, you will be getting leading edge decisions that solve today’s challenges and have a vision
of tomorrow. We work as closely as you need to develop the right hosting and infrastructure decisions for your business, no matter how big or small.</p>
</div>
</div>
</section>
Display grid with grid-row worked. I just needed to switch the img and text in my HTML as well. thanks!

Is it possible for the color to 'erase' the background in CSS?

I really doubt what I am asking is possible but it's still worth a try.
I am trying to create a button that normally has background-color: transparent; color: white; and when you hover over it, those properties should swap. The problem is that if you just swap them then all you see is a white button. If you know the background colour of the containing element then you can get the colour from there but If the button is over an image or a canvas then this won't work.
This is how I've been doing it so far
html,
body {
height: 100%;
}
#container {
background-color: #38404D;
height: 100%;
}
.ghost-button {
background-color: transparent;
border: 1px solid #ffffff;
outline: none !important;
transition: all 0.8s;
margin: 10px 10px;
padding: 6px 7px;
cursor: pointer;
color: #ffffff;
}
.ghost-button:hover {
background-color: #ffffff;
color: #38404D;
}
.ghost-button:active {
box-shadow: inset 0 0 8px 0px #888888;
}
<div id="container">
<button class="ghost-button">Hover Here</button>
</div>
UPDATE
It seems that quite a few people were confused by the question. I am asking if there is a way to do the exact same thing I've done above but on top of an image or a canvas (instead of a solid colour). See example below
html,
body {
height: 100%;
}
#container {
background-image: url("http://www.freegreatpicture.com/files/147/17878-hd-color-background-wallpaper.jpg");
height: 100%;
}
.ghost-button {
background-color: transparent;
border: 1px solid #ffffff;
outline: none !important;
transition: all 0.8s;
margin: 10px 10px;
padding: 6px 7px;
cursor: pointer;
color: #ffffff;
}
.ghost-button:hover {
background-color: #ffffff;
color: #38404D;
}
.ghost-button:active {
box-shadow: inset 0 0 8px 0px #888888;
}
<div id="container">
<button class="ghost-button">Hover Here</button>
</div>
Yes, it IS possible in CSS with mix-blend-mode.
Answer's update in April 2021: Currently it have a very solid support (95% globally) although Safari doesn't have hue, saturation, color, and luminosity blend modes. Of course, IE isn't a considerable thing if you expect to use it (like many of other cool CSS features of the last years).
.ghost-button {
/* Important part */
mix-blend-mode: screen;
background: #000;
color: #fff;
/* Button cosmetics */
border: .125em solid #fff;
font: 2em/1 Cursive;
letter-spacing: 1px;
outline: none !important;
transition: all .8s;
padding: .5em 1em;
cursor: pointer;
}
.ghost-button:hover {
/* Important part */
background: #fff;
color: #000;
}
#container {
background: url('http://www.freegreatpicture.com/files/147/17878-hd-color-background-wallpaper.jpg') center/cover;
/* Also works with background-color or gradients: */
/* background: linear-gradient(to right, red, yellow); */
/* Container positioning */
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
html, body {
margin: 0;
}
<div id="container">
<button class="ghost-button">Hover Here</button>
</div>
As you can see, the secret here is using mix-blend-mode: screen along with the black color for the "erased" part, since black is mixed with the background when using this screen mode.
No, it isn't possible in CSS! You could try to set the color with JS to mimic this effect.
body {
height: 100%;
}
#container {
background-color: #38404D;
height: 100%;
}
.ghost-button {
background-color: transparent;
border: 1px solid #ffffff;
outline: none !important;
transition: all 0.8s;
margin: 10px 10px;
padding: 6px 7px;
cursor: pointer;
color: #ffffff;
}
.ghost-button:hover {
background-color: none;
color: red;
}
.ghost-button:active {
box-shadow: inset 0 0 8px 0px #888888;
}
<div id="container">
<button class="ghost-button">Hover Here</button>
</div>
hover color is set to red you can update it.

Overlapping divs having position fixed and relative

I have a div named container that contains multiple child div elements. Of these child divs, the top most one, named top_bar, has position: fixed while the remaining others have position: relative. The trouble is that divs that have relative positioning are overlapping with the div with fixed positioning. The jsfiddle outlining the issue. I was able to correct this by adding top:150px but this feels more like a hack. Is there a better way to do this?
If you want to this dynamic so you can check below mentioned link:
https://jsfiddle.net/06vzbuf0/2/
I've used jQuery to resolve this issue.
Add padding-top:120px; to container and top:0; to top_bar to that below div is not overlay to topbar.
html, body {
height:100%;
}
.container {
text-align: center;
width:100%;
margin:0%;
padding:120px 0 0;
color: dodgerblue;
}
.top_bar{
box-shadow: 0px 5px 5px #DDD;
position: fixed;
z-index: 10000;
opacity: .95;
background-color:#f9f9f9;
width:100%;
top:0;
}
.mugoogle{
font-size: 22px;
font-family: Arial;
margin: 10px auto;
}
.mugoogle a, .tab_results a {
text-decoration:none;
-webkit-transition:all .3s ease;
-ms-transition:all .3s ease;
transition:all .3s ease;
}
.mugoogle a:hover{
color: #aaa;
}
.tab_results a:hover {
text-decoration:underline;
color: #000
}
.textbox{
margin: 0px auto;
height:30px;
width:60%;
}
.rounded {
border-radius:5px;
-moz-border-radius:5px;
-webkit-border-radius:5px;
}
/* h4{
-moz-transition: all .5s;
-webkit-transition: all .5s;
transition: all .5s;
}
*/
input[type="submit"] {
height: 30px;
}
input[type="text"] {
border: 1px solid #ccc;
margin: 10px;
padding: 5px;
-moz-transition: all .5s;
-webkit-transition: all .5s;
transition: all .5s;
}
input[type="text"]:focus {
border-color: #66afe9;
outline: 0;
-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, 0.6);
box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, 0.6);
}
.button {
display: inline-block;
outline: none;
cursor: pointer;
text-align: center;
text-decoration: none;
width: 40px;
font: 14px/100% "Century Gothic", Arial, Helvetica, sans-serif;
/* padding: .5em 2em .55em; */
text-shadow: 0 1px 1px rgba(0,0,0,.3);
-webkit-border-radius: .5em;
-moz-border-radius: .5em;
border-radius: .5em;
-webkit-box-shadow: 0 1px 2px rgba(0,0,0,.2);
-moz-box-shadow: 0 1px 2px rgba(0,0,0,.2);
box-shadow: 0 1px 2px rgba(0,0,0,.2);
}
.button:hover {
text-decoration: none;
}
.button:active {
position: relative;
top: 1px;
}
.blue {
color: #d9eef7;
border: solid 1px #0076a3;
background: #0095cd;
background: -webkit-gradient(linear, left top, left bottom, from(#00adee), to(#0078a5));
background: -moz-linear-gradient(top, #00adee, #0078a5);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#00adee', endColorstr='#0078a5');
}
.blue:hover {
background: #007ead;
background: -webkit-gradient(linear, left top, left bottom, from(#0095cc), to(#00678e));
background: -moz-linear-gradient(top, #0095cc, #00678e);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#0095cc', endColorstr='#00678e');
}
.blue:active {
color: #80bed6;
background: -webkit-gradient(linear, left top, left bottom, from(#0078a5), to(#00adee));
background: -moz-linear-gradient(top, #0078a5, #00adee);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#0078a5', endColorstr='#00adee');
}
.project_data{
text-align:left;
width: 1000px;
position:relative;
padding: 5px;
word-wrap:break-word;
margin:0 auto;
font-family: Calibri;
font-size: 18px;
color: #555;
}
<div class = "container">
<div class = "top_bar">
<h4 class = 'mugoogle'>
<a href = '/search/'>
muGoogle
</a>
</h4>
<form class="form-wrapper" method = "GET" action = "{% url 'doc_scorer'%}">
<input type="text" name = 'query' class="textbox rounded" placeholder="Search docs related to..." required>
<input type="submit" class="button blue" value="🔎">
</form>
<br>
</div>
<br>
<div class = 'project_data project_name'>
<strong>Project name: </strong>
</div>
<div class = 'project_data scq_title'>
<strong>SGQ: </strong>
</div>
<div class = 'project_data situation'>
<strong>Situation: </strong>
</div>
<div class = 'project_data future_state'>
<strong>Future State: </strong>
</div>
<div class = 'project_data complications'>
<strong>Complications: </strong>
</div>
<div class = 'project_data questions'>
<strong>Questions: </strong>
</div>
<div class = 'project_data data'>
<strong>Data: </strong>
</div>
<div class = 'project_data name'>
<strong>Name: </strong>
</div>
<br>
<br>
</div>
Try position: sticky. Positions static & relative keep their natural space in the flow of the document, while the absolute & fixed don’t — their space is removed and they have a floating behavior.
position: sticky;

CSS Button turn to normal size smoothly when un-hovered

im new to css and i don't have any idea how to make button get smaller smoothly when user unhovered the button , i have successfully make the button get bigger smoothly but it turn into normal size in instant time , this is my code :
<html>
<head>
<style>
body {
background-image:url("http://cdn.mysitemyway.com/etc-mysitemyway/webtreats/assets/posts/976/full/tileable-light-blurs-and-abstract-circles-18.png");
}
.title {
position:relative;
text-align:center;
border : 5px solid rgba(255,255,255,0.9);
background-color:rgba(0, 199, 255, 0.7);
font-size:100%;
color:white;
box-shadow: 10px 10px 5px #888888;
}
.firstcontainer {
position:relative;
margin-top:3%;
}
.menubutton {
box-shadow: 10px 10px 5px #888888;
font-size:200%;
margin-left:1%;
text-align:center;
background-color: rgba(0,157,255,0.5);
display:inline-block;
color:white;
border:3px solid white;
padding:1% 1% 1% 1%;
}
.menubutton:hover {
background-color:rgba(0,199,255,0.5);
padding: 1.1% 1.1% 1.1% 1.1%;
transition-duration:0.5s;
}
.menutext {
color:white;
}
</style>
</head>
<body>
<div class="title"> <h1 > English Lesson </h1> </div>
<div class="firstcontainer">
<div class="menubar"></div>
<div class="menubutton"><strong><i><u>Home</u></i></strong></div>
<div class="menubutton"><strong><i><u>Contacts</u></i></strong></div>
</div>
</body>
</html>
I am sorry if this already asked somewhere but i cannot find it at search engine such as google .
Is there any way to make something like .menubutton:unhover ?
Add transition to menubutton also, the transition property gets applied to the hover state, therefore your animation takes 0.5 second when changing to that specific state. Adding it to the regular state will also apply it when changing back from a special state
body {
background-image: url("http://cdn.mysitemyway.com/etc-mysitemyway/webtreats/assets/posts/976/full/tileable-light-blurs-and-abstract-circles-18.png");
}
.title {
position: relative;
text-align: center;
border : 5px solid rgba(255,255,255,0.9);
background-color: rgba(0, 199, 255, 0.7);
font-size: 100%;
color: white;
box-shadow: 10px 10px 5px #888888;
}
.firstcontainer {
position: relative;
margin-top: 3%;
}
.menubutton {
box-shadow: 10px 10px 5px #888888;
font-size: 200%;
margin-left: 1%;
text-align: center;
background-color: rgba(0,157,255,0.5);
display: inline-block;
color: white;
border: 3px solid white;
padding: 1% 1% 1% 1%;
transition-duration: 0.5s;
-webkit-transition-duration: 0.5s;
-ms-transition-duration: 0.5s;
-moz-transition-duration: 0.5s;
}
.menubutton:hover {
background-color: rgba(0,199,255,0.5);
padding: 1.1% 1.1% 1.1% 1.1%;
transition-duration: 0.5s;
-webkit-transition-duration: 0.5s;
-ms-transition-duration: 0.5s;
-moz-transition-duration: 0.5s;
}
.menutext {
color: white;
}
<div class="title">
<h1 > English Lesson </h1>
</div>
<div class="firstcontainer">
<div class="menubar"></div>
<a href="#" class="menutext">
<div class="menubutton"><strong><i><u>Home</u></i></strong></div>
</a> <a href="#" clas="menutext">
<div class="menubutton"><strong><i><u>Contacts</u></i></strong></div>
</a>
</div>
Your transition property needs to be on the default .menubutton class. This means that when you hover the button it will transition to the new style and then back to the default again when you stop hovering.
.menubutton {
box-shadow: 10px 10px 5px #888888;
font-size:200%;
margin-left:1%;
text-align:center;
background-color: rgba(0,157,255,0.5);
display:inline-block;
color:white;
border:3px solid white;
padding:1% 1% 1% 1%;
transition-duration:0.5s;
}
.menubutton:hover {
background-color:rgba(0,199,255,0.5);
padding: 1.1% 1.1% 1.1% 1.1%;
}
The reason that your animation doesn't work when you stop hovering is that the transition property is no longer applied to the element, as it only exists on hover.
Add to class
.menubutton {
box-shadow: 10px 10px 5px #888888;
font-size:200%;
margin-left:1%;
text-align:center;
background-color: rgba(0,157,255,0.5);
display:inline-block;
color:white;
border:3px solid white;
padding:1% 1% 1% 1%;
transition:all 1s ease-in-out;
-webkit-transition:all 1s ease-in-out;
-moz-transition:all 1s ease-in-out;
-ms-transition:all 1s ease-in-out;
}
You need to use scale() effect and apply transition-duraion for both unhovered and hovered button
Look at snippet:
body {
background-image:url("http://cdn.mysitemyway.com/etc-mysitemyway/webtreats/assets/posts/976/full/tileable-light-blurs-and-abstract-circles-18.png");
}
.title {
position:relative;
text-align:center;
border : 5px solid rgba(255,255,255,0.9);
background-color:rgba(0, 199, 255, 0.7);
font-size:100%;
color:white;
box-shadow: 10px 10px 5px #888888;
}
.firstcontainer {
position:relative;
margin-top:3%;
}
.menubutton {
box-shadow: 10px 10px 5px #888888;
font-size:200%;
margin-left:1%;
text-align:center;
background-color: rgba(0,157,255,0.5);
display:inline-block;
color:white;
border:3px solid white;
padding:1% 1% 1% 1%;
transition-duration: 0.5s;
}
.menubutton:hover {
transform: scale(1.2);
transition-duration: 0.5s;
}
.menutext {
color:white;
}
<div class="title"> <h1 > English Lesson </h1> </div>
<div class="firstcontainer">
<div class="menubar"></div>
<div class="menubutton"><strong><i><u>Home</u></i></strong></div>
<div class="menubutton"><strong><i><u>Contacts</u></i></strong></div>
</div>
<html>
<head>
<style>
body {
background-image:url("http://cdn.mysitemyway.com/etc-mysitemyway/webtreats/assets/posts/976/full/tileable-light-blurs-and-abstract-circles-18.png");
}
.title {
position:relative;
text-align:center;
border : 5px solid rgba(255,255,255,0.9);
background-color:rgba(0, 199, 255, 0.7);
font-size:100%;
color:white;
box-shadow: 10px 10px 5px #888888;
}
.firstcontainer {
position:relative;
margin-top:3%;
}
.menubutton {
box-shadow: 10px 10px 5px #888888;
font-size:200%;
margin-left:1%;
text-align:center;
background-color: rgba(0,157,255,0.5);
display:inline-block;
color:white;
border:3px solid white;
padding:1% 1% 1% 1%;
transition: padding 0.1s;
}
.menubutton:hover {
background-color:rgba(0,199,255,0.5);
padding: 1.1% 1.1% 1.1% 1.1%;
}
.menutext {
color:white;
}
</style>
</head>
<body>
<div class="title"> <h1 > English Lesson </h1> </div>
<div class="firstcontainer">
<div class="menubar"></div>
<div class="menubutton"><strong><i><u>Home</u></i></strong></div>
<div class="menubutton"><strong><i><u>Contacts</u></i></strong></div>
</div>
</body>
</html>
Just remove transition-duration from hover element and add a transition: padding 0.1s to the button class. The animation does not look so smooth due to small padding change.
Try to use - in cases where it's possible - transform property. It handles the animations very smoothly.
In your case, I suggest you to use transform: scale() instead, animation works fine and it looks even better than before.
By the way, if you want to apply a value, e.g. 5px to padding or margin, you don't have to write it separately for all directions, just use simply:
margin: 5px or padding: 5px. It will affect top, bottom, left and right directions together.
body {
background-image: url("http://cdn.mysitemyway.com/etc-mysitemyway/webtreats/assets/posts/976/full/tileable-light-blurs-and-abstract-circles-18.png");
}
.title {
position: relative;
text-align: center;
border: 5px solid rgba(255, 255, 255, 0.9);
background-color: rgba(0, 199, 255, 0.7);
font-size: 100%;
color: white;
box-shadow: 10px 10px 5px #888888;
}
.firstcontainer {
position: relative;
margin-top: 3%;
}
.menubutton {
box-shadow: 5px 5px 2px #888888;
font-size: 200%;
text-align: center;
background-color: rgba(0, 157, 255, 0.5);
display: inline-block;
color: white;
border: 3px solid white;
padding: 4px;
margin: 4px;
transition: all .5s ease;
}
.menubutton:hover {
background-color: rgba(0, 199, 255, 0.5);
transform: scale(1.1);
transition: all .5s ease;
}
.menutext {
color: white;
}
<div class="title">
<h1> English Lesson </h1>
</div>
<div class="firstcontainer">
<div class="menubar"></div>
<a href="#" class="menutext">
<div class="menubutton"><strong><i><u>Home</u></i></strong>
</div>
</a>
<a href="#" clas="menutext">
<div class="menubutton"><strong><i><u>Contacts</u></i></strong>
</div>
</a>
</div>

Markings in top left corner of a table element

I have a left/right scrollable table with two rows and 30+ and growing columns on my homepage. It looks like this:
But I would like to add some titles on "flags" like this:
How could I add "flags" without having to draw transparent PNG and put it on top layer. I was thinking about using canvas, but how could I draw those "flags" which aren't squares and put them in top right corner of every table?
ADD
I like #rick-hitchcock's answer which looks really simple and I tried to implementing it into my webpage. But the "flags" won't seem to render.
Here is how I implemented it:
table.index{
table-layout: fixed;
border-spacing: 20px;
}
table.index td {
height: 190px; /*iz tega se preračuna višina slike v %*/
width: 190px; /*iz tega se preračuna širina slike v %*/
min-width: 190px; /*ne smejo biti manjši - tabela se širi*/
position: relative; /*da deluje spodnja vrstica*/
overflow: hidden;
border-radius: 5px;
border: 1px solid #1A1A1A;
background-color: rgba(0, 0, 0, 0.90);
box-shadow: 0px 0px 8px #000000;
-moz-box-shadow: 0px 0px 8px #000000;
-webkit-box-shadow: 0px 0px 8px #000000;
vertical-align: middle;
text-align: center;
padding: 5px 5px 5px 5px;
}
table.index td img {
position: absolute;
top: 0;
left: 0;
height: auto;
width: 100%;
z-index: -1;
-webkit-transition: all 1.5s ease;
-moz-transition: all 1.5s ease;
-o-transition: all 1.5s ease;
-ms-transition: all 1.5s ease;
transition: all 1.5s ease;
}
table.index td a{
color: #FF3C3F;
}
table.index td p.napis{
opacity: 0.0;
color: white;
text-shadow: 0px 0px 2px #555555;
font-size: 14px;
font-family: ss9;
-webkit-transition: all 1.5s ease;
-moz-transition: all 1.5s ease;
-o-transition: all 1.5s ease;
-ms-transition: all 1.5s ease;
transition: all 1.5s ease;
}
table.index td:hover p.napis{
opacity: 1.0;
}
table.index td:hover{
box-shadow: 0px 0px 15px #000000;
-moz-box-shadow: 0px 0px 15px #000000;
-webkit-box-shadow: 0px 0px 15px #000000;
}
table.index td:hover img {
-webkit-filter: blur(2px) opacity(20%);
-o-filter: blur(2px) opacity(20%);
-ms-filter: blur(2px) opacity(20%);
filter: blur(2px) opacity(20%);
}
div.index {
width: 100%;
overflow-x: auto;
overflow-y: hidden;
-ms-overflow-y: hidden;
}
<!-- THE CODE YOU PROVIDED-->
.container {
position: relative;
overflow: hidden;
display: inline-block;
}
.discount, .event {
position: absolute;
top: 0;
transform: rotate(-45deg);
transform-origin: 50% 250%;
width: 10em;
padding: 0.3em 0;
text-align: center;
border: 1px solid #333;
font: 14px verdana;
}
.discount {
background: #cfc;
}
.event {
background: yellow;
}
<section class="index">
<div class="index">
<table class="index">
<tr>
<td>
<div class="container">
<div class="discount">Discount</div>
<img src="../slike/index/2016-01-18-embedded_world.jpg"/>
<p class="napis">
Obiskali bomo sejem Embedded world v Nürnbergu, kjer si bomo ogledali najnovejšo tehnologijo na področju vgrajenih sistemov. Dijaki ŠC Kranj lahko pri meni prevzamete štiri brezplačne karte z vključenim prevozom!
</p>
</div>
</td>
</tr>
</table>
</div>
</section>
For some reason it won't render as a "flag" but only as a text. Normally it looks like this:
and on mouse hoover it looks like:
Here is my webpage if you want to check it out.
You could use CSS3 transform to rotate a DIV containing the flag.
To make the flag disappear when hovering the table cell, you could do this:
td:hover .discount, td:hover .event {
display: none;
}
That makes it disappear/reappear immediately, which may be a bit jarring. Alternatively, you could transition its opacity like this:
.discount, .event {
transition: 0.5s;
}
td:hover .discount, td:hover .event {
opacity: 0;
}
Snippet:
.index td {
position: relative; /* make the flags relative to their parent td */
overflow: hidden; /* prevent the flags from overflowing the cell */
}
.discount, .event {
position: absolute; /* position the flag absolutely within container */
top: 0; /* top of container */
transform: rotate(-45deg); /* rotate counterclockwise 45 degrees */
transform-origin: 50% 250%; /* experiment to find best placement */
width: 10em; /* width of flag */
text-align: center; /* center the flag's text */
padding: 0.3em 0; /* top and bottom padding */
border: 1px solid #333; /* dark border */
transition: 0.5s; /* transition changed styles in half a second */
font: 14px verdana;
}
.discount {
background: #cfc; /* light green */
}
.event {
background: yellow;
}
.index img {
width: 150px;
border: 1px solid black;
}
td:hover .discount, td:hover .event {
opacity: 0;
}
<table class="index">
<td>
<div class="discount">Discount</div>
<img src="http://ziga-lausegger.com/slike/index/2016-01-18-embedded_world.jpg"/>
<td>
<div class="event">Event</div>
<img src="http://ziga-lausegger.com/slike/index/2015-12-06-comptech.png">
</table>
I think you are looking for something like this: https://jsfiddle.net/DIRTY_SMITH/hywos6cx/
.wrapper {
margin: 50px auto;
width: 150px;
height: 150px;
background: white;
border-radius: 10px;
-webkit-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.3);
-moz-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.3);
box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.3);
position: relative;
z-index: 90;
}
.ribbon-wrapper-green {
width: 85px;
height: 88px;
overflow: hidden;
position: absolute;
top: -3px;
right: -3px;
}
.ribbon-green {
font: bold 15px Sans-Serif;
color: #333;
text-align: center;
text-shadow: rgba(255, 255, 255, 0.5) 0px 1px 0px;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
position: relative;
padding: 7px 0;
left: -5px;
top: 15px;
width: 120px;
background-color: #BFDC7A;
background-image: -webkit-gradient(linear, left top, left bottom, from(#BFDC7A), to(#8EBF45));
background-image: -webkit-linear-gradient(top, #BFDC7A, #8EBF45);
background-image: -moz-linear-gradient(top, #BFDC7A, #8EBF45);
background-image: -ms-linear-gradient(top, #BFDC7A, #8EBF45);
background-image: -o-linear-gradient(top, #BFDC7A, #8EBF45);
color: #6a6340;
-webkit-box-shadow: 0px 0px 3px rgba(0, 0, 0, 0.3);
-moz-box-shadow: 0px 0px 3px rgba(0, 0, 0, 0.3);
box-shadow: 0px 0px 3px rgba(0, 0, 0, 0.3);
}
.ribbon-green:before,
.ribbon-green:after {
content: "";
border-top: 3px solid #6e8900;
border-left: 3px solid transparent;
border-right: 3px solid transparent;
position: absolute;
bottom: -3px;
}
.ribbon-green:before {
left: 0;
}
.ribbon-green:after {
right: 0;
}