Newbie question here.
in my CSS i have a div with overflow hidden in which i am displaying images. Some images are tall (varying sizes) which poses a problem. wide images are ok when scaled down.
with the tall images my div is showing the image "head downwards" which is normal. however with my type of images the top is not so important (yacht mast and sails). is there a way i can display images in the div with the top cut off instead of the bottom?
Any ideas? Thanks Guys
Jay
You can try something like this:
.image{
height: 150px;
overflow: hidden;
position: relative;
}
img{
position: absolute;
bottom: 20px;
}
see this bin:
http://jsbin.com/muyoce/1/edit
in your css try
div.image_class{
overflow-y:hidden;
}
div.image_class img{
position: absolute;
top: 0px;
}
Try this HTML:
<div class="hide_top">
<img src="http://www.liveyachting.com/wp-content/uploads/2009/02/brenta-yacht-b60-4.jpg" alt="" />
</div>
and then apply this CSS:
.hide_top{width:50%; height:auto; max-height:400px; overflow:hidden; display:block;}
.hide_top img{width:100%; height:auto; transform: translateY(-50%); -webkit-transform:translateY(-50%); top:50%}
See fiddle here and play around with values
You could do a margin-top: -Xpx on the images and set up classes for each image size. For example
<div class="imgHold">
<img class="img400x800" src="..." />
<img class="img800x400" src="..." />
<img class="img400x400" src="..." />
</div>
.imgHold {
overflow: hidden;
}
.img400x800 {
margin-top: -200px; /* set to how much it needs to be offset */
}
.img800x400 {
margin-top: 50px; /* set to how much it needs to be offset */
}
.img400x400 {
margin-top: 0px; /* maybe this doesn't need any offset */
}
Related
I'm super new to coding so apologies if this frustrates anyone!
I'm working on a Wordpress site and I'm trying to lay a video (actually a shortcode) over a jpeg, like this;
http://imagizer.imageshack.us/v2/617x176q90/540/OJCIR1.jpg
Then place a video thumbnail (that opens into a lightbox when clicked) on the grey area. Here's my HTML:
<div style="width: 640px; height: 480px;">
<img src=".../uploads/2015/01/watch.jpg" style="z-index:-1" />
<div class="videodiv">[video_lightbox_youtube video_id="G7z74BvLWUg" width="640" height="480" auto_thumb="1"]
</div>
</div>
And here's my CSS:
div.videodiv {
float: right;
padding-left: 20px;
padding-right: 20px;
z-index: 1;
}
As I'm sure you can tell I'm brutally savaging this code from tips found online.
Any help would be massively appreciated, and how do I insert code into these topics?!
Sorry!
Actually, it's better to set the image as background and then align the video to the place where you want it, something like this:
HTML
<div class="wrapper">
<div class="videodiv">[video_lightbox_youtube video_id="G7z74BvLWUg" width="640" height="480" auto_thumb="1"]
</div>
</div>
CSS
div.wrapper {
width: 640px; //Change it to image's width
height: 480px; //change it to image's height
background: url(.../uploads/2015/01/watch.jpg) #fff;
}
div.videodiv {
right: 20px; //distance from right border to gray rectangle border
top: 10px; //distance from top border to gray rectangle top border
position: absolute; //let total control of the position of the video
}
Use position: absolute; rule in the video and position relative in the image, and then play with the position right and top in the video
CSS EXAMPLE
div.videodiv {
right: 0px;
top:0px;
z-index: 999;
position: absolute
}
img{
position: relative;
z-index: 998;
}
I am creating a site that has multiple pages that each have different images on them - of varying sizes. I have used the below css to center the whole page:
.container {
width: 960px;
margin: auto;
}
I am not sure how to then center these images on each page. I am currently using left margin and doing it by eye but this doesnt seem right especially since each image needs a different margin. Am is missing something? Is there a better way to do this?
e.g HTML
<div id="image_description_multipleimages">
<section id="image_container_multipleimages">
<img src="main_content_images/1.HOSS.png" id="hossimage1">
<img src="main_content_images/2.HOSS.png" id="hossimage2">
<img src="main_content_images/3.HOSS.jpeg" id="hossimage3">
</section>
<section id="description">
<h2> Hoss Intropia</h2>
</section>
</div>
CSS
#hossimage1 {
width:600px;
height:399px;
margin-left:50px;}
#hossimage2, {
width:600px;
height:908px;
margin-left:136px;}
#hossimage3 {
width:600px;
height:1025px;
margin-left:50px;}
#image_description_multipleimages {
clear:both;
width: 600px;
height: 2500px;
margin-left:130px;
margin-top:60px;
}
#image_container_multipleimages img{
margin-top:15px;
float: left;
clear:both;}
You can use text-align: center; on their container div. This will align them to the center like it would text.
Fiddle.
If you use this pattern
<div class="parent">
<img class="child">
...
With the following CSS
.parent {
display: flex; /* Here is the trick */
height: someContainerHeight;
width: someContainerWidth;
}
.child {
width: someElementHeight;
height: someElementWidth;
margin: auto; /* Here is the trick */
}
You will get the image perfectly centered automatically.
you just need to set img to display:block;, and make margin-left and margin-right both auto:
img { display:block; margin:0 auto; }
See example using your code:
http://jsfiddle.net/3Lh3U/
Use
#hossimage1 {
width:600px;
height:399px;
margin-left:50px;
position:relative;
top:t px;
left:y px;
align:center;
}
in each hossimage1, hossimage2, hossimage3 id.
Here's my situation: I have a changing image of various sizes (always different) being brought into an area of our splash. I posted a question about this a few days ago and employed the solutions that someone suggested. However, there were other issues that I also had to deal with I am back with an updated page that fixes other problems but I now need to see how to vertically center an image within this new code
First, here's the page: http://americanart.si.edu/index_newsplash3m.cfm
It's the middle image for our blog under the slider. Here's the code and css:
Code:
<div class="middle">
<div class="middleimage">
<img src="http://americanart.si.edu/eyelevel/images/luce_eyes.jpg" id="middleimg" alt="Blog: Eye Level Image" /><br />
</div>
<div id="middletext">
<p>
<i>The Dying Tecumseh</i> by Ferdinand Pettrich has returned to the second floor galleries at American Art after his extended stay with the National Portrait Gallery for the exhibition, <i>1812: A Nation Emerges</i>. Visit his new spot among the ...
</i>
<span class="red">Read more...</span> </p>
</div>
</div>
And here is the CSS:
.middle {
float: left;
width: 30.5%;
margin-right: 2.1%;
margin-bottom: 2% ;
background-color: #fff;
min-height: 100%;
background: url(/#res/img/americanart_blog_test.jpg) no-repeat #fff;
padding-top: 31px;
text-align: center;
position: relative;
}
div.middleimage { height: 207px;
}
div#middletext {margin-right: 2.1%;
margin-bottom: 2% ;
background-color: #fff;
min-height: 100%;
}
div.middle img#middleimg { max-height: 207px;
max-width: 291px;
bottom:0;
left:0;
right:0;
margin:auto;
vertical-align: middle;
position: relative;
}
I had to create some new nested divs around the image and text in order to keep the text from going into the image area when the image was of small height.
Thanks.
For div.middleimage add this css rule:
display:table;
Then wrap a div around your actual img tag like this:
<div id="imagewrap"><img src="http://americanart.si.edu/eyelevel/images/luce_eyes.jpg" id="middleimg" alt="Blog: Eye Level Image"></div>
And add this rule to your css:
#imagewrap {
display:table-cell;
vertical-align:middle;
}
You can also do this without any tables, simply add line-height: 207px; to your middleimage class and that should center the image inside.
div.middleimage {
line-height: 207px;
}
Centering things vertically in CSS is next to impossible, as far as I know. There's an article I've been meaning to read that may help you: http://designshack.net/articles/css/how-to-center-anything-with-css/
I'm building a responsive page that has an image and <div> side by side:
The width and height of the image retain their proportions and expand/contract with the browser window.
The width of the <div> does the same, but I'd like it to match the image in terms of height.
Is there any way of achieving this? Here's a Fiddle of the problem: http://jsfiddle.net/alecrust/xwJHw/
You can use display:table property for this. Write like this:
section{
display:table;
width:100%;
}
.text-box,.image{
display:table-cell;
vertical-align:top;
}
Check this http://jsfiddle.net/xwJHw/8/
Note: display:table works till IE8 & above.
You can use jQuery.
Calculate the hight of the image using $('#imgId').height() and the set the same to Div.
Also see the code, how heights are adjusted here http://filamentgroup.com/examples/equalHeights/
EDITED:
#alecrust: This is a fine solution and also implemented in your fiddle, See Here
A pure css solution: SEE DEMO
CSS:
#wrapper {
overflow: hidden;
background: #ccc;
}
.placeholder_image {
float: left;
width: 430px;
height: 264px;
background: #fff;
padding: 0 20px 0 0;
}
.placeholder_text {
background: #ccc;
margin-left: 450px;
display: block;
}
HTML:
<div id="wrapper">
<div class="placeholder_image">
<img src="http://www.qesign.com/templates/designs/christmas-after-effects-animated-e-card-template-31966.jpg" alt="" />
</div>
<div class="placeholder_text">
A block of text
</div>
</div>
I''m looking to move an image of a saw in between two borders so it is looks likes this.
I believe I have centered the image correctly but it appears I haven't and I am loathe to use padding if that is not right way, as I want this to be semantic as possible for a responsive design. I also need it to be placed within the two borders with one border stacked in front. Presumably I need use z-index to do that but I haven't got that far.
JsFiddle
Are you looking for something like this:
See Demo: http://jsfiddle.net/rathoreahsan/Fcn96/
Hi Played with positioning and tried to make the results as per your referred image requirement. I hope this will help you.
CSS
#logo-container .saw {
left: 50%;
margin: 0 auto;
position: relative;
top: 46px;
}
#tag-container {
border: 2px solid #00AC9D;
height: 150px;
margin-bottom: 5px;
position: relative;
width: 1140px;
}
see the demo:- http://jsfiddle.net/RJVXE/16/
You need to utilize both z-index and positioning.
.line
{
height:1px;
width:100%;
background:#000;
position:absolute;
left:0px;
}
.item1
{
top:5px;
z-index:5;
}
.item3
{
top:25px;
z-index:15;
}
<div style="width:100%; position:relative">
<div class="line item1"></div>
<div style="position:absolute; top:0px;left:50px;z-index:10">
<img src="saw.png" />
</div>
<div class="line item3"></div>
</div>
(example uses both inline & blocked CSS references only for brevity. Stay away from inline CSS).
You could tryo what AlphaMale suggestes here: How to center image in a div horizontally and vertically
Before your image include a 'span' tag. Then add this properties to 'saw' class:
#logo-container .saw {
text-align: center;
margin-bottom:-50px!important;
}
The !important is to override margin: 0 auto that actually has.
http://jsfiddle.net/2EKWS/1/