I want to add a image hover effect on only the div images not the whole html code. How do I do this?
Take a look at how to "nest" CSS selectors.
Here's an example. Is this what you need?
<div>
Image in a div
<img src="http://baconmockup.com/300/200" />
</div>
div img:hover {
border: 1px solid red;
}
You can see it live here.
Related
This DOM object has no specific class selector applied to it, so I can't select it via CSS.
I could use some first-child hack or change the /apps/page/.Class/* files but I don't feel like either is a clean solution.
I want to have an image with some text in front of it.
Shall I modify the HTML of my page? I could also change the CSS of a markdown or text (app), but it doesn't feel like a tidy solution.
I also thought of having the image as a background pic, then life would be easy :)
What is the best solution?
Here is where I am:
Thanks!
You should create a html-1 content and apply some css to it.
Here are the files you should create with their [file types]:
content [html-1]
content/style.css [css-1]
content/style.css/background.png [image-1]
The content file should store your HTML:
<div class="-container">
<div class="-text">Hello world</div>
</div>
The style.css file could then apply the background image and make your text prettier:
.-container {
height: 400px;
background: url(background.png) no-repeat center center transparent;
}
.-text {
color: red;
font-size: 3em;
text-align: center
line-height: 400px;
}
(The image url will be expanded by the css-1 app.)
How can I do similar responsive images? Like on this page.
http://pixelgrade.com/demos/border/
I was trying do this with css, but with no effects.
Thanks.
Use background-size:cover property
html, body{
height:100%;
}
.responsive_bg{
background:url("http://upload.wikimedia.org/wikipedia/commons/5/51/ShiFengWaterFall_002.jpg") no-repeat;
background-size:cover;
width:100%;
height:100%
}
DEMO
This image is set as a background-image. Do you have any code to share with us so we might help?
Basically, instead of writing the usual image:
<img src="this/cool/image.png" />
you would use a regular div that you size according to the responsive behavior you want to see:
<div style="background-image: url(this/cool/image.png)"></div>
and the CSS that comes with to style the image (background) itself:
div{
background-size:cover; // fills the div
background-position; 50% 50%; //centers the background
//add here some way to get your div to be the proper size for responsiveness
}
And of course, you use media-queries to add some more responsiveness to the whole shenanigan.
I want to position several images inside a div block. The position of the images inside it should be relative to that div.
Should I put each image inside a block of its own size and position those blocks relatively to the bigger block? (So in any browser the block will look the same!)
You can do it like this. Here's a simple mock up.
the Html
<div>
<img src="/1st.jpg">
<img src="/2nd.jpg">
<img src="/3rd.jpg">
</div>
The css
div { display: block; }
img { display: inline-block; position: relative; float: left; }
I am using the jQuery Cycle (full) Plugin on a page where I am using a container DIV (.content-left) with a width of 75% and a jQuery Cycle slideshow inside of that container. The images inside of that container should be adjusted automatically.
I use:
JS:
$('.slides').cycle({
fx: 'fade',
containerResize: 1 // default for jquery.cycle.all
});
HTML:
<div id="content">
<div class="content-left">
<div class="slides">
<img src="...">
<img src="...">
<!-- etc. -->
</div>
</div>
<div class="content-right">
some text
</div>
<div class="clear"></div>
</div>
CSS:
#content {
overflow:hidden;
}
#content .content-left {
width:75%;
float:left;
}
#content .content-left img { /* or: .slides img */
width:100% !important;
position:relative;
left:0px;
top:0px;
z-index:-2;
}
#content .content-right {
width:25%;
float:right;
}
On Page init my wrapping DIV's (.content-left) height and width get's adjusted just fine thanks to the containerResize function. However when I resize my browser window, the width and height of the slides stay the same, which is not what I wanted.
containerResize: 0 doesn't bring the desired effect either (it then ignores the height of the images and adjusts the height of the wrapper to the height of .content-right (and cuts off the image)).
When I am using only an image without loading Cycle at all everything works fine.
Any solutions for that?
Thanks!
Set in JS:
containerResize: 0,
slideResize: 0,
(really!) and then use the trick of transparent image in the container div. See here
for detail.
How about trying max-width: 100% !important; on the images, and remove the !important from the width: 100% !important, so that when cycle attempts to resize your slides back to the original width, your max-width definition will take precedence.
If you could provide a jsfiddle, that would also be of great help.
I have 3 divs in a container div. The first is floated left, the second is floated right and the last sits in the center. This creates 3 approximately even divs across a container div.
In each of these divs I am placing an image of varying heights. Then there is a separate div to sit below the container div which will be the full width (call it description div).
I want the container div to stretch to height of largest image div so that the description div sits nicely underneath the images. Currently this works when the left floated and middle divs contain the largest image but not for the right floated div. I cannot see why or what i'm missing any help would be much appreciated.
NOTE: I'm trying to do this without using any absolute values, just percentages. So I don't want to declare an absolute height to the container div! Also clear's will not work as this is simplified and there are actually a lot of other div containers around all of this etc, unless you can clear just the floats in the above nested div.
Here's the code:
<html>
<head>
<style>
#b_pics {
border: 2px solid grey;
width: 100%;
}
#b_pic1 {
border: 0px solid grey;
float:left;
width:33%;
}
#b_pic2 {
border: 0px solid grey;
margin: 0px auto;
width: 33%
}
#b_pic3 {
border: 0px solid grey;
float:right;
width:33%;
}
#b_website {
border: 1px solid grey;
width:100%;
}
</style>
</head>
<body>
<div id='b_pics'>
<div id='b_pic1'>
Image 1 here
</div>
<div id='b_pic3'>
Image 3 here
</div>
<div id='b_pic2'>
Image 2 here
</div>
</div>
<div id='b_website'>
Line of text goes here
</div>
</body>
Thanks in advance for any help, trying to keep any hair thats left in my head!
A containing element won't stretch to accommodate floating divs. In your example, the the containing div has no actual content and will thus be 0 pixels high. Try changing the border or background colour to illustrate this.
You can force an element to be below any floating divs by giving it the style:
clear: both;
You can also clear just left or right floating divs.
You can add an empty div after your three picture divs that has that style, to make the b_pics container stretch to accommodate the floating elements, or you could just make the b_website div clear both.
I totally agree with SpoonMeiser answer. I had the same problem (only with IE do) and adding a clear: both (div in my case) is the only solution that seems to work.
SpoonMeiser's explanation is correct. Here is some code that should work for you. Essentially, I've added an empty div with "clear:both" at the end of your container div. This forces the container to take up the space of the floating divs it contains.
This is better than making the #b_website div "clear:both" (SpoonMeiser's alternative suggestion) because that would make the #b_website div display in the correct place but would not force the #b_pics border to surround the floating divs.
<div id='b_pics'>
<div id='b_pic1'>
Image 1 here</div>
<div id='b_pic3'>
Image 3 here
</div>
<div id='b_pic2'>
Image 2 here
</div>
<div style="clear:both;"></div>
</div>
<div id='b_website'>
Line of text goes here
</div>
I hope that helps?
Give this a shot. Nothing's hard-coded, and it should do what you want.