I have the following fiddle
https://jsfiddle.net/7q8nejo3/1/
I'm going to explain what I have know, and what I intent to achieve.
NOW
I have a fixed position modal in the middle of the page in a min-width and min-height ... that is for mobiles devices... all works ok... if you resize the page it's all fine.
What I need
Due to the min-width and min-height, the modal keeps its size, so I need that when the screen is bigger, the tourImage also increase its size. I try to use
width: 80%; min-width:260px;
This in order to resize the picture but didn't work.
Any advice?
Yop,
I think you need to add a width on your fixed modal, and on your image, like this :
.tourImage{
position: relative;
width: 100%;
min-width: 260px;
min-height: 340px;
margin: 0 auto;
display: none;
background: #55acee;
}
.popover{
background:#fff;
width: 80%;
transform: translate(-50%, -50%);
position: fixed;;
top: 50% !important;
left: 50% !important;
padding: 0 20px;
}
https://jsfiddle.net/7q8nejo3/4/
You can adjust the widths as you need.
You could try this way. What you will get is that the width of the image won't overflow the container div.
#media screen and (max-width:800px){
.tourImage{
position: relative;
width: 80%;
min-width: 260px;
min-height: 340px;
margin: 0 auto;
background: #55acee;
}
.popover{
background:#fff;
width: 80%;
transform: translate(-50%, -50%);
position: fixed;;
top: 50% !important;
left: 50% !important;
padding: 0 20px;
}
}
#media screen and (max-width:400px){
.popover{
width: auto;
}
}
Related
I want a circle with dynamic content. I am using a background image (SVG) and scale it so it is alway behind the content. It almost works. The background gets scaled but the overflow is not visible. So the left and right overflow, or the top and bottom depending on the screen width, are not visible.
.icwrap {
position: absolute;
top: 50%;
left: 50%;
overflow: visible;
display: flex;
transform: translate(-50%, -50%);}
.iccont {
text-align: center;
position: relative;
display: table-cell;
overflow: visible;
width: 45vw;
padding: 7.5vw;
height: auto;
color: #FFF;}
.iccont h1 {
font-size: 1.5em;
font-weight: 700;
margin-bottom: 0px;
line-height: 1.5em;}
.iccont p {
line-height: 1.5em;}
.icwrap:before {
content: '';
width: 100%;
height: 100%;
min-height: 100%;
display: block;
position: absolute;
left: 50%;
top: 50%;
overflow: visible;
transform: translate(-50%, -50%);
background-position: center;
background-image: url(https://upload.wikimedia.org/wikipedia/commons/0/01/SVG_Circle.svg);
background-repeat: no-repeat;
background-size: cover;}
See my code like described above:
https://jsfiddle.net/g471tLzf/
I like the behavior. Is there a solution to display the overflow?
The rectangle that can be inscribed in a circle has a maximum area that is a square having radius/sqrt(2) width.
Check the video if interested in underlying maths.
https://www.youtube.com/watch?v=wNMK92GVTO8.
So you can't solve this problem in general unless your content fits in every case inside that box.
So I have an image on my website and I want to perfectly center it. I have tried many things but none have worked.
body{
background-color: black;
}
img {
position: absolute;
margin-top: 10%;
text-align: center;
height: 40%;
z-index: -5
}
<img src="images/astronaut.png">
The simplest way to centre an image horizontally is with:
img {
display: block;
margin-right: auto;
margin-left: auto;
}
Like this?
body{
background-color: black;
}
img {
position: absolute;
margin-top: 10%;
text-align: center;
height: 40%;
z-index: -5;
left: 50%;
top:50%;
transform: translate(-50%, -50%);
}
<img src="images/astronaut.png">
The centering codes are the left, top, and especially the transform
Have a look at the following links for further help, hope it helps.
https://www.w3.org/Style/Examples/007/center
https://css-tricks.com/snippets/css/absolute-center-vertical-horizontal-an-image/
html {
width: 100%;
height: 100%;
background:url(http://tse4.mm.bing.net/th?id=OIP.IX1fAIIUJ82DtdfgR2tSnADhEs&w=207&h=276&c=8&qlt=90&o=4&dpr=2&pid=1.7) center center no-repeat;
}
Setting the left and right margin to auto will center the image horizontally within it's parent if your position isn't set or is set to relative.
So you could use:
img {
margin-top: 10%;
margin-left: auto;
margin-right: auto;
text-align: center;
height: 40%;
z-index: -5
}
If your position needs to be set to absolute, you can use CSS3's viewport sizing to center your image. This would place the image in the exact center of the page; so if you want to center the image within a sidebar, for example, don't use this method. You'll need to set a width for your image and then align it using the "left" property. That would look like this:
img {
position: absolute;
margin-top: 10%;
text-align: center;
height: 40%;
z-index: -5
width: 500px;
left: calc( 50vw - 250px );
}
The viewport is always 100vw wide, so setting the left property to 50vw - 1/2 of the image's width will center it on the page.
You can also use jQuery to similarly calculate the proper alignment and position the element.
You can put the image in a div and make it 100% of the screen in width and height.
Then add text-align:center; to center it horizontally.
Then set the line height to 100% and then add vertical-align: middle; to the image to center it vertically.
body{
background-color: black;
}
.CenterImage img {
height: 40%;
z-index: -5;
vertical-align: middle;
}
.CenterImage{
width:100vw;
height:100vh;
line-height: 100vh;
text-align:center;
}
<div class="CenterImage"><img src="images/astronaut.png"></div>
body{
background-color: black;
}
img {
position: absolute;
text-align: center;
height: 40%;
top: 50%;
left: 50%;
z-index: -5
}
<img src="images/astronaut.png">
I facing some issues for the table alignment over an image which I can't figure out which part is no correct. My table alignment is totally out of expectation when view by using different resolution device(laptop,TV) below is my code.
#image_overlay_panel {
width:100% !important;
float: left;
}
#image_overlay_panel .image{
background: transparent 50% 50% no-repeat url('/iameg/Acer_schematics.png');
position: relative;
top: 0px;
left: 0px;
width: 100%;
height: 808px;
background-size: 100%;
}
#effTablehtml{
position:absolute;
top: 28%;
left: 80%;
color: black;
}
I had try to removed height: 808px; and my whole image become very small as attachment below. Mind to share what mistake did I make. Thank you very much.
If you want your image to responsive to all screen, try to fix this rules in your code
#image_overlay_panel .image{
background: transparent 50% 50% no-repeat url('/iameg/Acer_schematics.png');
position: relative;
top: 0px;
left: 0px;
//width: 100%; <-- comment this line
//height: 808px; <-- comment this line
display: block;
max-width: 100%;
height: auto;
background-size: 100%;
}
you can use media screen css , as per your requirement
#media screen and (min-width: 480px) {
body {
}
}
I am trying to centre an img within a containing div, where the img fills (minimum) 100% of the width and height of that containing div, meaning thta the image automatically scales to maintain image ratio. It is easy for me to align that img to the top, bottom, left or right, but I am hoping to centre the img both vertically and horizontally. I have been unable to locate the solution thus far, so any help greatly appreciated.
HTML
<section id="hero-image">
<img src="https://s-media-cache-ak0.pinimg.com/originals/ae/1d/6e/ae1d6ef744320d237a95fc1e7d6ee98b.jpg">
</section>
CSS
#hero-image {
position: relative;
width: 100%;
height: 400px;
overflow: hidden;
background: red;
}
#hero-image img {
position: absolute;
min-height: 100%;
height: auto;
min-width: 100%;
width: auto;
margin: auto;
right: 0;
left: 0;
top: 0;
z-index: 0;
}
Fiddle
Use transform:translateX(-50) to manage this (but CSS3), large screen or small screen the image will always stay center and keep his ratio aspect.
Here the fiddle
Otherwise if you want something more cross browser you will probably need a bit of javascript, but I may be wrong.
Could you not set the hero image as a background? This will allow for more flexibilty both in terms of positioning and image size.
<section class="hero-image" style="background-image:url('https://s-media-cache-ak0.pinimg.com/originals/ae/1d/6e/ae1d6ef744320d237a95fc1e7d6ee98b.jpg');">
</section>
.hero-image {
width: 100%;
height: 400px;
background-repeat: no-repeat;
background-position: 50% 50%;
background-size: cover;
}
This achieves what you've set out to do exactly. There's other benefits to this method too, for instance, responsive images.
The CSS above sets the properties for any background image within a div class of hero-image. All you need to do then, is inline the background-image itself.
NOTE: If this doesn't have to be CMS driven, you can simply apply the image to the class rather than have it inline.
If you're happy with CSS3 (not supported in some older browsers) you could do this:
#hero-image img {
position: absolute;
min-height: 100%;
height: auto;
min-width: 100%;
width: auto;
margin: auto;
left: 50%;
top: 50%;
z-index: 0;
-webkit-transform:translate(-50%, -50%);
-moz-transform:translate(-50%, -50%);
-ms-transform:translate(-50%, -50%);
-o-transform:translate(-50%, -50%);
transform:translate(-50%, -50%);
}
#hero-image {
position: relative;
width: 600px;
height: 400px;
overflow: hidden;
background: red;
}
#hero-image img {
position: absolute;
min-height: 100%;
height: auto;
min-width: 100%;
width: auto;
margin: auto;
left: 50%;
top: 50%;
z-index: 0;
-webkit-transform:translate(-50%, -50%);
-moz-transform:translate(-50%, -50%);
-ms-transform:translate(-50%, -50%);
-o-transform:translate(-50%, -50%);
transform:translate(-50%, -50%);
}
<section id="hero-image">
<img src="https://s-media-cache-ak0.pinimg.com/originals/ae/1d/6e/ae1d6ef744320d237a95fc1e7d6ee98b.jpg">
</section>
You can try this:
CSS
#hero-image {
position: relative;
width: 100%;
height: 400px;
overflow: hidden;
background: red;
}
#hero-image img {
position: absolute;
display:block;
height: auto;
margin: 0 auto;
top: 0;
z-index: 0;
min-height:100%;
width:100%;
left: -50%;
-webkit-transform: translateX(50%);
transform: translateX(50%);
}
HTML
<section id="hero-image">
<img src="https://s-media-cache-ak0.pinimg.com/originals/ae/1d/6e/ae1d6ef744320d237a95fc1e7d6ee98b.jpg">
</section>
DEMO HERE
You could also just set it as a background with background-size: cover. Like this: https://jsfiddle.net/wzjzjsdp/2/
.img1, .img2 {
height: 400px;
width: 300px;
background-image:url(http://placehold.it/350x150);
background-repeat: no-repeat;
background-position: center center;
background-size:cover;
display:inline-block;
}
.img2 {
width:500px;
height:400px;
}
<div class="img1"></div>
<div class="img2" style="background-image:url(http://placehold.it/350x250"></div>
EDIT: You can use inline style.
I am trying to create a div that is covers the browser window diagonally. See example here:
This is my CSS:
.shape {
height: 100%;
width: 150%;
transform: rotate(25deg);
}
This is my actual result:
I've tried a bunch of different things using transformOrigin and setting top and left of the div, but nothing seems to work to have this div centered diagonally across the browser.
You need to add these: transform-origin: center;
Also when width is more than 100% you need to move content its centered before rotate. Like Position: absolute; left: -25%;
body {
padding: 0px;
margin: 0px;
}
.frame {
width: 100vw;
height: 100vh;
background: #EFEFEF;
}
.rotated {
position: absolute;
left: -25%;
width: 150%;
height: 100%;
border: 2px solid blue;
transform: rotate(25deg);
transform-origin: center;
}
<div class='frame'>
<div class='rotated'></div>
</div>