How to change stacking order of bg image? - html

How can I make it so that the mouth, eyes, and eyebrows appear on top of the face without changing the html? (The mouth is in the wrong position so I can see it)
<body>
<div id = "shoulders">
<div id = "face">
<div class = "eyebrow" id = "lefteyebrow"> </div>
<div class = "eyebrow" id = "righteyebrow"> </div>
<div class = "eye" id = "lefteye"> </div>
<div class = "eye" id = "righteye"> </div>
<div id = "mouth"></div>
</div>
</div>
</body>
https://jsfiddle.net/tvkhb8zt/

You have several ways to achieve what you want.
As mentioned before you can use z-index. Just remember that if you have complicated structure of a page it is not recommended to use z-index.
Easier approach may be to use simple relative/absolute positioning. Here is a good article of explaining CSS positioning. This is JSfiddle example of your image with positioned mouth and head on top of shoulders.

try css property: z-index
<div class = "eyebrow" id = "lefteyebrow" style="z-index:0"> </div>
<div class = "eyebrow" id = "righteyebrow" style="z-index:1"> </div>

You can add z-index to the CSS. Please note z-index only works on explicity positioned elements, so just add a position: relative as well. Largest z-index will be on top.
So for example:
#face, .eyebrow, .eye {
position: relative;
}
#face {
z-index: 1;
}
.eyebrow {
z-index: 2;
}
.eye {
z-index: 2;
}

Related

css display none select div relative behind

i wanted to know if in css there is a way to inject a display none to the relative of an attribute es;
<div class="classeA">
<div class="classeB" data-userid="1234" >
</div>
</div>
what should i use?
[data-userid="1234"] < .classeA{
display:none !important;
}
what should I do?
I want class classA with display none selecting the data-userid attribute
You could consider using :has(), although as of yet there is no support across any browser.
It would look something like this:
.classeA:has([data-userid="1234"]){
display:none;
}
Demo:
$('.classeA:has([data-userid="1234"])').hide();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="classeA">
<div class="classeB" data-userid="1234">
</div>
</div>

CSS set height related to the width

I'm making a album page with HTML and CSS and I want to set my height of the image to be 9/16 of the width.
HTML code
<div class = "col-md-12" id = "album-list">
<div class = "col-md-4">
<div id = "album-card" style = "border: 1px solid grey;">
<img class = "image_thumbnail" src = "images/sampleImage.jpg" alt = "Thumbnail" />
<div style = "padding-top: 10px; padding-bottom: 5px;">
<p class = "card-text"><strong>TITLE HERE</strong></p>
</div>
</div>
</div>
<!-- More Columns -->
</div>
CSS style
.image_thumbnail {
width: 100%;
}
I saw some posts on stackoverflow with similar questions, and the answer was to use padding-bottom to set the height according to the width. However, since I gave border around #album-card, #album-card gets longer in height than it's supposed to be.
How can I set the heigth 9/16 of the width??
To convert the images:
var images = document.querySelectorAll('.image_thumbnail');
for (var i = 0; i < images.length; i++) {
images[i].height = images[i].width * 0.5625;
}
This will select all the images on the page with the according class and will directly convert the height relative to their width (as: 16 / 9 = 0.5625).
With the help calc() in css3 you can calculate width.
.image_thumbnail {
width: calc((100%*9)/16);
}
This is Referance calc(), This may be helpful for you.

Bootsrap Affix not working

