I am a javascript/PHP programmer brand new to CSS and having some trouble getting images to display in a container with overflow. My understanding is that the below code should display the images in rows of three with 15 pixels of space between them. Instead, it displays one single image in the top left of where the div should be. If I remove the ID for the div the images display down a vertical line, and if I remove the div entirely they flow rightward across the page normally. When I gave the div a background color it appeared to be the proper size and in the proper location.
#items_container {
position:absolute;
overflow:auto;
height:500px;
width:500px;
}
.item_image {
margin: 0 15px 15px 0;
padding: 0 0 0 0;
}
<div id="items_container">
<img src="imageLocation" height="150" width="150" class="item_image" />
<img src="imageLocation" height="150" width="150" class="item_image" />
<img src="imageLocation" height="150" width="150" class="item_image" />
<img src="imageLocation" height="150" width="150" class="item_image" />
<img src="imageLocation" height="150" width="150" class="item_image" />
<img src="imageLocation" height="150" width="150" class="item_image" />
</div>
I also tried giving the container div a height/width in the HTML, and the image class a height/width in the CSS. Neither did anything. Thanks for any help, everybody!
Not sure I fully understand the question, but this is how I would layout your structure:
http://jsfiddle.net/mDXL2/
HTML
<div id="items_container">
<img src="imageLocation" height="150" width="150" class="item_image" />
<img src="imageLocation" height="150" width="150" class="item_image" />
<img src="imageLocation" height="150" width="150" class="item_image" />
<img src="imageLocation" height="150" width="150" class="item_image" />
<img src="imageLocation" height="150" width="150" class="item_image" />
<img src="imageLocation" height="150" width="150" class="item_image" />
</div>
CSS
#items_container {
overflow:hidden;
height:500px;
width:500px;
}
.item_image {
float:left;
margin: 0 15px 15px 0;
padding: 0 0 0 0;
}
The overflow hidden could be replaced by a clear, but I prefer to go the overflow hidden route.
After that you just need to float all of the .item_image elements.
Related
I am working on a website, and I would like to align 4 circles in the center of the content area. The example can be found at invisionbilling.com/stackoverflow. I have something right now that does the job, but I know there will be issues with different window sizes, different picture sizes, etc. How do I set the height of the div container to automatically wrap around the 4 circles/images? Is there a way to automatically center it using margin-left and margin-right? I tried "auto" for all of these and it wasn't doing the job. Thanks!
HTML
<div class="wrapper">
<div class="circles">
<img src="http://invisionbilling.com/wp-content/uploads/2018/08/Benefits-
Circles-Lower-Costs-300x300.png" alt="" width="150" height="150"
class="alignnone size-medium wp-image-358" />
</div>
<div class="circles">
<img src="http://invisionbilling.com/wp-content/uploads/2018/08/Benefits-
Circles-Greater-Cash-Flow-300x300.png" alt="" width="150" height="150"
class="alignnone size-medium wp-image-363" />
</div>
<div class="circles">
<img src="http://invisionbilling.com/wp-content/uploads/2018/08/Benefits-
Circles-Increased-Revenue-300x300.png" alt="" width="150" height="150"
class="alignnone size-medium wp-image-364" />
</div>
<div class="circles">
<img src="http://invisionbilling.com/wp-content/uploads/2018/08/Benefits-
Circles-Emphasis-on-Patient-Care-300x300.png" alt="" width="150"
height="150" class="alignnone size-medium wp-image-361" />
</div>
</div>
CSS
.circles {
display: block !important;
float: left !important;
margin: 10px !important;
}
.wrapper {
height: 175px;
width: 100%;
margin-left: 225px;
}
Try flexbox instead of floating, and try never to use !important:
<!DOCTYPE html>
<html>
<head>
<style>
.circles {
margin: 10px;
}
.wrapper {
height: 175px;
width: 100%;
margin: auto;
display: flex;
align-items: center;
justify-content: center;
}
</style>
</head>
<body>
<div class="wrapper">
<div class="circles">
<img src="http://invisionbilling.com/wp-content/uploads/2018/08/Benefits-Circles-Lower-Costs-300x300.png" alt="" width="150" height="150"
class="alignnone size-medium wp-image-358" />
</div>
<div class="circles">
<img src="http://invisionbilling.com/wp-content/uploads/2018/08/Benefits-Circles-Greater-Cash-Flow-300x300.png" alt="" width="150" height="150"
class="alignnone size-medium wp-image-363" />
</div>
<div class="circles">
<img src="http://invisionbilling.com/wp-content/uploads/2018/08/Benefits-Circles-Increased-Revenue-300x300.png" alt="" width="150" height="150"
class="alignnone size-medium wp-image-364" />
</div>
<div class="circles">
<img src="http://invisionbilling.com/wp-content/uploads/2018/08/Benefits-Circles-Emphasis-on-Patient-Care-300x300.png" alt="" width="150"
height="150" class="alignnone size-medium wp-image-361" />
</div>
</div>
</body>
</html>
I have several images that are in a line that will resize on hover so that the user knows that the image is being selected. The problem is that when you move from one image to the next, all the rest of the images move downwards. Additionally, when moving quickly from one image to the next, the screen appears to shake. How can I fix this?
img{
margin:10px;
}
img:hover{
width:100px;
height:100px;
}
<img src="https://www.thegamecrafter.com/printable-icon/SmallSquareMat.png" width="70" height="70" />
<img src="https://www.thegamecrafter.com/printable-icon/SmallSquareMat.png" width="70" height="70" />
<img src="https://www.thegamecrafter.com/printable-icon/SmallSquareMat.png" width="70" height="70" />
<img src="https://www.thegamecrafter.com/printable-icon/SmallSquareMat.png" width="70" height="70" />
<img src="https://www.thegamecrafter.com/printable-icon/SmallSquareMat.png" width="70" height="70" />
http://jsfiddle.net/sgqsn618/
To fix this, add vertical-align: top to your images. Also, to prevent the screen from looking so shaky, add a transition to your images.
img{
margin:10px;
vertical-align: top;
transition: all 200ms ease;
}
img:hover{
width:100px;
height:100px;
}
<img src="https://www.thegamecrafter.com/printable-icon/SmallSquareMat.png" width="70" height="70" />
<img src="https://www.thegamecrafter.com/printable-icon/SmallSquareMat.png" width="70" height="70" />
<img src="https://www.thegamecrafter.com/printable-icon/SmallSquareMat.png" width="70" height="70" />
<img src="https://www.thegamecrafter.com/printable-icon/SmallSquareMat.png" width="70" height="70" />
<img src="https://www.thegamecrafter.com/printable-icon/SmallSquareMat.png" width="70" height="70" />
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm trying to make a stack of images using HTML and CSS, that if I hover or click on any of them, it will be enlarged in the same page. This is what I've been able to do:
<img src ="mark1.jpg" height="150" width="300" />
<img src ="mark2.jpg" height="150" width="300" />
<img src ="mark3.jpg" height="150" width="300" />
<img src ="mark4.jpg" height="150" width="300" />
<img src ="watson1.jpg" height="150" width="300" />
<img src ="watson2.jpg" height="150" width="300" />
<img src ="watson3.jpg" height="150" width="300" />
<img src ="watson4.jpg" height="150" width="300" />
<img src ="watson5.jpg" height="150" width="300" />
<img src ="morgan1.jpg" height="150" width="300" />
<img src ="nyong1.jpg" height="150" width="300" />
<img src ="lion1.jpg" height="150" width="300" />
One possibililty using hover only is to use transform:scale
JSfiddle Demo
CSS
img {
transition:transform 0.25s ease;
}
img:hover {
-webkit-transform:scale(1.5); /* or some other value */
transform:scale(1.5);
}
Add all the images to a container, for example:
<div class="imageContainer">
<img src ="lion1.jpg" height="150" width="300" />
</div>
Then set some CSS that does something to all <img> tags in that container when hovered:
.imageContainer > img:hover {
width: 500px;
height: 200px;
}
I have not tried this but I think it might get you on the right track to experiment yourself.
Check this fiddle
HTML:
<body>
<div id="rightImage">
<img src="https://www.gravatar.com/avatar/703327d6394d273e741186dbc0109f4f?s=128&d=identicon&r=PG&f=1" alt="image"/>
</div>
</body>
CSS:
#rightImage
{
height:275px;
float:left;
position:relative;
}
#rightImage:hover img
{
height: 300px;
}
I have a header on my screen that contains 7 images.
I want the header to cover width: 100% site. The header is 1920*50px. I want the right side of the header to cut out if the screen resolution is less than 1920*1080 and not the left side.
Here's the header in html:
<div id="apDiv1">
<img src="Bilder/navbar/images/navbar-rambech_01.jpg" width="53" height="50" />
<img src="Bilder/navbar/images/navbar-rambech_02.jpg" width="236" height="50" alt="Rambech" />
<img src="Bilder/navbar/images/navbar-rambech_03.jpg" width="202" height="50" alt="Sourcebans" />
<img src="Bilder/navbar/images/navbar-rambech_04.jpg" width="135" height="50" alt="Forum" />
<img src="Bilder/navbar/images/navbar-rambech_05.jpg" width="199" height="50" alt="Søke Admin" /><img src="Bilder/navbar/images/navbar-rambech_06.jpg" width="116" height="50" alt="VIP" />
<img src="Bilder/navbar/images/navbar-rambech_07.jpg" width="979" height="50" max-width="100%" />
</div>
Here you go.
Add the below code to your CSS. This will cut images on the right side.
#apDiv1 {
width:100%;
white-space:nowrap;
overflow:hidden;
}
I have three images that I want to display in a single row next to each other.
Here is the HTML:
<div id="client_logos">
<img style="display: inline; margin: 0 5px;" title="heartica_logo" src="https://s3.amazonaws.com/rainleader/assets/heartica_logo.png" alt="" width="150" height="50" />
<img style="display: inline; margin: 0 5px;" title="mouseflow_logo" src="https://s3.amazonaws.com/rainleader/assets/mouseflow_logo.png" alt="" width="150" height="50" />
<img style="display: inline; margin: 0 5px;" title="piiholo_logo" src="https://s3.amazonaws.com/rainleader/assets/piiholo_logo.png" alt="" width="150" height="50" />
</div>
Here is the CSS:
#client_logos { display: inline-block; }
For some reason, it only displays two logos next to each other. Not sure what's wrong. Any ideas?
URL: http://rainleader.com/who-we-are/
See screenshot.
You have a line break <br> in-between the second and third images in your markup. Get rid of that, and it'll show inline.
The code you have posted here and code on your site both are different. There is a break <br> after second image, so the third image into new line, remove this <br> and it will display correctly.
Place this css in your page:
<style>
#client_logos {
display: inline-block;
width:100%;
}
</style>
Replace
<p><img class="alignnone" style="display: inline; margin: 0 10px;" title="heartica_logo" src="https://s3.amazonaws.com/rainleader/assets/heartica_logo.png" alt="" width="150" height="50" /><img class="alignnone" style="display: inline; margin: 0 10px;" title="mouseflow_logo" src="https://s3.amazonaws.com/rainleader/assets/mouseflow_logo.png" alt="" width="150" height="50" /><img class="alignnone" style="display: inline; margin: 0 10px;" title="mouseflow_logo" src="https://s3.amazonaws.com/rainleader/assets/piiholo_logo.png" alt="" width="150" height="50" /></p>
To
<div id="client_logos">
<img style="display: inline; margin: 0 5px;" title="heartica_logo" src="https://s3.amazonaws.com/rainleader/assets/heartica_logo.png" alt="" width="150" height="50" />
<img style="display: inline; margin: 0 5px;" title="mouseflow_logo" src="https://s3.amazonaws.com/rainleader/assets/mouseflow_logo.png" alt="" width="150" height="50" />
<img style="display: inline; margin: 0 5px;" title="piiholo_logo" src="https://s3.amazonaws.com/rainleader/assets/piiholo_logo.png" alt="" width="150" height="50" />
</div>