I have made an analogue clock like so that shares 1 parent div space with 2 other divs:
.left {
vertical-align: top;
width: 27%;
overflow: hidden;
display: inline-block;
}
#picLeft {
height: 100%;
width: 100%;
}
.container {
vertical-align: top;
position: relative;
display: inline-block;
width: 16.7%;
}
.clock {
vertical-align: top;
width: 100%;
height: 100%;
position: relative;
display: inline-block;
}
.hands {
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.hands-cl {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
vertical-align: top;
}
.right {
vertical-align: top;
width: 52.2%;
height: 100%;
overflow: hidden;
display: inline-block;
}
.picRight {
width: 100%;
height: 100%;
}
<div class="header-logo">
<div class="left">
<img id="picLeft" src="TIDleft.png">
</div>
<div class="container">
<div class="clock">
<img class="hands" src="TidClockFace.png">
<img id="hourHand" class="hands-cl" src="hourHand.png">
<img id="minuteHand" class="hands-cl" src="hourHand.png">
</div>
</div>
<div class="right">
<img class="picRight" src="TIDright.png">
</div>
</div>
This is what happens:
As You can see it looks ridiculous.
I don't know if the problem is in the rotation or the image size since the divs shrink the images to fit the part of the website.
This is the third day I have been persistently searching for the answer. No stackoverflow threads are similar, and I have run out of ideas for search terms.
I hope this question is asked properly, and enough info has been given.
If not though, don't hesitate to ask for something or correct me.
Related
So I've looked at some similar problem, but I still don't get it. Please take a look on my HTML and CSS sheet:
CSS:
.bottom1Container {
vertical-align: middle;
position: relative;
text-align: right;
}
.bottom1 {
position: absolute;
right: 0;
top: 63%;
width: 100%;
object-fit: scale-down;
}
HTML:
<div class="bottom1Container">
<div class="bottom1" style="background:url(/images/bottom1.svg) no-repeat ;"></div>
So, as you can see there's already position: relative in the parent. But why is this still not working? (btw the bottom1.svg file is an animation svg)
When you make it non 100% wide, it will work
.bottom1Container {
vertical-align: middle;
position: relative;
text-align: right;
}
.bottom1 {
position: absolute;
right: 0;
object-fit: scale-down;
}
div {
height: 200px;
}
<div class="bottom1Container" style="background-color: gray">
<div class="bottom1" style="background-color: blue; width: 50%">
<p>Your div with background image</p>
</div>
</div>
I'm trying to create a gallery of rounded photos (mostly landscape rectangular images). It works for the first image but I don't know how to apply it to all the images while maintaining the rounded format. Any help would be appreciated since I'm still new to this.
Here's my HTML:
<div class="photos">
<img src="url">
<img src="url">
etc.. more images
</div>
Then my CSS:
.photos {
display: inline-block;
position: relative;
width: 200px;
height: 200px;
overflow: hidden;
border-radius: 50%;
}
img {
width: auto;
height: 100%;
margin-left: -50px;
display: inline-block;
}
Add this to your css, it works for all img tag inside of Photos
.photos img{
border-radius: 50%;
}
<div class="photos"></div>
You should use .photos with one image inside it, like:
.photos {
display: inline-block;
position: relative;
width: 200px;
height: 200px;
overflow: hidden;
border-radius: 50%;
}
img {
width: auto;
height: 100%;
margin-left: -50px;
display: inline-block;
}
<div class="photos">
<img src="http://cdn1-www.dogtime.com/assets/uploads/gallery/cardigan-welsh-corgi/chasing-8_680-453.jpg">
</div>
<div class="photos">
<img src="http://cdn1-www.dogtime.com/assets/uploads/gallery/cardigan-welsh-corgi/chasing-8_680-453.jpg">
</div>
Hope this helps!
Try editing your css with this:
.photos img {
display: inline-block;
position: relative;
width: 200px;
height: 200px;
overflow: hidden;
border-radius: 50%;
}
img {
width: auto;
height: 100%;
margin-left: -50px;
display: inline-block;
}
You would simply put each image in its own <div> with a class round for instance.
.round {
display: inline-block;
position: relative;
width: 200px;
height: 200px;
overflow: hidden;
border-radius: 50%;
background-color:blue;
}
<div class='round'>
<img src='yourImage'>
</div>
<div class='round'>
<img src='yourImage'>
</div>
So it's possible to center and scale an image of unknown dimensions within a variable width and height container Codepen:
html,
body {
width: 100%;
height: 100%;
}
.Wrapper {
width: 50%;
height: 100%;
text-align: center;
font-size: 0;
vertical-align: middle;
}
.Wrapper:before {
content: '';
height: 100%;
vertical-align: middle;
display: inline-block;
}
.Wrapper--landscape {
float: right;
background: #DDD;
}
.Wrapper--portrait {
background: #AAA;
}
img {
max-width: 100%;
max-height: 100%;
display: inline-block;
vertical-align: middle;
}
<div class="Wrapper Wrapper--landscape">
<img src="https://dl.dropboxusercontent.com/u/316978/landscape.jpg">
</div>
<div class="Wrapper Wrapper--portrait">
<img src="https://dl.dropboxusercontent.com/u/316978/portrait.jpg">
</div>
And it's possible to create a fluid width container with a fixed aspect ratio [Codepen(http://codepen.io/Pedr/pen/rVoyoL):
html,
body {
width: 100%;
height: 100%;
}
.Wrapper {
width: 50%;
height: 100%;
}
.Wrapper--left {
float: left;
}
.Wrapper--left {
float: right;
}
.AspectRatioBox {
width: 100%;
text-align: center;
font-size: 40px;
}
.AspectRatioBox--6-4 {
width: 100%;
padding-bottom: 66.666666%;
background: #CCC;
}
.AspectRatioBox--6-4::after {
content: '6:4';
}
.AspectRatioBox--16-9 {
width: 100%;
padding-bottom: 56.25%;
background: #666;
}
.AspectRatioBox--16-9::after {
content: '16:9';
}
<div class="Wrapper Wrapper--left">
<div class="AspectRatioBox AspectRatioBox--6-4"></div>
</div>
<div class="Wrapper Wrapper--right">
<div class="AspectRatioBox AspectRatioBox--16-9"></div>
</div>
But is there any way of doing both at the same time? The problem with combining the two approaches above, is that the method for giving the containers an intrinsic ratio involves using padding to give the container it's visual height. This won't play well with the first technique which involves giving the image max-height: 100% as the height of the container will be 0.
Note: I'm looking for a CSS-only solution that works across modern browsers.
Looks like the answer is yes - by using an extra container to create a new context for the image: Codepen
html,
body {
width: 100%;
height: 100%;
}
.Wrapper {
width: 50%;
height: 100%;
}
.CenteringContainer {
text-align: center;
font-size: 0;
vertical-align: middle;
}
.CenteringContainer:before {
content: '';
height: 100%;
vertical-align: middle;
display: inline-block;
}
.Wrapper--landscape {
float: right;
background: #DDD;
}
.Wrapper--portrait {
background: #AAA;
}
.IntrinsicContainer {
position: relative;
width: 100%;
padding-bottom: 56.25%;
}
.IntrinsicContainer-context {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
background: #333;
}
img {
max-width: 100%;
max-height: 100%;
display: inline-block;
vertical-align: middle;
}
<div class="Wrapper Wrapper--landscape">
<div class="IntrinsicContainer">
<div class="IntrinsicContainer-context CenteringContainer">
<img src="https://dl.dropboxusercontent.com/u/316978/landscape.jpg">
</div>
</div>
</div>
<div class="Wrapper Wrapper--portrait">
<div class="IntrinsicContainer">
<div class="IntrinsicContainer-context CenteringContainer">
<img src="https://dl.dropboxusercontent.com/u/316978/portrait.jpg">
</div>
</div>
</div>
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I've combined some answers regarding centering an image, so it will work on a full HTML page.
.image-center {
vertical-align: middle;
margin: 1em 0;
}
.helper {
display: inline-block;
height: 100%;
vertical-align: middle;
}
.vert-center {
min-height: 10em;
vertical-align: middle;
height: 100%;
}
.horz-center {
text-align: center;
}
html, body {
height: 100%;
}
<body>
<div class="vert-center horz-center">
<span class="helper"></span>
<img src="img/image.gif" class="image-center" />
</div>
</body>
this way, the image will be vertically centered because its container is on 100% height of the page. this is usually way the image itself isn't centered vertically.
hope that helps some of you.
Or, you avoid so many 'bad' css styling conventions and go for something like below, as stated in the thousands of other SO questions on this matter.
option 1
html, body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
display: table;
}
.container {
display: table-cell;
text-align: center;
vertical-align: middle;
}
.content {
display: inline-block;
text-align: left;
}
<div class="container">
<div class="content">
<img src="http://placekitten.com/g/200/300" alt="" />
</div>
</div>
option 2
.parent {
display: table;
height: 300px;
background: yellow;
width:300px;
}
.child {
display: table-cell;
vertical-align: middle;
text-align:center;
}
<div class="parent">
<div class="child">
<div class="content">XXX</div>
</div>
</div>
option 3
#outer {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
text-align:center;
}
#inner {
width: 50%;
height: 50%;
top: 25%;
margin: 0 auto;
position: relative;
background: orange;
}
<div id=outer>
<img id=inner src="http://placekitten.com/g/200/300" alt=""/>
</div>
option 4
If you know the size of the image (and div), you could apply margins like:
.container {
height: 300px;
width: 300px;
background: #eee;
position: absolute;
margin: -150px 0 0 -150px;
left: 50%;
top: 50%;
}
.box {
height: 100px;
width: 100px;
background: #222;
position: absolute;
/*Centering Method 2*/
margin: -50px 0 0 -50px;
left: 50%;
top: 50%;
}
<div class="container">
<div class="box"></div>
</div>
option 5
centering text is also a doddle in css
.container {
height: 200px; /*Set line-height to this value*/
width: 400px;
background: #eee;
margin: 150px auto;
}
h1 {
font: 40px/200px Helvetica, sans-serif;
text-align: center;
}
<div class="container">
<h1>I'm centered!</h1>
</div>
option 6 (IMO the best)
using background image positioning
.container {
height: 300px;
width: 300px;
margin: 150px auto;
background: #eee url(http://lorempixum.com/100/100/nature/4) no-repeat center;
}
<div class="container"></div>
So, as you can see, there's literally LOADS of ways to achieve this with just a few lines of code.
This is my first question so appologies if the format is wrong.
I've tried every method I've found on stack overflow but I still cannot get this content to display vertically in the middle.
CSS:
div.img-wrapper {
display: table;
height: 232px;
overflow: hidden;
position: relative;
width: 100%;
}
div.cover {
display: table-cell;
height: 232px;
left: 0;
margin: 0;
overflow: hidden;
padding: 0;
position: absolute;
text-align: center;
top: 0;
vertical-align: middle;
width: 100%;
}
HTML Markup:
<div class="img-wrapper">
<img alt="" src="img2.jpg">
<div class="cover">
<img alt="" src="img1.png">
<span class="product-name">Product Name</span>
<span class="product-sub">Sub Line</span>
</div>
</div>
I'm using position:absolute as the .cover div rolls over the img to display product information.
Any help would be greatly appreciated :)
Thanks in advance.
Will
Here is my attempt for it. An outter-container is needed because the table won't cover the page's width and height on it's own
Try this:
#outter-container {
position: absolute;
top: 0px;
right: 0px;
bottom: 0px;
left: 0px;
}
#img-wrapper {
display: table;
width: 100%;
height: 100%;
}
#cover {
display: table-cell;
vertical-align: middle;
text-align: center;
}
DEMO