CSS3 div background-image autoresize - css

I was looking for many posts here on stackoverflow, but there was nothing, what could help me. Maybe this question is trivial, but i don't know how to do that, because I am beginner in this
So i have some header, where is logo, menu and some title -that is not problem. Under this header i have div with class slider, where i want to have some background-image and on this background-image i want to have some button and title and another image. And here is finally my question.
What should i do, if i want to have this background-image of this div on full width and with auto height (height from end of header to end of screen) for any screen resolution on desktop?
I mean: if i have resolution 1920x1080 i want to have this bg-image from end of header to end of screen. Same thing for resolution for example 1366x768 etc etc...i hope you understand my question.
Example on this
image
Header is red. And i want to have bg-image (in this case white part of image, but i want to have image there) auto resize for any screen resolution.
I really hope you understand my question and someone can help me.
Really thanks for any reply
http://jsfiddle.net/YKY4t/
I have some errors in code so please...
Code:
#import url(https://fonts.googleapis.com/css?family=Quicksand:400,300,700);
body {
margin: 0;
padding: 0;
}
.mainheader {
width: 100%;
height: 10%;
background-color: #ff5959;
position: absolute;
}
.mainheader img {
max-width: 100%;
height: auto;
margin-left: 20%;
margin-top: 1.5%;
float: left;
}
.title {
position: absolute;
margin-top: 1%;
margin-left: 22%;
font-size: 35px;
font-family: 'Quicksand', sans-serif;
color: #ffffff;
}
.meta {
position: absolute;
margin-left: 18%;
margin-top: 3%;
font-size: 19px;
font-family: 'Quicksand',sans-serif;
font-weight: bold;
color: #ffffff;
}
.nav {
position: absolute;
right: 20%;
margin-top: 1%;
font-size: 19px;
font-family: 'Quicksand', sans-serif;
font-weight: bold;
}
.nav li {
list-style-type: none;
float: left;
}
.nav li a {
color: #ffffff;
text-decoration: none;
display: block;
margin-left: 25%;
}
.slider img {
background-image: url(../img/slider-image.png);
background-repeat: no-repeat;
background-position: center center fixed;
background-size: cover;
}

As i commented, you can use media queries for the different screen sizes where you can use different resolution images. In that case:
#media all and (min-width: 1920) {
.img-holder img{
background-img: url(../img/slider-image.png);
}
}
#media all and (min-width: 1366) {
.img-holder img{
background-img: url(../img/slider-image-medium.png);
}
}
You can use them to use all screen resolutions you want to cover.
You alse can use any responsive framework like Bootstrap which responsives the images.

Related

Wordpress storefront Sticky header with centered menu and logo

I'm working on wordpress project for a friend. Unluckily (for me), she decided that site need sticky header which goes beyond my actual CSS understanding. I've created css that helps me center logo and menu below. Now I need help with making it sticky and setting logo in between menu/navbar positions.
Screen of header
[1]: https://i.stack.imgur.com/Vg3PF.jpg
a:focus {
outline: 0;
}
#import url('https://fonts.googleapis.com/css2?family=Open+Sans:wght#300&family=Playfair+Display+SC&display=swap');
/* center logo*/
.site-branding{
width:100% !important;
text-align:center;
}
.site-header .site-branding img {
margin: auto;
margin-top: 50px;
margin-bottom: 30px;
max-width: 300px;
}
/* center menu */
nav#site-navigation {
width: 100%;
text-align: center;
margin-right: 0px;
margin-bottom:55px;
font-size: 24px;
font-family: Playfair Display SC;
}
#media (min-width: 768px){
.woocommerce-active .site-header .site-header-cart {
width: 21.7391304348%;
margin: 0 auto;
float:none;
}
.entry-content{
font-family: Open Sans;
}
.h2 {
font-family: Playfair Display SC;
}````
you can use sticky and position : fixed for sticky items.
.sticky {
position: fixed;
top: 0;
width: 100%
}

How to make logo stay centered and shrink to fit as browser resized

Trying here: http://alternativegrow.com.au/
to make logo stay centered and shrink to fit as browser resized (instead of getting cut off). I have followed a number of recommended techniques but to no avail...
I am a little unsure which elements I've added or modified are helping or hindering.
What I've added, via custom css plug in for now:
.header-image .site-title > a {
float: left;
max-width: 100%;
height: auto;
background-size: 100% auto !important;
background-position:center;
}
.title-area {
float: left;
padding: 10px 0;
}
.site-header .wrap {
padding: 10px 0;
}
What is in stylesheet:
/* ## Title Area
--------------------------------------------- */
.title-area {
float: left;
padding: 10px 0 10px 15px;
width: 360px;
}
.header-full-width .title-area {
width: 100%;
}
.site-title {
font-size: 24px;
font-weight: 400;
line-height: 1.2;
}
.site-title a,
.site-title a:hover {
color: #fff;
}
.header-image .site-title > a {
background: url(images/logo.png) no-repeat left;
float: left;
min-height: 160px;
width: 350px;
}
.site-description {
font-size: 16px;
font-weight: 300;
line-height: 1.5;
}
.site-description,
.site-title {
margin-bottom: 0;
}
.header-image .site-description,
.header-image .site-title {
display: block;
text-indent: -9999px;
}
.site-description {
color: #fff;
edit - Oh I did try media queries but they also did not work. Specifically I tried adjusting the min-height at different beak points, with width set as auto, expecting the width to adjust relative to the height setting, but in fact the logo just disappeared when I did this. I do not really want to use multiple sized logos for various break points as this seems clunky to me, however it is better than what is here, but this also did not work for me.
Not sure to understand whether the example you point to is what you try to achieve or what you try to modify.
Maybe this example can help you
The important parts are:
1) to make the element which holds the logo as background take all the space available
2) set the background-size at 'contain'
<header>
<div class="logo"></div>
</header>
.logo{
background:url('http://www.vectortemplates.com/raster/batman-logo-big.gif') no-repeat center;
width: 100%;
height: 100%;
background-size:contain;
}
header{
height:200px;
}

