I'm wanting to create some boxed content that reveals alternate content when hovered. I've found a few examples from others questions, and tried to utilise them to what I want, but not having much luck.
The perfect example of what I'm trying to achieve is the 3 hover buttons under the "Build a Smarter WordPress Site" (just below the fold) on http://www.copyblogger.com/.
I'm assuming the static state includes an icon/image & text below, and the hover state includes an icon/image, descriptive text, and a hyperlinked button.
This is exactly what I'm wanting to reproduce. Could anyone please provide an example of this so I can understand what I need to do?
Thanks.
Edit: I understand the code Copyblogger have used from what little I can retrieve through "Inspect Element". I'm not looking to use their code - as I cannot find all the connecting commands, but something that acts the same way.
for code sample that showed in your sent link
<li class="design">
<div class="icon">Design</div>
<p>The Genesis design framework, support and dozens of stunning themes.</p><div class="btn-primary-small">Find Out More</div>
</li>
the css will be
li.design a{
display:none;
}
li.design:hover a{
display:block;
}
Here is a fiddle. There are 3 or 4 ways to do this, but you just want someone to do it for you, so I wont go into those specifics. I wrote it mobile first and assuming you can use box-sizing: border-box; - so if you can't do that - then you just add the proper widths and you'll be good to go.
HTML
<a href="#" class="block-icon">
<div class="block top-stuff">
<div class="text-w">
Top stuff
</div>
</div>
<div class="block under-stuff">
<div class="text-w">
<h4>Under stuff</h4>
<p>Some paragraph</p>
<div class="button">Call to action</div>
</div>
</div>
</a>
CSS
*, *:before, *:after {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
a {
text-decoration: none;
color: inherit;
}
.block-icon {
position: relative;
display: block;
width: 100%;
float: left;
border: 1px solid red;
text-align: center;
height: 10em;
margin-bottom: 1em;
}
.block-icon .block {
height: 100%;
padding: .5em;
}
.block-icon .text-w {
width: 100%;
height: 100%;
display: inline-block;
vertical-align: middle;
border: 1px solid blue;
}
.block-icon .text-w:after {
content: "\0020";
height: 100%;
display: inline-block;
vertical-align: middle;
/* this creates a second element so that they can align vertical middle to one another */
}
.top-stuff {
position: absolute;
top: 0;
left: 0;
width: 100%;
background-color: white;
opacity: 1;
transition: opacity .5s linear;
}
.under-stuff {
background-color: #eee;
}
a:hover .top-stuff {
opacity: 0;
transition: opacity .1s linear;
}
.button {
width: auto;
border: 1px solid black;
}
#media (min-width: 500px) {
.block-icon {
width: 32%;
margin-right: 2%;
}
.block-icon:nth-of-type(3) {
margin-right: 0;
}
} /* end break-point */
Related
This a simple sign up formed I've made my school project and for one to sign up is to choose their roles. There's not much to this but I can't seem to figure how to fix this border problem under the anchor? How do I make it so that the space at the top is equivalent to the bottom as well?
enter image description here
body {
font-family: Arial, Helvetica, sans-serif;
}
* {
box-sizing: border-box;
}
.center {
position: absolute;
top: 150px;
width: 99%;
text-align: center;
font-size: 18px;
}
.box {
margin: auto;
border: 1px solid #ccc;
width: 30%;
padding: 15px;
}
a {
background-color: #333;
text-decoration: none;
display: block inline;
color: white;
padding: 14px 20px;
margin: 8px 0px;
border: none;
cursor: pointer;
width: 100%;
opacity: 1.5;
}
a:hover {
background-color: #ddd;
color: black;
}
ul {
list-style-type: none;
}
li {
display: inline;
}
<div class="center">
<div class="header">
<h2>WELCOME TO SMK USJ 12<br/> ENGLISH QUIZ</h2>
</div>
<form action="role.php" method="post">
<div class="box">
<h3>Choose your role<br/> You are a...</h3>
Teacher</button>
Student
</div>
</div>
You have a typo with the display property on the a tags. I think you meant to use inline-block instead of block inline?
a {
/* ... */
display: inline-block;
/* ... */
}
The correct solution (in my opinion) would be to change your markup a bit, employ a wrapping container for the buttons and then apply the proper styles to that container. However, without changing your markup - you can still achieve what you are looking for, by adding some line-height to your buttons. Something like:
.box a{
line-height: 5em;
}
Should put you in the ball-park of what you are trying to achieve.
When hovering over a in html I want to display a text. Right now I have it this way:
echo "<td onmouseover='' style='cursor: pointer; background-color:#ffeb3b' title=$text id=$text></td>";
The problem is that it looks very small and without design.
How could I make it look bigger and with a little look?
I would like to do something similar to this in html.A box that appears on the right
For more information look here
body {
text-align: center;
}
.tooltip {
position: relative;
display: inline-block;
cursor: default;
}
.tooltip .tooltiptext {
visibility: hidden;
padding: 0.25em 0.5em;
background-color: black;
color: #fff;
text-align: center;
border-radius: 0.25em;
white-space: nowrap;
/* Position the tooltip */
position: absolute;
z-index: 1;
top: 100%;
left: 100%;
transition-property: visibility;
transition-delay: 0s;
}
.tooltip:hover .tooltiptext {
visibility: visible;
transition-delay: 0.3s;
}
<div class="tooltip">Hover over me
<span class="tooltiptext">Tooltip text</span>
</div>
This is how you can do it. First, create the main element, I'm using a text, and next to it add the text you wish to show on hover. Style everything according to your taste. Make sure you set the display of the extra text to none. Basically, we'll hide it and show it only when someone hovers over the main element.
Now, in the CSS, I've added .Main-Text:hover + .Extra-Text CSS Selector to achieve what we are trying to do. This basically means that when someone hovers on the element with class Main-Text, something will happen to the element with the class Extra-Text.
You can read about this more here.
* {
margin: 0px;
padding: 0px;
}
body {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 20px;
min-height: 100vh;
}
.Main-Text:hover + .Extra-Text {
display: block;
}
.Extra-Text {
background-color: #FFFFFF;
margin-top: 10px;
width: 200px;
border: 2px solid #000000;
padding: 10px;
font-size: 16px;
display: none;
}
<html>
<div>
<p class="Main-Text">
Hover me to know more about me.
</p>
<div class="Extra-Text">
<p>
This is the extra information that will be displayed when the text is hovered.
</p>
</div>
</div>
</html>
I don't think so if this is something you are looking for but it's worth mentioning. You can use the title attribute in the HTML Elements to display some text when the user hovers over the element. Try it yourself. Run the snippet below and hover over the text.
* {
margin: 0px;
padding: 0px;
}
body {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 20px;
min-height: 100vh;
}
<html>
<div>
<p class="Main-Text" title="This is some extra text">
Hover me to know more about me.
</p>
</div>
</html>
I want each button "Read more" of each div to be aligned in the same level (and in this case at the bottom of the div). The problem is that I don't want to give a specific height to the divs and neither change any markup or style.
I could use a bunch of pseudo class selectors but I would like to keep the code simple and maybe there's a simpler way.
Here's the working fiddle
.btn{
display: inline-block;
font-family: 'Oswald', sans-serif;
font-weight: 400px;
padding: 5px 10px;
border: 2px solid #1AC4F8;
color: #1AC4F8;
cursor: pointer;}
Flexbox can do that.
It will set all the columns to equal height and tell the button to be at the bottom of each column.
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
*::before,
*::after {
box-sizing: border-box;
}
.row {
display: flex;
}
#services {
background-color: rgb(265, 265, 265);
color: #424242;
}
#services .col-3 {
text-align: left;
float: none;
display: flex;
flex: 0 0 25%;
padding: 10px;
flex-direction: column;
}
#sevices h3 {
margin: 10px 0
}
.btn {
margin-top: auto;
display: inline-block;
font-family: 'Oswald', sans-serif;
font-weight: 400px;
padding: 5px 10px;
border: 2px solid #1AC4F8;
color: #1AC4F8;
cursor: pointer;
-webkit-transition: color 0.8s, background-color 0.8s;
transition: color 0.8s, background-color 0.8s
}
<section id="services">
<!-- Services Starts Here -->
<div class="wrapper">
<h2>SERVICES</h2>
<div class="divider"></div>
<div class="row">
<div class="col-3">
<h3>Consulting and audit</h3>
<p>Get help to accelerate your company online from our highly experienced specialists. It is as good as it sounds!</p>
Read more
</div>
<div class="col-3">
<h3>Web Development</h3>
<p>Professional custom e-commerce and web design to let your business grow at a rapid pace. See how we do that.</p>
Read more
</div>
<div class="col-3 right-align">
<h3>Search Engine Optimization</h3>
<p>Want to be on Page 1 of Google and Bing? Read about our SEO services that drive more potential customers.</p>
Read more
</div>
<div class="col-3 right-align">
<h3>Pay Per Click Management</h3>
<p>Attract highly relevant audience with Google Adwords, Display, Retargeting, Facebook, YouTube, Twitter.</p>
Read more
</div>
</div>
</div>
</section>
Assuming I've understood you correctly, I've made the following amendments:
.btn{
display: inline-block;
font-family: 'Oswald', sans-serif;
font-weight: 400px;
padding: 5px 10px;
border: 2px solid #1AC4F8;
color: #1AC4F8;
cursor: pointer;
-webkit-transition: color 0.8s, background-color 0.8s;
transition: color 0.8s, background-color 0.8s;
position: absolute;
bottom: 0px;
}
.wrapper {
position: relative;
}
added position: absolute; to your btn class
added bottom: 0px to compliment the position (again to the btn class)
added position: relative; to a wrapper class so btn knows what it is positioning itself within.
You may need to update your existing CSS to adjust to the changes.
Updated Fork:
https://jsfiddle.net/exaboofu/
One solution entails using flexbox and absolute positioning:
https://jsfiddle.net/aLbu6frL/6/
.row {
display: flex;
flex-direction: row;
padding-bottom:40px;
}
.column {
flex: 0 0 auto;
position: relative;
}
.btn-bottom {
position: absolute;
bottom: -40px;
left: 0px;
right: 0px;
text-align:center;
}
Please add some more CSS in your existing and your button align with bottom please look below CSS code:
#services .right-align h3, #services .right-align p{
text-align: right;
}
#services .right-align .btn{
text-align:left;
}
.btn{
bottom: 0;
position:absolute;
}
You can set p tag a min-height. I just try it and it work's for me see sample code below. You can set p tag height based on your need.
#services .row .col-3 p {
width: 100%;
height: 300px;
}
Up until a couple days ago using position:absolute; and bottom:-36px was enough to hide the controls down the page, and they would popup whenever the mouse was hovered over the player. Now I'm able to scroll down to see them. How can I fix this while keeping the same slide-up effect?
Also, one more thing... I set the controls div with line-height:36px expecting it to be 36px in height but it is actually 38px (making bottom:-36px kind of useless since 2px are visible). The timer and the P, M and F divs get two extra px on the top and the seek bar gets them on the bottom. Where are these extra px coming from?
Sample
Any help on how to fix these issues and understand what's going on will be greatly appreciated. Thank you.
EDIT1:
Thanks to Fahad I managed to solve my first issue. The snippet didn't work outside of codepen but I fixed it adding position:relative; to the parent div. It still is unclear to me why line-height adds those extra px, though.
Giving the parent div a relative position raised another problem, don't ask me why but sometimes I need to scroll inside the "player" (well, you can ask) and when I do the controls don't stay at the bottom. Please see for yourselves:
Sample
EDIT2:
Apparently that can be easily solved by replacing position:absolute; with position:fixed; in the controls div. I'm still testing just in case this little change is messing with anything else.
You can assign overflow-y: hidden; to your body tag using CSS (to disable vertical scrolling) and change the bottom value to -38px.
html,
body {
font-family: Verdana, Helvetica, Arial, sans-serif;
color: #EEE;
margin: 0;
overflow-y: hidden;
}
#player {
background-color: #333;
text-align: center;
height: 100vh;
}
#toggle {
margin: auto;
width: 500px;
font-size: 24px;
line-height: 60px;
background-color: #B83B3B;
}
#toggle:hover + #controls {
bottom: 0;
}
#controls {
position: absolute;
left: 0;
right: 0;
bottom: -38px;
line-height: 36px;
background-color: #B83B3B;
transition: bottom 0.3s ease;
}
#left {
float: left;
}
#right {
float: right;
}
#curTime {
font-size: 13px;
font-weight: bold;
margin: 0px 8px;
display: inline-block;
vertical-align: middle;
}
#center {
overflow: hidden;
}
#seekBar {
-webkit-appearance: none;
outline: none;
background-color: #1F7783;
height: 6px;
margin: 0;
width: 100%;
}
#seekBar::-webkit-slider-thumb {
-webkit-appearance: none;
background-color: #EEE;
height: 12px;
width: 12px;
border-radius: 12px;
cursor: pointer;
opacity: 0.8;
}
.button {
margin: 0px 8px;
font-size: 24px;
display: inline-block;
vertical-align: middle;
}
<div id="player">
<div id="toggle">Hover to show controls.</div>
<div id="controls">
<div id="left">
<div class="button">P</div>
<span id="curTime">0:01</span>
</div>
<div id="right">
<div class="button">M</div>
<div class="button">F</div>
</div>
<div id="center">
<input type="range" id="seekBar" step="any">
</div>
</div>
</div>
Here's the example on CodePen.
I have a timeline on a site I'm trying to recreate and when I resize the window to mobile, the divs get separated. I'm a little far into the site and am very cautious about what I need to do to make this work. The timeline has icons (which have their own div) & a icon background (which have their own div too) but I think I need to wrap them around in one larger div to make this work, but not sure how.
See images here for a before I resize and after I resize:
See how the icons get separated from the background?
Html code for each item in timeline:
<div class="timeline_item">
<div class="timeline_time"><p><em>1 hr ago</em></p></div>
<div class="icon_background"></div>
<div class="timeline_icon "><i class="ss-icon">doc</i></div>
<div class="timeline_text"><p>You read the article </p> </div>
</div>
CSS:
.timeline_item {
width: 100%;
padding-bottom: 17%;
}
.timeline_item .timeline_time {
float: left;
width: 20%;
}
.timeline_item .timeline_icon {
float: left;
width: 1%;
}
.timeline_item .timeline_text {
float: left;
width: 65%;
padding-left: 3%;
}
.timeline_icon {
margin-left: -4%;
margin-top: 2.5%;
}
Without access to a proper Jsfiddle Demo, here's one suggestion with a reduced HTML structure which uses pseudo-elements.
You could use an icon-font, sprite or whatever where I have used a single letter.
Codepen Demo
HTML
<div class="timeline">
<article class="timeline_item">
<div class="timeline_time">
<p>1 hr ago<p>
</div>
<div class="timeline_text" data-event-type="doc"><p>You read the article </p> </div>
</article>
<article class="timeline_item">
<div class="timeline_time">
<p>1 hr ago<p>
</div>
<div class="timeline_text" data-event-type="alert"><p>You have a 'Do Not Miss' Meeting scheduled for tomorrow 9a.m.</p> </div>
</article>
<article class="timeline_item">
<div class="timeline_time"><p>1 hr ago<p>
</div>
<div class="timeline_text" data-event-type="video"><p>You watched a video</p> </div>
</article>
</div>
CSS
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
margin: 0;
padding: 0;
}
.timeline {
width:50%;
margin: 1rem auto;
border:1px solid lightgrey;
}
.timeline_item {
display: table;
width:100%;
}
.timeline_time,
.timeline_text {
display: table-cell;
padding:1rem 2rem;
}
.timeline_time {
width:25%;
text-align: right;
border-right:1px solid lightgrey;
}
.timeline_text {
position: relative;
}
[data-event-type]:before {
position: absolute;
content:"";
width:32px;
height:32px;
line-height: 32px;
text-align: center;
color:white;
left:0;
top:0;
border-radius: 50%;
transform:translate(-50%,50%);
}
[data-event-type="doc"]:before {
content:"D";
background: #00f;
}
[data-event-type="alert"]:before {
content:"A";
background: #f00;
}
[data-event-type="video"]:before {
content:"V";
background: #0f0;
}
The techniques shown here might help you wit your current issue(s).
There are, of course, alternatives to this layout method, including floats and actual tables. some of those will require 'fixes' to achieve the 'equal heights' that is native to CSS tables.
Since there was no complete html or css, this is a mobile first approach that requires fairly decent css skills to follow, but it starts off in a logical way for small viewports and adjusts fluidly. The min-width is where the layout for larger view ports starts. The styles before this are global (shared by all view port sizes).
DEMO: http://jsbin.com/zerijo/1/
http://jsbin.com/zerijo/1/edit
CSS:
/*demo only body */
body {
font-family: sans-serif;
background:#fff;
padding:5%;
}
/* ---------- timeline styles ------------ */
.timeline_wrapper:after, .timeline_item:after {
visibility: hidden;
display: block;
font-size: 0;
content: " ";
clear: both;
height: 0;
}
.timeline_wrapper, .timeline_item {
display: inline-block
}
* html .timeline_wrapper, * html .timeline_item {
height: 1%
}
.timeline_wrapper, .timeline_item {
display: block
}
.timeline_wrapper,
.timeline_wrapper div,
.timeline_wrapper *:before,
.timeline_wrapper *:after {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
.timeline_wrapper {
position: relative;
padding-top: 10px;
line-height: 1.5;
}
.timeline_wrapper:before {
position: absolute;
top: -5px;
bottom: 10px;
left: 15px;
content: "";
height: 100%;
display: block;
border-right: 1px solid #777;
width: 1px;
z-index: -1;
}
.timeline_wrapper p {
margin: 0
}
.timeline_icon i {
background: red;
display: block;
border-radius: 50%;
width: 30px;
height: 30px;
line-height: 32px;
text-align: center;
font-size: 15px;
color: #fff;
float: left;
}
.timeline_text {
float: left;
width: 100%;
padding: 0 0 0 40px;
}
.timeline_time {
padding-left: 40px
}
.timeline_item {
width: 100%;
position: relative;
}
.timeline_item:not(:last-child) {
padding-bottom: 30px;
}
#media (min-width:480px) {
.timeline_wrapper {
position: relative;
padding-top: 10px;
}
.timeline_wrapper:before {
left: 27%
}
.timeline_item > div {
float: left;
position: relative;
}
.timeline_time {
width: 22%;
text-align: right;
padding: 0;
left: -10%;
}
.timeline_icon {
width: 10%;
min-height: 50px;
left: 22%;
top:-5px;
}
.timeline_icon i {
margin: 0 auto;
float: none;
}
.timeline_text {
float: left;
width: 100%;
margin-left: -37%;
padding: 0 0 0 37%;
}
}
HTML -- structured differently for mobile then adjusted position at the min-width:
<div class="timeline_wrapper">
<div class="timeline_item">
<div class="timeline_icon">
<i class="your-icon"></i>
</div>
<div class="timeline_time">
<p><em>1 hr ago</em></p>
</div>
<div class="timeline_text">
<p>Lack of peppering one's sentences with gerunds.Lack of peppering one's sentences with gerunds. Lack of peppering one's sentences with gerunds. You read the article </p>
</div>
</div>
<div class="timeline_item">
<div class="timeline_icon">
<i class="your-icon"></i>
</div>
<div class="timeline_time">
<p><em>1 hr ago</em></p>
</div>
<div class="timeline_text">
<p>You read the article Lack of peppering one's sentences with gerunds. Lack of peppering one's sentences with gerunds.Lack of peppering one's sentences with gerunds.Lack of peppering one's sentences with gerunds.</p>
</div>
</div>
<div class="timeline_item">
<div class="timeline_icon">
<i class="your-icon"></i>
</div>
<div class="timeline_time">
<p><em>1 hr ago</em></p>
</div>
<div class="timeline_text">
<p>You read the article.</p>
</div>
</div>