I have the following html:
<div class="parent">
<div class="sibling" data-modal=".child"></div>
<div class="child"></div>
</div>
When I hover over the sibling element, its border changes color and causes the child to show. I want to hold that styling whether sibling or child are hovered over.
I could add the css permanently to sibling using JS, then remove it on mouseleave but would prefer a css solution if possible
CSS:
.parent {
position:relative;
width:250px;
height:200px;
background-color: #f1f1f1;
}
.sibling {
width:100px;
height:30px;
padding:6px;
border:4px solid red;
}
.sibling:hover {
border-color: green;
}
.child {
position: absolute;
width:200px;
height:50px;
top:70px;
background: blue;
display: none;
}
Is this possible?
Here's a fiddle
i am not so sure if i get you right, but is this something you would need?
.parent {
position:relative;
width:1000px;
height:200px;
}
.sibling {
width:100px;
height:30px;
padding:8px;
border:1px solid red;
}
.sibling:hover {
border-color: blue;
}
.sibling:hover + .child {
display: block;
}
.child {
position: absolute;
width:200px;
height:50px;
top:60px;
background: blue;
display: none;
}
<div class="parent" data-modal="child">
<div class="sibling"></div>
<div class="child">test</div>
</div>
pure css solution
Yes,
Add a hover condition to the parent.
.parent {
position:relative;
width:250px;
height:200px;
background-color: #f1f1f1;
}
.sibling {
width:100px;
height:30px;
padding:6px;
border:4px solid red;
}
.parent:hover .sibling, /* here */
.sibling:hover {
border-color: green;
}
.child {
position: absolute;
width:200px;
height:50px;
top:70px;
background: blue;
display: none;
}
<div class="parent">
<div class="sibling" data-modal=".child"></div>
<div class="child"></div>
</div>
Yes its possible
$( ".parent" ).mouseenter(function() {
var divName = $(this).data('modal');
$(divName).fadeIn('fast').animate({
'top': '30px'
}, {duration: 'slow', queue: false}, function() { /*Animation complete*/ });
});
.parent {
position:relative;
width:1000px;
height:200px;
}
.parent:hover .sibling{border-color: #000;}
.sibling {
width:100px;
height:30px;
padding:8px;
border:1px solid red;
}
.child {
position: absolute;
width:200px;
height:50px;
top:60px;
background: blue;
display: none;
}
<div class="parent" data-modal="child">
<div class="sibling"></div>
<div class="child"></div>
</div>
You dont need javascript, pure CSS solution exist. Refer CSS selectors and the "+" selector is what you need to control sibling classes.
So in your case,
.sibling:hover + .child{
display:block;
}
controls the child class when the sibling class is hovered on.
.parent {
position: relative;
width: 1000px;
height: 200px;
background: pink;
}
.sibling {
width: 100px;
height: 30px;
padding: 8px;
border: 1px solid red;
background: blue;
}
.child {
position: absolute;
width: 200px;
height: 50px;
top: 60px;
background: green;
display: none;
}
.sibling:hover {
border: 3px solid green;
}
.sibling:hover + .child {
display: block;
}
<div class="parent" data-modal="child">
<div class="sibling"></div>
<div class="child"></div>
</div>
Hope this helps
Related
I have a container div.
Inside it I have all the child divs each with float left property.
How do space the child div evenly across the row ?
The code pen is as follows:
https://codepen.io/pranavbhagwat81/pen/NWNgaVW
<div class='box'>
<div class='box1'></div>
<div class='box2'></div>
<div class='box3'></div>
</div>
CSS
.box{
}
.box1{
height:50px;
width:50px;
background-color:violet;
float:left;
}
.box2{
height:50px;
width:50px;
background-color:indigo;
float:left;
}
.box3{
height:50px;
width:50px;
background-color:green;float:left;
}
Use flex instead, with space-between (or space-evenly):
.box {
display: flex;
justify-content: space-between;
}
.box > * {
height: 50px;
width: 50px;
}
.box1 {
background-color: violet;
}
.box2 {
background-color: indigo;
}
.box3 {
background-color: green;
}
.box4 {
background-color: orange;
}
.box5 {
background-color: yellow;
}
.box6 {
background-color: red;
}
.box7 {
background-color: black;
}
.box8 {
background-color: pink;
}
<div class='box'>
<div class='box1'></div>
<div class='box2'></div>
<div class='box3'></div>
<div class='box4'></div>
<div class='box5'></div>
<div class='box6'></div>
<div class='box7'></div>
<div class='box8'></div>
</div>
If you couldn't use flex, you can calc to determine how much the margin should be:
.box > * {
height: 50px;
width: 50px;
float: left;
}
.box > *:not(:first-child) {
margin-left: calc((100vw - 50px * 8) / 8)
}
.box1 {
background-color: violet;
}
.box2 {
background-color: indigo;
}
.box3 {
background-color: green;
}
.box4 {
background-color: orange;
}
.box5 {
background-color: yellow;
}
.box6 {
background-color: red;
}
.box7 {
background-color: black;
}
.box8 {
background-color: pink;
}
<div class='box'>
<div class='box1'></div>
<div class='box2'></div>
<div class='box3'></div>
<div class='box4'></div>
<div class='box5'></div>
<div class='box6'></div>
<div class='box7'></div>
<div class='box8'></div>
</div>
I am trying to add a dark colored border at the end of an image and write a text on it. I have attached the screen shot of how I want it to be.
Does anybody knows how to work this out?
I'm guessing something like this?
You should read up on position CSS for elements. Position absolute and relative
Fiddle for you
<div class="container">
<img src="http://placehold.it/200x150" alt="" />
<span>Here's your text</span>
</div>
* {
box-sizing: border-box;
}
.container {
position: relative;
}
.container span {
position: absolute;
bottom: 0px;
background-color: red;
width: 200px;
display: block;
padding: 10px 15px;
text-align: center;
text-transform: uppercase;
color: #fff;
}
Check this. I updated this fiddle for you! http://jsfiddle.net/EgLKV/5712/
#container
{
height:400px;
width:400px;
position:relative;
}
#image
{
position:absolute;
left:0;
top:0;
}
#text
{
z-index:100;
position:absolute;
color:white;
font-size:24px;
font-weight:bold;
text-align:center;
top:350px;
width: 400px;
background: #0686c9;
}
http://jsbin.com/tanesehivu/5/
CODE
.box{
width:200px;
height:150px;
background:grey;
float:left;
margin:10px;
display:block;
border:1px solid #999;
}
.box img{
width:200px;
height:150px;
border:1px solid #999;
}
.box span {
width:200px;
height:30px;
background:grey;
display:block;
text-align:center;
font-size:40px;
position:absolute;
top:140px;
line-height:35px;
color:#fff;
font-size:30px;
}
<div class="box">
<img src ="http://www.debrecensun.hu/media/2014/01/13-parties-for-wednesday-15-january/party.jpg"/>
<span>TITLE</span>
</div>
<div class="box">
<img src ="http://www.tnpsc.com/downloads2011/StreetRaceCars.jpg"/>
<span>TITLE</span>
</div>
I want to make all divs side by side.
I mean remove the space form top of the #div3 and #div4.
I tried float and display:inline-block
my code :
<div id="wrapper">
<div id="div1">The first</div>
<div id="div2">next to each other.</div>
<div id="div3">The two divs are</div>
<div id="div4">The two divs are</div>
</div>
#div1 {
display: inline-block;
width:220px;
height:120px;
border: 1px solid red;
}
#div2 {
display: inline-block;
width:260px;
height:260px;
border: 1px solid green;
}
#div3 {
display: inline-block;
width:100px;
height:160px;
border: 1px solid green;
}
#div4 {
display: inline-block;
width:100px;
height:160px;
border: 1px solid green;
}
http://jsfiddle.net/u5y6tuwm/
One solution is to use flex in the parent container:
#wrapper {
display: flex;
/*set display to flex*/
margin-top: 20px;
}
#wrapper > div {
margin-right: 10px;
/*add some margin to the right to direct children div*/
}
#div1 {
width: 220px;
height: 120px;
border: 1px solid red;
}
#div2 {
width: 260px;
height: 260px;
border: 1px solid green;
}
#div3 {
width: 100px;
height: 160px;
border: 1px solid green;
}
#div4 {
width: 100px;
height: 160px;
border: 1px solid green;
}
<div id="wrapper">
<div id="div1">The first</div>
<div id="div2">next to each other.</div>
<div id="div3">The two divs are</div>
<div id="div4">The two divs are</div>
</div>
vertical-align: top;
to each div1, 2, 3 and 4
you can add this to affect all divs on the page
div {
vertical-align: top;
}
or this for all divs within #wrapper div
#wrapper div {
vertical-align: top;
}
or this to target each div you want ( 1-4 )
#div1, #div2, #div3, #div4 {
vertical-align: top;
}
or to each one individually, or inline style and so on.
You just need to add
#div1, #div2, #div3, #div4 {
float:left;
}
This will work perfectly. Also do not forget to clear the float after
I am trying to achieve something like this: http://i.minus.com/ibxOaBw7BW8b5g.png
This is what I have so far: http://jsfiddle.net/QAPub/2/
How can I center the wrapper/container? I really don't care if the container exists or not, my main goal is the center the three black divs but this is as far as I have gotten.
HTML:
<div class="clearfix">
<div class="content"></div>
<div class="content"></div>
<div class="content"></div>
</div>
CSS:
.clearfix:after {
content: " ";
display: block;
height: 0;
clear: both;
}
.clearfix {
background-color: orange;
display: inline-block;
}
.content {
float: left;
background-color: black;
border: 1px solid black;
width: 100px;
height: 100px;
margin: 10px;
}
There are a couple of different ways you can accomplish this.
Here's the one I would use, put the container in the body and give it margin and position it wherever you want to.
http://jsfiddle.net/QAPub/3/
body{
width:500px;
height:500px;
}
.clearfix {
position:relative;
background-color: orange;
display: block;
width:370px;
height:120px;
margin:auto;
top:20px;
}
.content {
float: left;
background-color: black;
border: 1px solid black;
width: 100px;
height: 100px;
margin: 10px;
}
use the following css for ".clearfix "
.clearfix {
background-color: orange;
display:table;
margin:0 auto;
}
here is the jsFiddle file.
Im trying to make a couple of hexagons in css /html to resemble something like this:
http://www.asta-uk.com/sites/all/themes/asta/logo.png
now i have made one hexagon, and tried to copy it two other times but the top part doesn't seem to show on the second two.
any ideas why?
PS use IE, reason being it will only ever be used in an IE environment.
<html>
<HEAD>
<STYLE>
.top
{
height:0;
width:50;
display: block;
border:15px solid red;
border-top-color:transparent;
border-right-color:transparent;
border-bottom-color:red;
border-left-color:transparent;
}
.middle
{
height: 20px;
background: red;
width: 50px;
display: block;
}
.bottom
{
height:0;
width:50;
display: block;
border:15px solid red;
border-top-color:red;
border-right-color:transparent;
border-bottom-color:transparent;
border-left-color:transparent;
}
<!-- Second Hex-->
.top2
{
height:0;
width:50;
display: block;
border: 15px solid black;
border-top-color:transparent;
border-right-color:transparent;
border-bottom-color:black;
border-left-color:transparent;
}
.middle2
{
height: 20px;
background: black;
width: 50px;
display: block;
}
.bottom2
{
height:0;
width:50;
display: block;
border:15px solid black;
border-top-color:black;
border-right-color:transparent;
border-bottom-color:transparent;
border-left-color:transparent;
}
<!--hex 3-->
.top3
{
height:0;
width:50;
display: block;
border:15px solid green;
border-top-color:transparent;
border-right-color:transparent;
border-bottom-color:green;
border-left-color:transparent;
}
.middle3
{
height: 20px;
background: green;
width: 50px;
display: block;
}
.bottom3
{
height:0;
width:50;
display: block;
border:15px solid green;
border-top-color:green;
border-right-color:transparent;
border-bottom-color:transparent;
border-left-color:transparent;
}
</STYLE>
</HEAD>
<BODY>
<div class="hexagon"style="position: absolute; top: 0px; left: 2px;">
<span class="top"></span>
<span class="middle"></span>
<span class="bottom"></span>
</div>
<!-- GREEN-->
<div class="hexagon3" style="position: absolute; top: 48px; left: 55px;">
<span class="top3"></span>
<span class="middle3"></span>
<span class="bottom3"></span>
</div>
<!-- black-->
<div class="hexagon2" style="position: absolute; top: 120px; left: 40px;">
<span class="top2"></span>
<span class="middle2"></span>
<span class="bottom2"></span>
</div>
</BODY
</html>
Remove your comment from the css
like <!-- Second Hex--> and <!--hex 3-->
they are buggy.
These comments are meant to be in HTML only not for css
for css use this syntax --> /* A comment */
You have typo in width:50; Add px so it should be width:50px; for .top, .top2, .top3