I have added the library for Bootstrap and data-spy attribute where I want to make the div fix when I scroll the page down. But it doesn't work, I have almost tried everything, but not able to figure out the problem.
Is is something like the data-spy attribute doesn't work on class = "row" ?
Here's my code for HTML.
<div class="row">
<h4> HEADING </h4>
<h5>
<div class="row" data-spy="affix" data-offset-top="10">
dsds
Date : <input type="date" name="graph_date" id="graph_date">
</div>
<div class="row">
<div class="graph-hourly">
<div class="loader" id="chart_loader">
<p>Loading...</p>
</div>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_hourly"></div>
</div>
</div>
</div>
and some css :
.affix {
top : 0;
width: 80%;
}
after searching for some solutions, I've added this also,
.affix-top {
width: 100%;
}
.affix-bottom {
position: absolute;
width: 100%;
}
but this solution also dosen't worked for me.
Not sure what the problem is in your case. I copied and pasted your code into a jsfiddle with the bootstrap library and the affix class did work. Though, it worked badly because it affixed the row right when you started scrolling.
Looks like Bootstrap doesn't have a way to set the offset to the current position of the element so I added the following javascript to make it work.
$('#affix-this').affix({
offset: {
top: $('#affix-this').offset().top
}
})
(#affix-this should be changed to the id of the row you want to affix.)
Note the $('#affix-this').offset().top. This makes sure the element gets affixed right when you reach the element's current position.
Second, I removed the html attributes that you had for the affixing.
<div class="row">
<h4> HEADING </h4>
<div class="row" id="affix-this">
dsds Date :
<input type="date" name="graph_date" id="graph_date">
</div>
<div class="row">
<div class="graph-hourly">
<div class="loader" id="chart_loader">
<p>Loading...</p>
</div>
<div id="chart_hourly"></div>
</div>
</div>
Notice the affix-this id was added to the row that you want to affix.
Here is a working JSFiddle with these changes so you can see it in action: https://jsfiddle.net/heraldo/6s4u26m3/4/
First of all delete top:0; from affix class because it will make a issue for you.
now you have two methods pick a one :
1
adding data-spy="affix" which is works fine for me
2
same result ass data-spy but you will need some styling after you complete your page
by adding a position Property for input tag
as ex. :
CSS:
sticky{
position:fixed;
}
and HTML :
<input type="date" name="graph_date" class="sticky" id="graph_date">
Update 1
this Jquery code can detect a scroll event so when user scroll down it will make the div tag sticky or "affix"
$(function() {
$(window).scroll(function() {
var aTop = "100";
if ($(this).scrollTop() >= aTop) {
$('#affix-this').css( "position", "fixed" );
$('#affix-this').css( "top", "0" );
$('#affix-this').css( "width", "100%" );
}
});
});
change the aTop variable with the height you want (in pixel) so when the user scroll down 100px the div become sticky
a JSfiddle example
Update 1.1
a bit smarter Jquery code do the same but get the height automatically from a another element this can be good if you format your page to something similar to this
$(function() {
$(window).scroll(function() {
var aTop = $('id').height();
if ($(this).scrollTop() >= aTop) {
$('#affix-this').css( "position", "fixed" );
$('#affix-this').css( "top", "0" );
$('#affix-this').css( "width", "100%" );
}
});
});
Make sure the element to which you're adding data-spy="affix has been created in the DOM before your Bootstrap scripts load. I ran into an issue where I was adding data-spy="affix" in my HTML, but it was wrapped up in a section that wasn't rendering, thanks to data-ng-if. My HTML was created after my Bootstrap had loaded, so the <div> I wanted to stick to the top of the screen never stayed in a fixed position. If you can, use data-ng-show, or something that merely hides HTML, rather than prevents it from being created on page load.

relocating divs of an Html page using css

I have HTML structure as shown below. I want to relocate the position of divs such that 'calc' div should move to 'region-content' div and should appear on the right end. Is it possible to achieve this using css? Can any one provide me some references to work on this using css, etc.
<div class='region-content'>
<form id='responseform'>
<div class='content '>
<div class ='formulation '>
<div class='qtext '>
<div class='calc '></div>
</div>
</div>
</div>
</form>
</div>
You cannot achieve the change in DOM structure with CSS. So, calc div can't be moved to region-content div. You need to do some javascript work for that.
However, styling it to appear where you want should be possible. Please provide your css code, if possible a jsfiddle, if this part is still troubling you.
You may try this.
.region-content { position: relative; }
.calc { position: absolute; top: 0; right: 0; }
Other then this you will also need to change parameter for width to make this possible. Since you just posted html structure and not content within it including respective css, this is how I can guess the solution for you.

CSS hover - can it effect multiple divs with same class name

I have 5 div's all with the same class name like this:
CSS:
.test:hover{
color:red;
}
HTML:
<div class="test"></div>
<div class="test"></div>
<div class="test"></div>
<div class="test"></div>
<div class="test"></div>
Imagine for a moment these Div's are in different parent div's on the page...
I'm trying to find a way so they all change to color:red if i hover my mouse over any of the 5 rather than just the one in question changing...
I can't wrap them in a parent and give that parent a hover how ever... they are not sharing the same parents in the first place.
Does CSS provide a way to do this or am I going to have to rest to JavaScript?
One (plain/vanilla) JavaScript approach that works (in compliant browsers, which support [].forEach(), and document.querySelectorAll()), given that CSS cannot (yet) perform this task, is:
function classToggle (evt, find, toggle) {
[].forEach.call(document.querySelectorAll('.' + find), function(a){
a.classList[evt.type === 'mouseover' ? 'add' : 'remove'](toggle);
});
}
var els = document.querySelectorAll('.test');
for (var i = 0, len = els.length; i<len; i++){
els[i].addEventListener('mouseover', function(e){
classToggle(e, 'test', 'highlight');
});
els[i].addEventListener('mouseout', function(e){
classToggle(e, 'test', 'highlight');
});
}
JS Fiddle demo.
References:
Array.prototype.forEach().
document.querySelectorAll().
Element.classList.
Function.prototype.call().
You could use JQuery to pretty easily achieve what you want... copy this to an .html file to test it...
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$(document).ready(function() {
$(".test").hover(
function() {
$(".test").css("background-color", "red");
}, function() {
$(".test").css("background-color", "");
}
);
});
</script>
</head>
<body>
<div class="test">My Div</div><br />
<div class="test">My Div</div><br />
<div class="test">My Div</div><br />
<div class="test">My Div</div><br />
<div class="test">My Div</div>
</body>
</html>
It's impossible to select element's parent via CSS nowadays. So also it's impossible to select element by one element and general parent. It's like a tiny proof.
Here is the code:
css:
.sample{
background: none repeat scroll 0 0 #FFFFFF;
height: 105px;
opacity: 0.1;
position: absolute;
top: 0;
width: 5%;
}
.sample:hover ~ div{
color:red;
cursor:pointer;
}
html:
<div class="sample"></div>
<div class="container">
<div class="test">1111</div>
</div>
<div class="container">
<div class="test">2222</div>
</div>
<div class="container">
<div class="test">3333</div>
</div>
<div class="container">
<div class="test">4444</div>
</div>
<div class="container">
<div class="test">5555</div>
</div>
Check the demo here: http://jsfiddle.net/eN49z/
Quick answer: it is not possible via CSS-only to achieve the effect that you are looking for, as CSS is unable to travel up the parent, but only down the DOM tree to affect elements.
You can, however, rely on JavaScript to achieve the effect. In my example I have chosen to rely on jQuery. You can use various methods to get all other <div>s with the class test, but it depends on how they are nested - are they nested under parents that are siblings, and the level of nesting and etc.
Here is an example markup of the scenario you have described:
<div>
Parent 1
<div class="test"></div>
</div>
<div>
Parent 2
<div class="test"></div>
</div>
<div>
Parent 3
<div class="test"></div>
</div>
The CSS would be simple. The .hover class (not the :hover state) is added dynamically by jQuery (see below):
.test:hover, .test.hover {
background-color: red;
}
The JS would be something like:
$(function() {
$(".test").hover(function() {
// Find '.test' in all siblings of a specific '.test' parent
$(this).parent().siblings().find(".test").addClass("hover");
}, function() {
// You can refine the criteria of which '.test' should be selected.
$(document).find(".test").removeClass("hover");
});
});
http://jsfiddle.net/teddyrised/fHwFf/