In iE and Chrome my container block is well vertically centered but not in Firefox. I don't understand because all the parent are well defined so it would be ok under every browser. Maybe there is a special toolkit under Mozilla for that kind of CSS but i didn't find it .
index.html.twig
{% block body %}
<div class="container">
<div class="vertical-center-row">
<div align="center">
<div class="col-md-6 col-md-offset-3">
<div class="col-xs-6">
<img src={{ asset('images/icones/buy_button.png') }} alt="buy_button" id="buy_button"class="img-rounded img-responsive">
</div>
<div class="col-xs-6">
<img src={{ asset('images/icones/sell_button.png') }} alt="sell_button" id="sell_button" class="img-rounded img-responsive">
</div>
</div>
</div>
</div>
</div>
{% endblock %}
Applied CSS :
html,body{
height: 100%;
}
body {
margin: 0;
background: url('../../../../images/pictures/home_background.jpg');
background-repeat:no-repeat;
background-position: center center;
background-attachment: fixed;
background-size: cover;
background-color: #464646;
padding-top: 6%;
overflow: hidden;
}
/*general*/
#toHide{
display: none;
}
/*center*/
.container{
min-height: 100%;
height: auto;
display: table;
vertical-align: middle;
}
.vertical-center-row {
display: table-cell;
vertical-align: middle;
}
/* footer*/
#general-navbar{
height: 6%;
}
#wrap{
height: 94%;
}
#footer {
background-color: #f5f5f5;
height: 6%;
}
#footer-container{
background-color: #f5f5f5;
height: 100%;
width:100%;
}
#clean-footer{
clear:both;
}
.hide-scroll {
overflow: hidden;
}
.viewport {
overflow: auto;
height: 100%;
max-height: 100%;
margin-right: -100000px;
padding-right: 100000px;
}
/* responsive design*/
#media only screen and (max-width: 600px) {
body {
/* The file size of this background image is 93% smaller
to improve page load speed on mobile internet connections */
background: url('../../../../images/pictures/home_background.jpg');
padding-top: 6%;
}
.hide-scroll {
overflow-x: auto;
overflow-y: hidden;
}
.viewport {
margin-right: -600px;
padding-right: 600px;
}
body {
overflow: visible;
}
}
So, my question is how to make it work under Mozilla Firefox?
Thanks in advance
Horizontal centering:
For the object you need to center just use the following:
display: block;
margin-left: auto;
margin-right: auto;
It is absolutely cross-browser.
Edit:
Try to change container class styles like this:
.container{
height: 100%;
display: table;
vertical-align: middle;
background: green;
}
You need to make the blocks you want aligned vertically inline or inline-block. vertical-align: middle; does not work on block elements.
Related
I have the following HTML
.wrapper {
position: relative;
width: 100%;
overflow: hidden;
}
.no-padding {
padding: 0 !important;
}
.home-slider img {
margin-right: 6px;
float: left;
width: 35px;
position: relative;
top: -4px;
}
.home-slider-wrap {
position: relative;
}
.home-slider-wrap .bg-img {
height: 500px;
width: auto;
max-width: none;
}
.img-full {
width: 100%;
}
#media (max-width: 767px) {
.home-slider-wrap .bg-img {
min-height: auto;
min-width: 100%;
width: 100%;
height: auto;
}
}
<div class="wrapper">
<div class="container-fluid no-padding">
<div class="home-slider-wrap">
<div class="home-slider">
<div>
<img src="https://g5-assets-cld-res.cloudinary.com/image/upload/q_auto,f_auto,fl_lossy/g5/g5-c-1t2d31r8-berkshire-communities/g5-cl-i2pbvvuq-creekstone/uploads/pet-friendly.jpg" class="bg-img img-full ing-responsive" alt="">
</div>
</div>
</div>
</div>
</div>
I am trying to resize this image but at the same time also keep a minimum height for devices less than 768px; However as you can see in the demo below, this ain't working out.
The portion of the cat and dog isn't visible when the page is resized for a mobile device.
Demo
How do I fix this? Any help is appreciated.
You could try using a media query
Maybe you can try this css:
background-size: cover;
background-position: center;
background-repeat: no-repeat;
You can use media query to target below 768px width devices to define style like below -
#media (max-width:767px){
.home-slider-wrap .bg-img {
min-height: auto;
min-width: 100%;
width: 100%;
height: auto;
}
}
I'm trying to build an info card where if the screen is large, you'd have an image filling the left half of the card and text on the right and if the screen is small you'd have the picture on the top and text on the bottom. I was able to do the first part by adding position: absolute;top: 0;left: 0;bottom: 0;width: 40%, and the setting background-image: src;background-size: cover; and then setting margin-left: 40% on the content. But ultimately this makes it hard for a structure like this to adapt to screen sizes without some javascript. I'd like to avoid using js as much as possible for this so I looked for solutions online and came upon answers such as using a flexbox and using the object-fit css property, but none of those really worked. Here's my code:
.signup-form-wrapper {
display: flex;
align-items: center;
height: 400px;
width: auto;
border: 1px solid rgb(200, 200, 200);
margin: 10px 0px;
}
.img-wrapper {
height: 100%;
width: 50%;
}
.img-wrapper img {
display: block;
max-width: 100%;
height: auto;
}
.content-wrapper {
display: inline-block;
max-width: 60%;
text-align: center;
padding: 0px 14%;
}
body {
height: 100%;
width: 100%;
}
<body>
<div class='signup-form-wrapper'>
<div class='img-wrapper'>
<img src='http://www.parkermeridien.com/media/pool_fashion_f.jpg' />
</div>
<div class='content-wrapper'>
<p>Hello, World!</p>
</div>
</div>
</body>
You were on the right track!
Media queries (which you experimented with) are the right way to do this without JavaScript. I went back to using a background-image instead of an img - here's a simple way to do this using floating to keep the elements side-by-side, with a media query (at the bottom of the CSS) that turns off the floating so the elements stack.
I also added box-sizing: border-box; for all elements to prevent padding/borders from modifying the size of elements (which is good practice).
body {
height: 100%;
width: 100%;
}
* {
box-sizing: border-box;
}
.signup-form-wrapper {
height: 350px;
border: 1px solid rgb(200, 200, 200);
margin: 10px 0px;
}
.img-wrapper {
height: 100%;
width: 40%;
float: left;
background-image: url('http://www.parkermeridien.com/media/pool_fashion_f.jpg');
background-size: cover;
}
.content-wrapper {
float: left;
width: 60%;
text-align: center;
padding: 0px 14%;
}
#media (max-width: 768px) {
.img-wrapper,
.content-wrapper {
width: auto;
float: none;
height: 175px;
}
}
<body>
<div class='signup-form-wrapper'>
<div class='img-wrapper'>
</div>
<div class='content-wrapper'>
<p>Hello, World!</p>
</div>
</div>
</body>
I am new to this so please excuse me.
I am working on my first website coding and, I am having so much difficulties with centering my button. I want to place the button on the middle of the window.
I will attach the code below:
/* Hide Scroll */
html, body {
overflow:hidden;
}
/* Home Page - Background Image */
body {
background: url(Image-2.jpg);
background-repeat: no-repeat;
background-size: cover;
position: relative;
top: 0;
left: 0;
min-width: 100%;
min-height: 100%;
}
/* Mains */
#Mains-Logo {
margin-top: 42px;
margin-left: 80px;
}
#Mains-Basket {
float: right;
margin-top: 48px;
margin-right: 96px;
}
#Mains-SP {
text-align: center;
margin-top: 785px;
margin-left:810px;
}
/* Button */
.Button-SN {
text-align: center;
min-height: 100%;
min-width: auto;
}
.SN {
border: 5px solid #fcfcfc;
padding: 8px 25px;
margin: auto;
}
<body>
<img id="Mains-Logo" src="Logo.png">
<img id="Mains-Basket" src="Basket.png">
<!-- THIS RIGHT HERE -->
<div class="Button-SN">
<a class="SN" href="#">SHOP NOW</a>
</div>
<!-- END -->
</body>
<footer>
<img id="Mains-SP" src="SP.png">
</footer>
This question has already been answered in stack overflow, here are some useful links to solve your problem.
align text in middle/center of page and button on bottom/center
How to center a button within a div?
trying to align html button at the center of the my page
How to center html element in browser window?
Remove the wrapper .Button-SN.
Add:
.SN{
position:absolute;
display: inline-block;
top:50%;
left:50%;
width:150px;
border: 5px solid #fcfcfc;
line-height: 40px;
margin-top:-20px;
margin-left:-75px;
}
Use clear:both to clear floated direction.
.Button-SN {
clear: both;
min-height: 100%;
min-width: auto;
text-align: center;
}
Try adding this to your button CSS:
display: flex;
justify-content: center; /*centers items on the line (the x-axis by default)*/
align-items: center; /*centers items on the cross-axis (y by default)*/
position:absolute;
Let me know how you get on!
Thanks
Method #01:
Wrap both images in a div and set layout of parent with overflow: hidden.
/* Hide Scroll */
html, body {
overflow:hidden;
}
/* Home Page - Background Image */
body {
background: url(Image-2.jpg);
background-repeat: no-repeat;
background-size: cover;
position: relative;
top: 0;
left: 0;
min-width: 100%;
min-height: 100%;
}
/* Mains */
.image-holder {
overflow: hidden;
}
#Mains-Logo {
margin-top: 42px;
margin-left: 80px;
}
#Mains-Basket {
float: right;
margin-top: 48px;
margin-right: 96px;
}
#Mains-SP {
text-align: center;
margin-top: 785px;
margin-left:810px;
}
/* Button */
.Button-SN {
text-align: center;
min-height: 100%;
min-width: auto;
}
.SN {
border: 5px solid #fcfcfc;
display: inline-block;
vertical-align: top;
padding: 8px 25px;
margin: auto;
}
<body>
<div class="image-holder">
<img id="Mains-Logo" src="Logo.png">
<img id="Mains-Basket" src="Basket.png">
</div>
<!-- THIS RIGHT HERE -->
<div class="Button-SN">
<a class="SN" href="#">SHOP NOW</a>
</div>
<!-- END -->
</body>
<footer>
<img id="Mains-SP" src="SP.png">
</footer>
Method #02:
Add clear: both to the styles of .Button-SN.
/* Hide Scroll */
html, body {
overflow:hidden;
}
/* Home Page - Background Image */
body {
background: url(Image-2.jpg);
background-repeat: no-repeat;
background-size: cover;
position: relative;
top: 0;
left: 0;
min-width: 100%;
min-height: 100%;
}
/* Mains */
#Mains-Logo {
margin-top: 42px;
margin-left: 80px;
}
#Mains-Basket {
float: right;
margin-top: 48px;
margin-right: 96px;
}
#Mains-SP {
text-align: center;
margin-top: 785px;
margin-left:810px;
}
/* Button */
.Button-SN {
text-align: center;
min-height: 100%;
min-width: auto;
clear: both;
}
.SN {
border: 5px solid #fcfcfc;
display: inline-block;
vertical-align: top;
padding: 8px 25px;
margin: auto;
}
<body>
<img id="Mains-Logo" src="Logo.png">
<img id="Mains-Basket" src="Basket.png">
<!-- THIS RIGHT HERE -->
<div class="Button-SN">
<a class="SN" href="#">SHOP NOW</a>
</div>
<!-- END -->
</body>
<footer>
<img id="Mains-SP" src="SP.png">
</footer>
Try
.Button-SN {
text-align: center;
margin: 0 auto;
}
You can try this:
vertical-align:middle;
Is this a bug in firefox?
CSS,
html, body {
height: 100%;
margin: 0;
padding: 0 0;
/*border: 4px solid black;*/
}
.container-fluid {
height: 100%;
width: 100%;
display: table;
padding-right: 0;
padding-left: 0;
/*border: 4px solid blue;*/
}
.row-fluid {
height: 100%;
width: 100%;
display: table-cell;
vertical-align: middle;
background-color:#990000;
/*border: 4px solid red;*/
}
.img-container {
height: 100vh;
width: 100%;
display: flex;
align-items: center;
}
.img-container img{
max-width:100%;
max-height:100%;
margin-left: auto;
margin-right: auto;
}
HTML,
<div class="container-fluid">
<div class="row-fluid">
<div class="img-container">
<!-- <img src="http://placehold.it/400x450"> -->
<img src="http://placehold.it/2000x450">
<!-- <img src="http://placehold.it/400x480"> -->
</div>
</div>
</div>
Chrome,
The large image will be scaled down to fit the screen width which is what I want.
Firefox,
The image is not scaled down to fit the screen.
Any ideas how I can fix this?
EDIT:
#-moz-document url-prefix() {
.img-container img {
width: 100%;
max-width: -moz-max-content;
}
}
Since you are using CSS table for the layout already, I'm suggesting this approach without flexbox. It works nicely on Chrome and Firefox according to my tests. I added a div around the img.
jsFiddle
body { margin:0; }
.img-container {
display: table;
table-layout: fixed; /*required for responsive width in Firefox*/
width: 100%; /*required for fixed table layout*/
}
.img-container .image {
display: table-cell;
text-align: center;
vertical-align: middle;
height: 100vh; /*required for responsive height*/
}
.img-container .image img {
max-width: 100%;
max-height: 100%;
vertical-align: middle; /*remove whitespace*/
}
<div class="img-container">
<div class="image">
<img src="http://placehold.it/400x300">
<!-- <img src="http://placehold.it/2000x450"> -->
<!-- <img src="http://placehold.it/400x480"> -->
</div>
</div>
Alternatively, you can use pseudo element :before or :after + inline block for vertical alignment. No markup change is required.
jsFiddle
body { margin:0; }
.img-container {
width: 100vw; /*required for responsive width in Firefox*/
height: 100vh;
text-align: center;
font-size: 0; /*remove whitespace*/
}
.img-container:after {
content: "";
display: inline-block;
height: 100%;
vertical-align: middle;
}
.img-container img {
max-width: 100%;
max-height: 100%;
vertical-align: middle;
}
<div class="img-container">
<img src="http://placehold.it/400x300">
<!-- <img src="http://placehold.it/2000x450"> -->
<!-- <img src="http://placehold.it/400x480"> -->
</div>
Yes there is problem in firefox. It will not maintaining aspect ratio. To make it working just add width: 100%; to image will solve issue.
.img-container img {
margin-left: auto;
margin-right: auto;
max-height: 100%;
max-width: 100%;
width: 100%;
}
Working Fiddle
Check same type of issue here.
Edit:
To solve issue for all size image use max-width: -moz-max-content;
#-moz-document url-prefix() {
.img-container img { width: 100%; max-width: -moz-max-content; }
}
Updated Fiddle
Based on a bug report (see below), this is a known issue with Firefox. (Although IE11 also fails to scale the image as desired).
This seems to solve the problem in Firefox:
Instead of:
.img-container img {
max-width: 100%;
max-height: 100%;
margin-left: auto;
margin-right: auto;
}
Try this:
.img-container img {
width: 100%; /* adjusted */
height: auto; /* adjusted */
margin-left: auto;
margin-right: auto;
}
DEMO
Another possible solution involves adding table-layout: fixed to the main container (.container-fluid). This method is detailed in this bug report:
Bug 975632 - max-width: 100%; doesn't work inside tables or display: table
The page open with scroll. I want to make the page appear fully responsive without any scroll bar. I tried to set the height to 100% with no luck.
html {
height: 100%;
width: 100%;
}
body{
width:100%;
hight:100%;
margin: 0;
padding:0;
}
.main{
background-image: url("http://www.ghadaalsamman.com/new/images/bg.gif");
background-repeat: no-repeat;
background-position: center center;
margin: 0;
padding-top: 30vw;
background-size: 100%;
}
.marquee {
display: block;
position: relative;
width: 51vw;
margin: auto;
}
marquee{
width: 100%;
margin: auto;
display: block;
}
#btn1 {
background: url("http://www.ghadaalsamman.com/new/images/enter.gif") no-repeat scroll center center ;
display: block;
height: 53px;
margin: 0 auto;
position: relative;
width: 50%;
background-size: 100%;
margin-top: 33%;
margin-bottom:1%;
}
.button {
padding: 5px;
}
.container {
display: block;
height: 100%;
margin: 0 auto;
max-width: 960px;
position: relative;
}
#media screen and (max-width:500px) {
#btn1{
background-size: 100% auto;
}
}
<div class="main">
<div class="container">
<div class="marquee">
<marquee scrollamount="3" direction="right" dir="ltr">
<h3 align="center" style="color:#804000;font-size:large;margin-top:0px;"><strong>
<img height="auto" width="200%" src="http://www.ghadaalsamman.com/new/images/image21.png">
</strong></h3>
</marquee>
</div>
<a class="button" id="btn1" href="http://ghadaalsamman.com/new/site.html"></a>
</div>
</div>
This is the problem
body {
width: 100%;
hight: 100%; <----- 'hight' make it 'height'
margin: 0;
padding: 0;
}
Replace with this
body {
width:100%;
height:100%;
margin: 0;
padding:0;
}
the ratio of your image will make it difficult i believe.
Since you started using vw units, maybe it's an hint to use vh units and max-width too.
Because of your image, too much like a square, the container needs too be a bit smaller to stay in sight. Because of , vw units, i would propose to use display:fle to easily center you container :
DEMO of my idea
CSS updated :
html {
height: 100%;
width: 100%;
}
body {
width:100%;
height:100%;/* UPDATED*/
margin: 0;
padding:0;
display:flex;/* UPDATED*/
}
.main {
background-image: url("http://www.ghadaalsamman.com/new/images/bg.gif");
background-repeat: no-repeat;
background-position: center center;
margin: 0;
padding-top: 15vh;/* UPDATED*/
background-size: 100%;
width:100vh;/* UPDATED*/
margin:auto;/* UPDATED*/
max-width:100vw;/* UPDATED*/
overflow:hidden;/* UPDATED hide marquee*/
}
.container {
display: block;
height: 100%;/* useless when parent has no height given */
margin: 0 auto;
position: relative;
}