I have seen many different ways to resolve the following, but it does not work quite as I hoped...
I need to make a div (main div) with severel divs inside (item-divs).
Each item-div must show a different picture, but when I hover a certain picture, this picture should be hidden and a text showen instead - in the same div.
How on earth can I make this?
For example this variant:
<div class="wrap">
<div class="child1"></div>
<div class="child2"></div>
</div>
And your css chould be:
.wrap:hover > child2{
opacity: 0;
}
But static styles should be like this:
.wrap{
width: 200px;
height: 300px; /* maybe auto if you want */
position: relative;
}
.child1{
width: 100%;
height: 100%;
background: lightgreen;
}
.child2{
width: 100%;
height: 100%;
background: #ff3030; /* surely for example */
position: absolute;
top: 0;
left: 0;
}
/* and this block .child2 will be faced. When it's opacity will be 0, you get your effect */
You can do this with the CSS pseudo element :hover
See example:
http://jsbin.com/vijawuda/1/edit?html,css,output
HTML Markup:
<div class='outer-container'>
<div class='image-holder'>
<img src='' />
<div class='text'>
Test image 1
</div>
</div>
<div class='image-holder'>
<img src='' />
<div class='text'>
Test image 2
</div>
</div>
<div class='image-holder'>
<img src='' />
<div class='text'>
Test image 3
</div>
</div>
<div class='image-holder'>
<img src='' />
<div class='text'>
Test image 4
</div>
</div>
<div class='image-holder'>
<img src='' />
<div class='text'>
Test image 5
</div>
</div>
</div>
CSS
.image-holder {
width: 150px;
height: 150px;
display: inline-block;
}
.image-holder > .text {
visibility: hidden;
width: 150px;
height: 150px;
}
.image-holder:hover img {
visibility: hidden;
}
.image-holder:hover .text {
visibility: visible;
}
HTML
<div class="main">
<div class="content">
<div class="maincontent">
<img src="http://lorempixel.com/150/150/" alt="" height="150" width="150" />
</div>
<div>Hovering Content</div>
</div>
<div class="content">
<div class="maincontent">
<img src="http://lorempixel.com/150/150/" alt="" height="150" width="150" />
</div>
<div>Hovering Content</div>
</div>
<div class="content">
<div class="maincontent">
<img src="http://lorempixel.com/150/150/" alt="" height="150" width="150" />
</div>
<div>Hovering Content</div>
</div>
<div class="content">
<div class="maincontent">
<img src="http://lorempixel.com/150/150/" alt="" height="150" width="150" />
</div>
<div>Hovering Content</div>
</div>
<div class="content">
<div class="maincontent">
<img src="http://lorempixel.com/150/150/" alt="" height="150" width="150" />
</div>
<div>Hovering Content</div>
</div>
</div>
CSS
.main {
width: 1000px;
height: 200px;
}
.content {
width: 150px;
height: 150px;
background-color:#c80000;
color:#fff;
font-family:arial;
text-align:center;
float:left;
margin-left: 10px;
font-size: 20px;
cursor:pointer;
}
.content > div.maincontent + div {
display:none;
padding-top:50px;
}
.content:hover > div.maincontent {
display:none;
}
.content:hover > div.maincontent + div {
display:block;
}
http://jsfiddle.net/q92zL/4/
Related
I have a problem with CSS.
.special-banner{
width: 100vw;
position: relative;
}
.special-banner > img{
width: 100%;
height: 100%;
}
<div class="special-banner">
<img src="http://wanho1108.dothome.co.kr/hmb/web/n_himages/sub/sub_point_use_banner_01_renew.png"/>
</div>
<div class="special-banner">
<img src="http://wanho1108.dothome.co.kr/hmb/web/n_himages/sub/sub_point_use_banner_02_renew.png"/>
</div>
<div class="special-banner">
<img src="http://wanho1108.dothome.co.kr/hmb/web/n_himages/sub/sub_point_use_banner_03_renew.png"/>
</div>
<div class="special-banner">
<img src="http://wanho1108.dothome.co.kr/hmb/web/n_himages/sub/sub_point_use_banner_04_renew.png"/>
</div>
<div class="special-banner">
<img src="http://wanho1108.dothome.co.kr/hmb/web/n_himages/sub/sub_point_use_banner_05_renew.png"/>
</div>
<div class="special-banner">
<img src="http://wanho1108.dothome.co.kr/hmb/web/n_himages/sub/sub_point_use_banner_06_renew.png"/>
</div>
As you can see, there are some White line.
I want to remove them.
Also, I have 1 solution.
Using display: flex.
It's efficient but I can't use that.
Do you have another solution?
I guess it causes with display:block..
I don't know if you added display:block or not, but putting it in the img style removes the white line
.special-banner {
width: 100vw;
position: relative;
}
.special-banner>img {
width: 100%;
height: 100%;
display: block;
}
<div class="special-banner">
<img src="http://wanho1108.dothome.co.kr/hmb/web/n_himages/sub/sub_point_use_banner_01_renew.png" />
</div>
<div class="special-banner">
<img src="http://wanho1108.dothome.co.kr/hmb/web/n_himages/sub/sub_point_use_banner_02_renew.png" />
</div>
<div class="special-banner">
<img src="http://wanho1108.dothome.co.kr/hmb/web/n_himages/sub/sub_point_use_banner_03_renew.png" />
</div>
<div class="special-banner">
<img src="http://wanho1108.dothome.co.kr/hmb/web/n_himages/sub/sub_point_use_banner_04_renew.png" />
</div>
<div class="special-banner">
<img src="http://wanho1108.dothome.co.kr/hmb/web/n_himages/sub/sub_point_use_banner_05_renew.png" />
</div>
<div class="special-banner">
<img src="http://wanho1108.dothome.co.kr/hmb/web/n_himages/sub/sub_point_use_banner_06_renew.png" />
</div>
try applying float:left for .special-banner and .special-banner > img
.special-banner,.special-banner > img{
float: left;
}
I have 4 columns of products with a header, description and image below and I want the text areas to at the top and the images to each line up at the bottom so they stay aligned when the screen is resized.
At the moment the images move up and down as the text wraps - which looks very untidy as they each have a different amount of text.
I have tried using tables and position absolute and they each cause problems and don't work properly.
Here is my code:
#product-landing .landing-row {
position: relative;
height: inherit;
}
.product-landing,
.product-landing-2,
.product-landing-3 {
margin-right: 2.0533%;
}
.product-landing,
.product-landing-2,
.product-landing-3,
.product-landing-4 {
margin-left: 0px;
display: inline-block;
position: relative;
height: 100%;
vertical-align: top;
width: 22.978%;
}
.product-landing-4 {
margin-right: 0px;
}
#product-landing p {
margin-top: 0px;
margin-bottom: 5px;
clear: both;
width: 100%;
}
.product-landing .land-image {
vertical-align: bottom;
}
.product-landing img,
.product-landing-2 img,
.product-landing-3 img,
.product-landing-4 img {
margin-top: 10px;
display: block;
max-width: 350px;
margin: 0 auto;
bottom: 0px;
width: 100%;
}
<div id="product-landing">
<div class="landing-row">
<div class="product-landing">
<div id="product-text">
<div id="offer-title">Product1</div>
<p>
</p>
<p><b><i>Product description</i></b></p>
</div>
<p class="land-image">
<img src="http://image1.jpg">
</p>
</div>
<div class="product-landing-2">
<div id="product-text">
<div id="offer-title">Product2</div>
<p>
</p>
<p><b><i>Product description</i></b></p>
</div>
<p class="land-image">
<img src="http://image2.jpg">
</p>
</div>
<div class="product-landing-3">
<div id="product-text">
<div id="offer-title">Product3</div>
<p>
</p>
<p><b><i>Product description</i></b></p>
</div>
<p class="land-image">
<img src="http://image3.jpg">
</p>
</div>
<div class="product-landing-4">
<div id="product-text">
<div id="offer-title">Product4</div>
<p>
</p>
<p><b><i>Product description</i></b></p>
</div>
<p class="land-image">
<img src="http://image4.jpg">
</p>
</div>
</div>
</div>
You can use flexbox for this
#product-landing .landing-row {
display:flex;
flex-direction:row;
justify-content:space-between;
flex-wrap:wrap;
}
#product-landing p {
margin-top: 0px;
margin-bottom: 5px;
}
.product-landing {
display:flex;
flex-direction:column;
width: 22.978%;
}
.product-landing img {
margin-top: 10px;
display: block;
max-width: 350px;
width: 100%;
}
.product-text {
flex-grow:1;
}
<div id="product-landing">
<div class="landing-row">
<div class="product-landing">
<div class="product-text">
<div class="offer-title">Product1</div>
<p><b><i>Product description</i></b></p>
</div>
<p class="land-image">
<img src="http://via.placeholder.com/350x150">
</p>
</div>
<div class="product-landing">
<div class="product-text">
<div class="offer-title">Product2</div>
<p><b><i>Product description</i></b></p>
</div>
<p class="land-image">
<img src="http://via.placeholder.com/350x150">
</p>
</div>
<div class="product-landing">
<div class="product-text">
<div class="offer-title">Product2</div>
<p><b><i>Product description</i></b></p>
</div>
<p class="land-image">
<img src="http://via.placeholder.com/350x150">
</p>
</div>
<div class="product-landing">
<div class="product-text">
<div class="offer-title">Product3</div>
<p><b><i>Product description Product description Product description</i></b></p>
</div>
<p class="land-image">
<img src="http://via.placeholder.com/350x150">
</p>
</div>
<div class="product-landing">
<div class="product-text">
<div class="offer-title">Product4</div>
<p><b><i>Product description</i></b></p>
</div>
<p class="land-image">
<img src="http://via.placeholder.com/350x150">
</p>
</div>
</div>
Would've commented this if I could; Have you tried using flex-box? https://css-tricks.com/snippets/css/a-guide-to-flexbox/
This has saved me on many occasions where relative/absolute combinations fail.
To be more specific;
.wrapper{
display:flex;
flex-direction:column;
}
.text-wrapper-div{
align-self:flex-start;
}
.image-wrapper-div{
align-self:flex-end;
}
.wrapper is your parent-container, which flexes from top to bottom (column).
Inside are the two div's for text and image, which align themselves to the top (flex-start) and bottom (flex-end).
Have a look at the link if you get stuck - it's pretty well documented I think! Good luck.
Hope this may help you,
Using flex is considered to be best practice. The table and table-cell are the old ways as we have came way far and new properties are being invented day by day. As using the flex will adjust the content itself as you resize the browser and has its own qualities.
#product-landing .landing-row {
display: flex;
flex-direction: row;
}
.product-landing,
.product-landing-2,
.product-landing-3 {
margin-right: 2.0533%;
}
.product-landing,
.product-landing-2,
.product-landing-3,
.product-landing-4 {
flex: 1;
text-align: center;
}
#product-landing p {
margin-top: 0px;
margin-bottom: 5px;
clear: both;
width: 100%;
}
.product-landing .land-image {
vertical-align: bottom;
}
.product-landing img,
.product-landing-2 img,
.product-landing-3 img,
.product-landing-4 img {
margin-top: 10px;
display: block;
max-width: 350px;
margin: 0 auto;
bottom: 0px;
width: 100%;
}
<div id="product-landing">
<div class="landing-row">
<div class="product-landing">
<div id="product-text">
<div id="offer-title">Product1</div>
<p>
</p>
<p><b><i>Product description</i></b></p>
</div>
<p class="land-image">
<img src="http://image1.jpg">
</p>
</div>
<div class="product-landing-2">
<div id="product-text">
<div id="offer-title">Product2</div>
<p>
</p>
<p><b><i>Product description</i></b></p>
</div>
<p class="land-image">
<img src="http://image2.jpg">
</p>
</div>
<div class="product-landing-3">
<div id="product-text">
<div id="offer-title">Product3</div>
<p>
</p>
<p><b><i>Product description</i></b></p>
</div>
<p class="land-image">
<img src="http://image3.jpg">
</p>
</div>
<div class="product-landing-4">
<div id="product-text">
<div id="offer-title">Product4</div>
<p>
</p>
<p><b><i>Product description</i></b></p>
</div>
<p class="land-image">
<img src="http://image4.jpg">
</p>
</div>
</div>
</div>
I am trying to done is have a responsive div with 2 pictures centered, one in each div.
What I am want it is to drop down, when the screen is small and not big enought to display them side by side.
At the moment with the below when the screen is smaller it pushes the images into each other.
<style>
.container{width:100%}
.inner_container{float:left;width:50%;}
.img_container{width:250px;margin:0 auto:padding-bottom:5px;}
</style>
<div class="container">
<div class="inner_container">
<div class="img_container">
<img src="left_img.png" width="250" height="70" alt="" border="0">
</div>
</div>
<div class="inner_container">
<div class="img_container">
<img src="right_img.png" width="250" height="70" alt="" border="0">
</div>
</div>
</div>
You're using the wrong styles to do what you're trying to do. Mainly, you've set a fixed width of 250px to your img_container div which is why the images aren't getting scaled down. This the correct way to achieve what you want:
.container {
width: 100%
}
.inner_container {
width: 49%;
display: inline-block;
}
.img_container {
width: 100%;
}
.img_container a img {
width: 100%;
}
<div class="container">
<div class="inner_container">
<div class="img_container">
<a href="http://www.google.co.uk">
<img src="http://lorempixel.com/400/200/" width="250" height="70" alt="" border="0">
</a>
</div>
</div>
<div class="inner_container">
<div class="img_container">
<a href="http://www.google.com">
<img src="http://lorempixel.com/400/200/" width="250" height="70" alt="" border="0">
</a>
</div>
</div>
</div>
With the above code, the images keep on getting scaled down and stay on the same line until the window size is reduced to very small. If you would want them to appear on two separate lines after a particular width, you will need to use media-queries like this:
.container{width:100%}
.inner_container { width: 49%; display: inline-block; }
.img_container { width: 100%; }
.img_container a img { width: 100%; }
#media (max-width: 650px) {
.inner_container { width: 100%; display: block; }
}
<div class="container">
<div class="inner_container">
<div class="img_container">
<img src="http://lorempixel.com/400/200/" width="250" height="70" alt="" border="0">
</div>
</div>
<div class="inner_container">
<div class="img_container">
<img src="http://lorempixel.com/400/200/" width="250" height="70" alt="" border="0">
</div>
</div>
</div>
Set a min-width on the .inner_container
.container {
width:100%;
overflow: hidden;
}
.inner_container {
float:left;
width:50%;
min-width: 250px;
}
.img_container {
width:250px;
margin:0 auto;
padding-bottom:5px;
text-align: center;
}
http://jsfiddle.net/63pnotjc/
When I posted my reply, I didn't notice Fahad, Show code snippet link.
Thank you both for your help, this is the css code I went with in the end.
.container{width:100%;overflow:hidden;}
.inner_container{display:inline-block;width:49%;}
.img_container{width:250px;margin:0 auto;text-align:center;padding-bottom:5px;}
#media (max-width:501px){
.inner_container{display:block;width:100%;}
}
Once again thank you both for your help :)
I've included a screen shot of what I currently have and how I want it fixed here: http://i.imgur.com/urAI4UF.png
Here is the simplified HTML code for my project (I have 19 images that I'm building in a complex grid and so I'm only including the trouble images since the others are playing nice together):
<div class="wrapper">
<div class="images">
<div class="col col-1-3">
<div class="module" id="img-10">
<img src="img/pic_10.png">
</div>
</div>
<div class="col col-1-3 clear">
<div class="module" id="img-11">
<img src="img/pic_11.png">
</div>
</div>
<div class="col col-1-3">
<div class="module" id="img-12">
<img src="img/pic_12.png">
</div>
</div>
<div class="col col-1-3">
<div class="module" id="img-13">
<img src="img/pic_13.png">
</div>
</div>
</div><!--.images -->
</div><!--.wrapper -->
Img 11 has a clear so that it will tuck itself under image 10, but then I can't get img 12 and 13 to go level with image 10. If I don't do the clear on img-11, it will be side by side with img-10.
Here is my CSS:
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing:border-box:
}
.wrapper {
width: 1000px;
margin:0 auto;
}
.grid {
overflow: hidden;
}
.col{
float: left;
}
.col-1-5 {
width: 20%;
}
.col-1-3 {
width: 33.3333%;
}
.col-2-5 {
width: 40%;
}
.col-2-3 {
width: 66.6666%;
}
.col-3-5 {
width: 60%;
}
.module img {
width: 100%;
height: 100%;
padding: 3px;
}
#img-10 {
height: 194px;
width: 333.33px;
}
#img-11 {
height: 194px;
width: 333.33px;
}
#img-12,
#img-13 {
height: 388px;
width: 333.33px;
}
.clear {
clear: both;
}
UPDATE: I got help from a friend on a different site and using this code instead works:
<div class="col col-1-3">
<div class="module" id="img-10">
<img src="img/pic_10.png">
</div>
<div class="module" id="img-11">
<img src="img/pic_11.png">
</div>
</div>
UPDATE: I got help from a friend on a different site and using this code instead works:
<div class="col col-1-3">
<div class="module" id="img-10">
<img src="img/pic_10.png">
</div>
<div class="module" id="img-11">
<img src="img/pic_11.png">
</div>
</div>
Hello guys I'm trying to centre some images. They keep on floating to the left,I've tried text-aligning but it doesn't seem to work. THe jsfiddle is here. http://jsfiddle.net/E7Ydz/2/ P.S. I could probably do this when I've had some sleep, it's 5:56 in London :(
[HTML]
<div id="portfolio" style="height: 3020px;">
<div id="project" class="cms design html-css " data-col="1" data-row="0" style="right: 0px; opacity: 1; top: 0px;">
<div id="workEntry1" class="workEntry">
<div id="thumbAttachment">
<div id="inThumb">
<img src="http://www.enjoythis.co.uk/wp-content/files_mf/work_thumbnail275.jpg">
</div>
<div id="blackCross"> <img src="http://www.enjoythis.co.uk/wp-content/themes/enjoyThis/images/thumb_transparency.png"></div>
</div>
<!--<div id="attachmentShadowThumb"></div>-->
<div id="workTitle">
</div>
<div id="workTags">
</div>
</div>
</div>
<div id="project" class="design illustration html-css " data-col="2" data-row="0" style="right: 0px; opacity: 1; top: 0px;">
<div id="workEntry2" class="workEntry">
<div id="thumbAttachment">
<div id="inThumb">
<img src="http://www.enjoythis.co.uk/wp-content/files_mf/work_thumbnail2.jpg">
</div>
<div id="blackCross"> <img src="http://www.enjoythis.co.uk/wp-content/themes/enjoyThis/images/thumb_transparency.png"></div>
</div>
<!--<div id="attachmentShadowThumb"></div>-->
<div id="workTitle">
</div>
<div id="workTags">
</div>
</div>
</div>
<div id="project" class="app database design " data-col="0" data-row="1" style="right: 0px; opacity: 1; top: 0px;">
<div id="workEntry3" class="workEntry">
<div id="thumbAttachment">
<div id="inThumb">
<img src="http://www.enjoythis.co.uk/wp-content/files_mf/pgtips_thumb37.jpg">
</div>
<div id="blackCross"> <img src="http://www.enjoythis.co.uk/wp-content/themes/enjoyThis/images/thumb_transparency.png"></div>
</div>
<!--<div id="attachmentShadowThumb"></div>-->
<div id="workTitle">
</div>
<div id="workTags">
</div>
</div>
</div>
[css]
#project{
float:left;
position:relative;
padding: 0px 0px 0px 2px;
height:200px;
width:309px;
display: inline;
}
.workEntry{
width:310px;
overflow:hidden;
}
#thumbAttachment{
float:left;
width: 310px;
height:200px;
overflow: hidden;
}
#inThumb{
float:left;
}
#blackCross{
float:left;
width: 310px;
height:200px;
margin-top:-200px;
khtml-opacity:0;
-moz-opacity:0;
-ms-filter:"alpha(opacity=0)";
filter:alpha(opacity=0);
opacity:0;
}
#blackCross:visited{
khtml-opacity:0;
-moz-opacity:0;
-ms-filter:"alpha(opacity=0)";
filter:alpha(opacity=0);
opacity:0;
}
#blackCross:hover{
khtml-opacity:1;
-moz-opacity:1;
-ms-filter:"alpha(opacity=100)";
filter:alpha(opacity=100);
opacity:100;
}
Hope I understand your question well. You should use margin-left: auto; and margin-right: auto; to make a div (or in a better word, a block position element) center.
For instance you should change your css code to something like:
#inThumb{
margin-left: auto;
margin-right: auto;
}
See this jsFiddle: http://jsfiddle.net/E7Ydz/4/