I am trying to make a fairly simple web page, having a banner image
and a simple animation (marquee emulation). I want to have a responsive image
in the page. The problem is that whenever the animation loop iterates, the image resize repeats itself.
.marquee {
overflow: hidden;
white-space: nowrap;
animation: marquee 17s linear infinite;
-webkit-animation: marquee 17s linear infinite;
background-color: red;
}
.marquee:hover {
-webkit-animation-play-state: paused;
animation-play-state: paused;
}
.fixed-ratio-resize{
height:auto;
max-width: 90%;
}
<img src="image.png" class="fixed-ratio-resize" alt="banner" />
<p class="marquee">
Do not use marquee tag for improve accessibility and readability.
</p>
I would like to "disengage" the animation from the image resize, ie to have the image resized only when the viewport is changed.
MTIA
If you need responsive image then you have to follow this code on your fixed-ratio-resize css. you can set width:90% if you want.
.fixed-ratio-resize {
height: auto;
width: 100%;
display: block;
margin: 0 auto;
}
Here is an example with marquee emulation. With 90% of image width. If you have any question ask me in comment.
#keyframes marquee {
0% { text-indent: 430px }
100% { text-indent: -485px }
}
#-webkit-keyframes marquee {
0% { text-indent: 430px }
100% { text-indent: -485px }
}
.marquee {
overflow: hidden;
white-space: nowrap;
animation: marquee 17s linear infinite;
-webkit-animation: marquee 17s linear infinite;
background-color: red;
}
.marquee:hover {
-moz-animation-play-state: paused;
-webkit-animation-play-state: paused;
animation-play-state: paused;
}
.fixed-ratio-resize {
height: auto;
width: 90%; /*YOU CAN USE 100% if you want */
display: block;
margin: 0 auto;
}
<img src="http://orig10.deviantart.net/f6bf/f/2007/054/1/9/website_banner_landscape_by_kandiart.jpg" class="fixed-ratio-resize" alt="banner ">
<p class="marquee">Do not use marquee tag for improve accessibility and readability.</p>
Related
I have a typewriter effect in CSS for my below text:
these words are in two-line, I have the following code for typewriter effect
.typewriter h1 {
color: #333;
font-family: monospace;
overflow: hidden;
/* Ensures the content is not revealed until the animation */
border-right: .15em solid #ff5d22;
/* The typwriter cursor */
white-space: nowrap;
/* Keeps the content on a single line */
margin: 0 auto;
/* Gives that scrolling effect as the typing happens */
/* Adjust as needed */
animation: typing 3.5s steps(30, end), blink-caret .5s step-end infinite;
}
/* The typing effect */
#keyframes typing {
from {
width: 0
}
to {
width: 100%
}
}
/* The typewriter cursor effect */
#keyframes blink-caret {
from,
to {
border-color: transparent
}
50% {
border-color: orange
}
}
<div class="typewriter">
<h1>Professional, Creative, Flexible, Scalable Workspace</h1>
</div>
Now the problem is, the typewriter is only working in the first line, it's not going to the second line, can anyone please tell me what is wrong with my code?
try like this.. this way of css. or you must add js
html
<div class="container">
<p class="typing">
This paragraph of text will be animated with a "typewriter" style effect, and it will continue to work even if it splits across multiple lines. Well, in this case, up to a maximum of 5 lines, but you get the picture.
</p>
<div class="hiders">
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
</div>
</div>
css
#keyframes typing {
from { width: 100% }
to { width: 0 }
}
.container {
position: relative;
font-family: Consolas, monospace;
}
.typing {
position: absolute;
top: 0;
margin: 0;
z-index: -1;
}
.hiders {
margin: 0;
position: absolute;
top: 0;
width: 100%;
}
.hiders p {
position: relative;
clear: both;
margin: 0;
float: right; /* makes animation go left-to-right */
width:0; /* graceful degradation: if animation doesn't work, these are invisible by default */
background: white; /* same as page background */
animation: typing 2s steps(30, end);
animation-fill-mode: both; /* load first keyframe on page load, leave on last frame at end */
}
.hiders p:nth-child(2) {
animation-delay: 2s;
}
.hiders p:nth-child(3) {
animation-delay: 4s;
}
.hiders p:nth-child(4) {
animation-delay: 6s;
}
.hiders p:nth-child(5) {
animation-delay: 8s;
}
See the code in this jsfiddle: https://jsfiddle.net/frpL3yr1/
The idea is that I want a bar of images at the top of the screen. The img-wrapper div will later be animated via javascipt to move to the left when you mouse over. For an example of what I am ultimately attempting to accomplish, see this page. The difference is that in mine, the animation will only run when moused-over.
The issue is that in my jsfiddle and the linked example, the width of the div containing the images is hard-coded. In my case, the css hard-codes the width of img-wrapper to 200%. I need my page to support an arbitrary number of images, so I need its width to be equal to that of the contents. The way my jsfiddle is implemented, if there are more images that can fit in img-wrapper, they will wrap to a new line.
What is the best way to go about fixing this?
Approach using flexbox and animation:
html, body {
margin:0;
padding:0;
overflow: hidden;
}
.demo-ribbon {
width: 100%;
height: 70vmin;
margin-top: 2rem;
overflow: hidden;
}
.img-wrapper {
height: 70vmin;
width: 100%;
display: flex;
flex-flow: row nowrap;
justify-content: stretch;
}
img {
flex: 1;
object-fit: content;
margin: 0 .2rem;
width: 100vmin;
height: 100%;
}
.lead {
animation: bannermove 12s linear 320ms infinite paused alternate;
}
.img-wrapper:hover .lead {
animation-play-state: running;
}
#keyframes "bannermove" {
0% {
margin-left: 0%;
}
100% {
margin-left: -230%;
}
}
You will need to add prefixes in order to work in all browsers especially animation
Further reading: https://devdocs.io/css/animation
working pen: https://codepen.io/manAbl/pen/KROvjx ;
Aspect Ratio: https://www.w3schools.com/howto/howto_css_aspect_ratio.asp & https://css-tricks.com/aspect-ratio-boxes/
Hope helps! :)
Use flexbox and animation with translate :)
.demo-ribbon {
width: 100%;
overflow: hidden;
}
.demo-ribbon .img-wrapper {
display: flex;
justify-content: stretch;
margin-right: 0;
position: relative;
width: 100%;
}
.demo-ribbon .img-wrapper img {
transition: all 0.5s ease;
margin: 2px;
}
.demo-ribbon .img-wrapper img:first-child {
animation: lefttoRight 25s linear 320ms infinite paused alternate;
}
.demo-ribbon .img-wrapper img:hover {
transform: scale(1.1);
cursor: pointer;
box-shadow: 0px 3px 5px rgba(0, 0, 0, 0.2);
}
.demo-ribbon .img-wrapper:hover img {
animation-play-state: running;
}
#keyframes lefttoRight {
0% {
margin-left: 0;
}
50% {
margin-left: -200%;
}
100% {
margin-left: 0%;
}
}
<html>
<body>
<div class="demo-ribbon">
<div class="img-wrapper">
<img class="lead" src="https://media-cdn.tripadvisor.com/media/photo-s/0e/9a/e3/1d/freedom-tower.jpg">
<img src="http://static.asiawebdirect.com/m/phuket/portals/www-singapore-com/homepage/pagePropertiesImage/singapore.jpg.jpg">
<img class="" src="https://www.s-ge.com/sites/default/files/cserver/styles/sge_header_lg/streamy/company/images/Hongkong-Fotolia-48687313-rabbit75-fot-282451.jpg?itok=ANpJxrgW">
<img class="" src="https://media-cdn.tripadvisor.com/media/photo-s/0e/9a/e3/1d/freedom-tower.jpg">
<img src="http://static.asiawebdirect.com/m/phuket/portals/www-singapore-com/homepage/pagePropertiesImage/singapore.jpg.jpg">
<img class="" src="https://www.s-ge.com/sites/default/files/cserver/styles/sge_header_lg/streamy/company/images/Hongkong-Fotolia-48687313-rabbit75-fot-282451.jpg?itok=ANpJxrgW">
<img class="" src="https://media-cdn.tripadvisor.com/media/photo-s/0e/9a/e3/1d/freedom-tower.jpg">
<img src="http://static.asiawebdirect.com/m/phuket/portals/www-singapore-com/homepage/pagePropertiesImage/singapore.jpg.jpg">
<img class="" src="https://www.s-ge.com/sites/default/files/cserver/styles/sge_header_lg/streamy/company/images/Hongkong-Fotolia-48687313-rabbit75-fot-282451.jpg?itok=ANpJxrgW">
<img class="" src="https://media-cdn.tripadvisor.com/media/photo-s/0e/9a/e3/1d/freedom-tower.jpg">
</div>
</div>
</body>
</html>
Is marquee element supported in Html 5 ? if not, how could we give that effect (design) by Css 3 coding. I mean scrolling text one side to another side, etc etc.
Some browsers still supports marquee element. But when I google it. Some sites are saying that it is not supported by html 5. So what is its alternative options in css 3.
You can use css keyframes for making marquee effect
<div class="marquee">
<div>
<span>This is marquee text...done with css keyframes without using marquee tag</span>
<span>This is marquee text...done with css keyframes without using marquee tag</span>
</div>
body { margin: 20px; }
.marquee {
height: 25px;
width: 600px;
overflow: hidden;
position: relative;
}
.marquee div {
display: block;
width: 200%;
height: 30px;
position: absolute;
overflow: hidden;
animation: marquee 5s linear infinite;
}
.marquee span {
float: left;
width: 50%;
}
#keyframes marquee {
0% { left: 0; }
100% { left: -100%; }
}
From MDN
The HTML <marquee> element is used to insert a scrolling area of text. You can control what happens when the text reaches the edges of its content area using its attributes.
The element is obsolete and must not be used. While some browsers still support it, it's not required.
Marquee in CSS3
body {
margin: 20px;
}
.marquee {
height: 25px;
width: 420px;
overflow: hidden;
position: relative;
}
.marquee div {
display: block;
width: 200%;
height: 30px;
position: absolute;
overflow: hidden;
animation: marquee 5s linear infinite;
}
.marquee span {
float: left;
width: 50%;
}
#keyframes marquee {
0% {
left: 0;
}
100% {
left: -100%;
}
}
<div class="marquee">
<div>
<span>You spin me right round, baby. Like a record, baby.</span>
<span>You spin me right round, baby. Like a record, baby.</span>
</div>
</div>
I am trying to recreate the following effect (click one of the colours on this page to see what I mean: http://flatuicolors.com) on an overlay when a link is clicked.
The transition is something like this: An overlay with a success message scales out and fades in, pauses and then scales out and fades out.
However, it is not producing the desired effect. What's more, the scaling is not visible at all. Any help is much appreciated.
html, body { height: 100%; }
.container {
position: relative;
margin: 0 auto; }
.container.questionnaire {
background:#f1c40f;
width: 100%;
max-width: 100%;
height: 100%;
}
.row-flex.buttons-only {
height:100%;}
.row-flex {
display: table;
width: 100%; }
.column {
box-sizing: border-box; }
.one-third-flex.column {
width: 33.3333%;
display: table-cell;
text-align: center;
vertical-align: middle;
float: none; }
.overlay {
position: fixed;
top: 0;
left: 0;
height: 100%;
width: 100%;
display: table;
background-color:#1abc9c;
z-index: 10;
}
h1.success-message { display: table-cell; text-align: center;
vertical-align: middle;}
.animated {
-webkit-animation-duration: 2s;
animation-duration: 2s;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
-webkit-animation-timing-function: ease-out;
animation-timing-function: ease-out;
}
#-webkit-keyframes fadeOut {
0% {visibility:visible; opacity: 1;transform: scale(2);}
40% {opacity: 1;transform: scale(1.5);}
60% {opacity: 1;transform: scale(1.5);}
100% {visibility:hidden; opacity: 0;transform: scale(1);}
}
#keyframes fadeOut {
0% {visibility:visible; opacity: 1; transform: scale(2);}
40% {opacity: 1;transform: scale(1.5);}
60% {opacity: 1;transform: scale(1.5);}
100% {visibility:hidden;opacity: 0; transform: scale(1);}
}
.fadeOut {
-webkit-animation-name: fadeOut;
animation-name: fadeOut;
}
<body>
<div class="overlay animated fadeOut"><h1 class="success-message">Success</h1></div>
<div class="container questionnaire">
<div class="row row-flex buttons-only">
<div class="one-third-flex column"></div>
<div class="one-third-flex column" style="background-color: #f4f4f4;">
<div role="button" class="ico-btn btn-settings-lg">CLICK
</div>
</div>
<div class="one-third-flex column"></div>
</div>
</div>
</body>
Well, I hope this answer may help you.
As I thought that was an interesting effect (created with flash), I have worked a bit creating it from scratch with css3 and jquery. It was easier for me to do my code insteed of trying to modify yours so that’s why It maybe not be usefull for You but maybe it may be for other users.
The html is simple:
<div class="square ">
</div>
<div class="effect ">
<div class="text">TEXT HERE</div>
</div>
Where square is the area to click and effect is the container of the animation, which is a div with 0 height and width placed at the center of the window in case you want to add more animations (as to make it “grow” or shrink).
With, also, some simple jquery:
$('. square).click(function () {
$('. effect).addClass("animation");
$('.text').addClass("text-effect");
setTimeout(function () {
$('. effect).removeClass("animation");
$('.text').removeClass("text-effect");
}, 1500);
});
to add a class to effect and text on click and remove it after animation is done
Then after some basic CSS styles I made the animation for effect:
.animation {
animation-name: background;
animation-duration: 1.5s;
animation-timing-function: linear;
animation-delay: 0s;
animation-iteration-count: 1;
}
#keyframes background {
0% {height:100%; width:100%; opacity:1}
80% {height:100%; width:100%; opacity:1}
99.999% {height:100%; width:100%; opacity:0}
100% {height:0; width:0; opacity:0}
}
And for the text I have just used a transition:
.text {
background-color:rgba(255,255,255,0.6);
width:100%;
text-align:center;
font-size:50px;
color:#fff;
font-weignt:bold;
text-shadow: 1px 1px 0 #000000;
font-family:arial;
padding:20px 0;
transition:all 0.2s linear;
position:absolute;
top:50%;
transform: translateY(-50%);
transition:all 0.2s linear;
}
.text-effect {
padding:10px 0;
font-size:40px;
}
All toguether and adding 8 squares with different colors:
JSFIDDLE
and, as I wrote above, the background fading and shrinking just with
#keyframes background {
0% {height:100%; width:100%; opacity:1}
80% {height:100%; width:100%; opacity:1}
100% {height:0; width:0; opacity:0}
}
JSFIDDLE2
The problem is I can't figure out how to disable kind of scrolling effect to make each picture occupy whole space of box. To create kind of gif image, using only sprit-sheet and CSS.
JSFIDDLE
<title>Hey</title>
<link rel="stylesheet" href="learn.css">
<body>
<div class="animation"></div>
</body>
.animation {
width: 128px;
height: 128px;
margin: 2% auto;
background: url('http://s16.postimg.org/8f5770kpx/sprite.png') center;
animatio-play-state: paused;
animation: play 5s steps(10) infinite;
transorm: translateZ(0);
}
#keyframes play {
100% { background-position: 100px; }
}
This should do the trick:
.animation {
width: 128px;
height: 128px;
margin: 2% auto;
background: url('http://s16.postimg.org/8f5770kpx/sprite.png');
background-position:0px 0px;
animation-play-state: paused;
animation: play 5s steps(10) infinite;
transorm: translateZ(0);
}
#keyframes play {
from { background-position:0px 0px; }
to { background-position:1280px 0px; }
}
DEMO: http://jsfiddle.net/Hyg3C/4421/
So, from-to are actually 'steps', we move background position in 10 steps. If you remove steps parameter from animation - you can get nice infinite scrolling, btw, but this provides 'gif-like' behavior...