Hopefully simple enough, in the below example I want the blue section of the link to be clickable (as a link) but the red section not to be. I am planning to subscribe to the red section's onclick event after with Javascript.
Spent an hour on this and getting nowhere! Does anybody know how to do this?
.outer{
width:300px;
height:50px;
background-color:blue;
position:relative;
display:block;
color:white;
z-index:1;
}
.inner{
width:150px;
height:25px;
background-color:red;
top:0;
right:0;
position:absolute;
pointer-events:none;
z-index:2;
}
<a href="http://google.co.uk" class="outer">
Clickable
<div class="inner">
Not clickable
</div>
</a>
I thought the inner div having a higher z-index and no pointer events would do it, but doesn't seem to work.
Anybody have any ideas?
Instead of hacking the html like that, which is a very bad practice. Why not:
.outer {
background-color: red;
display: inline-block;
}
.inner {
background-color: blue;
width: 300px;
display: inline-block;
}
span {
display: inline-block;
}
<div class="inner">
Clickable
<span>Not clickable</span>
</div>
use preventDefault method.
$('.inner').click(function(e){
e.preventDefault();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>
<a href="http://google.co.uk" class="outer">
Clickable
<div class="inner">
Not clickable
</div>
</a>
Related
I would like to get a div within a container to extend to the edge of the page.
As you can see in my fiddle I have managed to do this, however the red 'bar' goes off the page so the user is able to scroll to the right.
I would like it to function how it does now but with the red div touching the side of the page and going no further.
Things to keep in mind:
I am trying to keep it pure HTML/CSS for now,
The code must be responsive,
This will also be used in a CMS so any length of text could be added.
.container{
background-color:grey;
}
.row{
padding-top:30px;
padding-bottom:40px;
}
.row_outer{
height:50px;
background-color:blue;
display: block;
float:right;
clear:both;
}
.text{
display: inline-block;
}
.holder{
width: 0px;
float:right;
height: 100%;
}
.bar{
height: 50px;
background-color:red;
position:absolute;
display:block;
width:100%;
}
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="row_outer">
<div class="text">Test Text 78oo76o689o 76o 68k yuk uik</div><div class="holder"><div class="bar">
</div></div>
</div>
</div>
</div>
Thank-you.
I have an Angular app with some buttons that change color on click depending on if they are clicked or not.
<div class="filter ng-click="seeButton()">
<div class="filter-icon'"></div>
<div class="filter-hover">
<span class="filter-text">Se</span>
</div>
</div>
However, I have a designer who likes some animations on websites.
I want the div class filter-hover to reveal itself when hovering the parent element filter. It should reveal itself from the bottom up. It is located in the bottom of the div and the filter-hover should stay at the bottom of the div. I use Angular and it is possible for me to use angular-animate.
How do I achieve this?
let's give you a quick CSS class. if element a is right next to element b like this:
<a id="a"></a>
<div id="b"></div>
You can use #a:hover + #b. If b is a descendent to a like this:
<a id="a">
<div id="b"></div>
</a>
You can use #a:hover #b. If there are elements between a and b but they are in the same scope:
<a id="a"></a>
<a></a>
<ol></ol>
<h1></h1>
<div id="b"></div>
You can use #a:hover ~ #b.
In your case you will use #a:hover #b like this:
.filter-hover {
opacity: 0;
transition: opacity 0.5s;
}
.filter:hover .filter-hover {
opacity: 1;
}
.filter {
background: grey;
}
<div class="filter" ng-click="seeButton()">
<div class="filter-icon'"></div>
<div class="filter-hover">
<span class="filter-text">Se</span>
</div>
</div>
DEMO
HTML
<div id="parent">
<div id="child">
</div>
CSS
#parent{
width:200px;
height:200px;
background-color:tomato;
}
#child{
width:50px;height:50px;
background-color:yellow;
display:none;
}
#parent:hover #child{
display:block;
}
I like use this technique http://jsfiddle.net/ps5nkpL5/1/ to simply show am element growing or animating from a direction. There are better techniques with javascript, but for with just css, this is what I would do.
.filter{
height: 100px;
width: 300px;
background: #dedede;
position: relative;
}
.filter-hover{
//background: #f1f1f1;
text-align:center;
height: 40px;
position:absolute;
overflow:hidden;
width:75px;
bottom:10px;
right:10px;
}
.button{
background: #252525;
color:#ffffff;
display:block;
text-align:center;
line-height:40px;
position: absolute;
width: 100%;
bottom:-40px;
}
.filter:hover .filter-hover .button{
bottom: 0px;
-webkit-transition: .5s;
transition: .5s;
}
I am trying to position the second image inline next to the one before, the second image is smaller and i want it to sit on the same bottom line next to the larger one next to it. this will create a gap above the second image where i can put a small bit of text.
My problem is when i play around with background-size:, height: and width: to change the size of the image it just goes to the top left hand corner of its surrounding div.
I plan on having 4 more small image next to the small one so I'm asking please could anyone sort out the positioning of the divs and css so that i can easily add more next to the prior one,
Here is an image to give you an understanding of what i am trying to achieve, The red box shows where i want it to be positioned, and the other red box is where i will have the next skin.
LINK
Things i have tried:
Bottom:0
margin-top ( to push it down ) though this does not leave room for me to add text above the smaller images
padding-top:
Here is my current CSS:
#secondinner {
width:980px;
margin:0 auto;
overflow: hidden;
}
#dailyskin {
width:120px;
height:20px;
background-color:#336699;
color:white;
font-size:14px;
text-align:center;
padding-top:1px;
}
#topskin {
background-image:url(images/topskins/1f.png);
background-size:110px;
height:220px;
background-repeat:no-repeat;
width:110px;
dislpay:inline-block;
float:left;
margin-top:5px;
}
#topskin2 {
background-image:url(images/topskins/1f.png);
background-size:80px;
height:150px;
background-repeat:no-repeat;
width:80px;
dislpay:inline-block;
float:left;
margin-top:5px;
}
#downloadbutton1 {
width:100%;
}
#firstskin {
width:110px;
overflow:hidden;
float:left;
}
#secondskin {
width:100px;
overflow:hidden;
float:left;
padding-left:10px;
}
Here is the HTML:
<div id="secondinner">
<div id="dailyskin">Todays Daily Skin!</div>
<div id="firstskin">
<div id="topskin"></div>
<button id="downloadbutton1" type = "button" name = "Download"> Download </button>
</div>
<div id="secondskin">
<div id="topskin2"></div>
<button id="downloadbutton1" type = "button" name = "Download"> Download </button>
</div>
</div>
This is the third section to the index page.
</div>
Here is a JS fiddle to show you what i mean,
http://jsfiddle.net/bjbear123/qdwgpaqc/
display: table-cell; with a vertical-align: bottom could be a good solution.
Have a jsBin!
HTML
<div class="skin-wrap">
<div>
<img src="http://www.placehold.it/100X300" />
<button>Download</button>
</div>
<div>
<p>text above </p>
<img src="http://www.placehold.it/100X200" />
<button>Download</button>
</div>
</div>
This is the third section to the index page.
CSS
.skin-wrap {
display: table;
}
.skin-wrap > div {
display: table-cell;
width: 100px;
vertical-align: bottom;
padding: 10px;
}
And if you don't want / are not able to use table-cell as misterManSam answered you can use nested divs with position absolute.
.wrapper{
position: relative;
height: 200px;
width: 100px;
}
.content{
position: absolute;
bottom: 0;
}
<div class="wrapper">
<div class="content">
<img src="whatever.jpg" />
</div>
</div>
And there you have a little jsbin http://jsbin.com/jiqakefu/1/
One easy solution is to increase the top margin of topskin2.
#topskin2 {
background-image:url(images/topskins/1f.png);
background-size:80px;
height:150px;
background-repeat:no-repeat;
width:80px;
dislpay:inline-block;
float:left;
margin-top:75px;
i tried this on jsfiddle both download button were inline.
You can set margin as per your need, if you want space between both then you can use margin-left to create gap.
you were right doing it through bottom:0;
The thing you missed was to set position:absolute; and for outer div position:relative;
Here's a fiddle: http://jsfiddle.net/Nive00/qdwgpaqc/2/
I am trying to create a div that is a button by putting an anchor inside a div.
HTML
<div class="div1" style="width:300px;">
hello
</div>
CSS
.div1 {
background-color:red;
color:white;
margin:5px;
border-width:5px;
border-style:solid;
padding:10px;
border-radius:5px;
text-align:center;
background: #494949 !important;
}
JSFiddle: http://jsfiddle.net/BzFyS/
I think it is not working because osomething simple I am missing with positioning. Any tips?
Thanks
The simplest way: add this css:
.div1 a {
display: block;
}
That's it.
If you want the whole div be clickable (including the padding area):
.div1 {
background-color:red;
color:white;
margin:5px;
border-width:5px;
border-style:solid;
padding:0px; /* set to 0 */
border-radius:5px;
text-align:center;
background: #494949 !important;
}
.div1 a {
display: block;
padding:10px;
}
Demo: http://jsfiddle.net/BzFyS/2/
If you want the whole div to be clickable, you may do this :
HTML
<div id="div1" style="width:300px;">
hello
</div>
CSS
#div1 {
background-color:red;
color:white;
margin:5px;
border-width:5px;
border-style:solid;
padding:10px;
border-radius:5px;
text-align:center;
background: #494949 !important; /* do you really need that ? */
cursor: pointer;
}
JavaScript
document.getElementById('div1').onclick=function(){
// do something
}
But then you don't really need the a element.
Demonstration
Try to add to your CSS:
.div1 a {
display: block;
}
You have to put the tags around the div like this:
<a href="#"><div class="div1" style="width:300px;">
<p>hello</p>
</div></a>
This will work.
I am assuming you want this div to be a "button" yes?
The simple solution is to define the size of the <a> by using padding and display: block;
you can still define the colors, margins, and position of the <div>... but the clickable area is in the <a>
Please check http://jsfiddle.net/mtN6R/9/
.tooltip{
color:red;
}
.wrapper {
overflow:hidden;
height:50px;
border:1px solid black;
width:50px;
position:relative;
}
<div class="wrapper">
<div class='tooltip'>A big tooltip which should be visible fully</div>
A lot of text<br>
A lot of text<br>
</div>
I need .tooltip make fully visible but I can't take it outside wrapper. Can we stylize that example so .tooltip will be shown above wrapper and the rest content will stay as is?
I think what you want is to have just your content itself have overflow: hidden on it:
CSS:
.tooltip{
color:red;
}
.wrapper {
position:relative;
}
.inner {
overflow:hidden;
height:50px;
border:1px solid black;
width:50px;
}
HTML:
<div class="wrapper">
<div class='tooltip'>A big tooltip which should be visible fully</div>
<div class="inner">
A lot of text<br>
A lot of text<br>
</div>
</div>
Sure, give tooltip an absolute position and then move things around as needed as in this jsFiddle example
.tooltip{
color:red;
position: absolute;
top:0;
}
.wrapper {
overflow:hidden;
height:50px;
border:1px solid black;
width:50px;
margin-top: 20px;
}