Fixed Header stays when scrolls but navigation doubles

I currently am using a fixed header for my website: http://www.destinykingproductions.com/test/ I have attached the css I currently have. Anyone have any suggestions on why this is happening?
#main {
background-color: transparent;
margin-top: -40px;
height: auto;
max-height: none;
width: auto;
padding-bottom: 35px;
}
header#masthead {
height: 103px;
background-image: url(http://www.destinykingproductions.com/test/wp-content/uploads/2014/08/header_bg1.jpg);
position: fixed;
z-index: 856;
width: 100%;
margin-top: 0px;
top: 0px;
}
nav.main-navigation {
top: -200%;
background-color: transparent;
z-index: 4670;
}
nav.main-navigation ul.menu li {
padding-left: 17px;
}
nav.main-navigation ul.menu {
margin-left: 18%;
}
#shiftnav-toggle-main {
display: none;
}
Thank you for your assistance!
The comments above are correct - the "sticky" class nav is being added / toggled at some point. When you add 'display:none' to that sticky class, then it is fine on a desktop view. However, it looks like you are using that class for something with mobile because when the screen is resized smaller and back to normal then the side menu area doesn't go away. It looks like you may want to move that sticky class to your 768px media query and/or have it not show on larger screens.
/*normal css*/
.main-navigation.sticky { display: none }
#media screen and (max-width: 768px)
{
.main-navigation.sticky { display: block }
}

How can I make this image responsive? [duplicate]

This question already has answers here:
How do i get my image to be responsive?
(4 answers)
Closed 2 months ago.
I am trying to include a logo for my site. It needs to be responsive. With the following CSS the image is OK with width, but the top & bottom of the logo are not displayed. If the site was not responsive, I would just put height: 100px; underneath the width. How can I make all the logo display, including the top and bottom bits of it, but still make the logo responsive?
.header-image .site-title > a {
background: url(images/logo.png) no-repeat left;
float: left;
width: 100%;
}
The rest of the CSS which my be making the top & bottom parts of the logo to not be displayed, is below.
.title-area {
float: left;
padding: 10px 0;
width: 360px;
}
.header-full-width .title-area {
width: 100%;
}
.site-title {
font-size: 32px;
font-weight: 400;
line-height: 1.2;
}
.site-title a,
.site-title a:hover {
color: #333;
}
.header-image .site-title > a {
background: url(images/logo.png) no-repeat left;
float: left;
width: 100%;
}
.site-description {
font-size: 16px;
font-weight: 300;
line-height: 1.5;
}
.site-description,
.site-title {
margin-bottom: 0;
height: auto; /*added by me */
}
.header-image .site-description,
.header-image .site-title {
display: block;
text-indent: -9999px;
}
I suspect that it is something to do with a container?
using a fixed height for an element doesn't automatically make a site "not responsive," but you might consider using min-height: 100px; (or whatever the correct height is) to ensure that important elements of the logo won't be hidden. Depending on what exactly the desired behavior is, you could also (or instead) set a relative height (e.g. height: 100%;)
Another possible approach is to use either the cover or contain keyword value for the background-size property

Trying to use percentages for Responsive CSS

I whipped up this site at http://www.flywavez.com/ and have it mostly situated (I have to even up a few margins a pixel here, a pixel there), but I went to check it on the iPhone, Android (galaxy s3 running 4.3, Chrome and the android browser), iPad, and Kindle and I don't think my CSS margins are being interpreted how they are in the screen browsers (i.e. - desktops and laptops).
I used percentages on my margins, and even tried padding, but I can't find that balance where the elements display relatively uniform. Should I specify a separate style sheet just for mobile with the different margins? For the phones, it seems like .socials ( a sprite, btw) would have a margin-left of 0, with a few on top to kick it down some.
The same for #quick-mid-text, on a seperate phone browser, the margin would be left 0.
However I want to keep it as much in one style sheet as possible. What should I use as margins or element arrangement to render the social media icons to be centered under the player, and for the paragraph in #quick-mid-text to be flush with the left edge of the player?
Here's my CSS:
.socials {
float: right;
padding-top: 13px;
margin-right: 40%;
width:275px;
}
.socials a {
display: block;
width: 58px;
height: 50px;
float: left;
background: url(../images/socials2.png) 0 0 no-repeat;
}
.socials a:hover {
opacity: 0.5;
}
.socials a+a {
margin-left: 12px;
background-position: -62px 0;
width: 56px;
}
.socials a+a+a {
margin-left: 4px;
background-position: -120px;
width: 32px;
}
.socials a+a+a+a {
margin-left: 4px;
background-position: -156px;
width: 93px;
}
I'd suggest you use media queries to change styles based on screen width. You can do base styles and then override them etc in your media query.
Eg:
.socials {
float: right;
padding-top: 13px;
margin-right: 40%;
width:275px;
}
#media only screen and (max-width: 979px) {
.socials {
margin-right: 10px;
}
}
Please Try This css...
#quick-mid-text {
margin-bottom: 0;
margin-left: auto;
margin-right: auto;
margin-top: 13px;
width: 42%;
}
.socials { /* style.css -line no.756*/
float: none;
margin-bottom: 0;
margin-left: auto;
margin-right: auto;
margin-top: 13px;
padding-top: 0;
width: 260px;
}

Resources