Asking for advice: What would be the best way of making my website's (square) logo appear on or to the left of a fluid header?
My header takes up 100% of the width, but resizes in height depending on the viewport size. So I can't simply float the logo to the left of the contents, because then the image doesn't have the right height (and width, because it's square).
I tried setting the picture as background-image to the header, using:
background-position: left;
background-repeat: no-repeat;
background-size: contain;
But the problem then is that it needs different paddings-left at different screen/viewport sizes.
Then tried putting display: table on the header and display: table-cell on the logo and header contents div, but then the header contents resize to the height of the logo rather than the other way around because the logo is the biggest element in line.
Here's the HTML (simplified):
<header>
<div class="header-contents">
<h1>Site title</h1>
<nav>
</div>
</header>
What should I do?
EDIT / COMPLETELY DIFFERENT SOLUTION:
Style it as a CSS table, put the img in a DIV that's the left table-cell, give that a percentage width and auto height:
(Here in a codepen: http://codepen.io/anon/pen/XXNyBe)
<div id="header">
<div id="logo">
<img src="http://placehold.it/300x300/fa0">
</div>
<div id="restofheader">
<h1>My Headline</h1>
</div>
</div>
#header {
background: green;
display: table;
width: 100%;
}
#logo {
display: table-cell;
line-height: 0;
width: 20%;
}
#logo img {
width: 100%;
height: auto;
}
#restofheader {
display: table-cell;
vertical-align: middle;
text-align: left;
padding-left: 30px;
}
Addition, 2 Screenshots where this is applied to your site (with 20% logo width = header height - could be smaller or larger):
Large screen:
small screen:
.header-contents {
background-image: url(yourimage);
background-position: left center;
background-size: auto 100%;
background-repeat: no-repeat;
}
if it is not the answer your looking for, please provide a fiddle and a better explanation :)
What I've done instead now is give fixed header heights for different resolutions. It seems totally fluid is not an option here.
The code, in case anyone's interested:
#media only screen and (min-width: 568px) {
.site-branding {
background: url('http://atlanticsentinel.com/wp-content/uploads/2015/12/Atlantic-Sentinel-logo.png');
background-position: left;
background-size: contain;
background-repeat: no-repeat;
height: 100px;
padding-left: 115px; }
h1.site-title {
font-size: 2em; } }
#media only screen and (min-width: 768px) {
.site-branding {
height: 120px;
padding-left: 135px; }
h1.site-title {
font-size: 3.2em; } }
If there is another option, please let me know! I would appreciate other ideas!
Thank you for your help!
Related
Take the following code:-
HTML:
<div id="wrapper">
<div id="nottingham-park">
</div>
CSS:
#wrapper {
width: 100%;
height: auto;
}
#nottingham-park {
background: url(http://planetbounce.m360.co.uk/wp-content/themes/planetbounce/assets/img/nottingham-park.png);
background-size:100% auto;
background-repeat: no-repeat;
display: block;
//height: 700px;
}
FIDDLE
If I don't set a height to #nottingham-park, the background image isn't visible, if I set a height, it's not responsive.
How can I display the image so it's always 100% width and auto height?
you can force the size of #nottingham-park to the size of the background-image with padding-top. see the comments in the css to see how you can calculate what the padding-top should be.
this way your image will be responsive and never stretched out of proportion.
hope this is what you are asking for.
#wrapper {
width: 100%;
height: auto;
}
#nottingham-park {
background: url(http://planetbounce.m360.co.uk/wp-content/themes/planetbounce/assets/img/nottingham-park.png);
background-size: contain;
background-repeat: no-repeat;
display: block;
/*
width of image / height of image * width
699px / 1200px * 100 = 57.7208918249
(change the 100 in this formula to whatever you want.)
*/
padding-top: 57.7208918249%;
}
<div id="wrapper">
<div id="nottingham-park">
</div>
</div>
EDIT
How about a fluid padding-bottom ?
Like this
#nottingham-park {
background: url(http://planetbounce.m360.co.uk/wp-content/themes/planetbounce/assets/img/nottingham-park.png);
background-size:100% auto;
background-repeat: n-repeat;
display: block;
padding-bottom : 55%;
}
The "menu" is in the page footer. With a picture, a sprite and text. When I resize and open the site or by phone, the menu does not fit. I tried to add some medium queries, but without success.
I want in the way mobile and or resize the screen, the image, text and sprite fit according to the size of the viewport.
Link site
If possible, resize the screen to a small width, open the browser console or the same cell.
CSS:
html, body{
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
ul, li{
margin: 0;
padding: 0;
}
h2{
font-family: 'Open Sans Condensed', sans-serif !important;
color: black !important;
font-size: 30px !important;
line-height: 15px !important;
}
#principal {
width: 100%;
height: 100%;
background-image: url('../images/background.jpg');
position: absolute;
background-repeat: no-repeat;
background-position: center center;
background-size: cover;
}
#faixa{
position: absolute;
width: 100%;
background-image: url('../images/faixa2.png');
background-repeat: no-repeat;
bottom: 0;
}
#img-logo{
margin-left: 35%;
display: inline-block;
text-align: center;
}
#contato{
position: absolute;
margin-left: 20px;
display: inline-block;
height:auto;
text-align: center;
}
#media(max-width:1050px){
#img-logo{
margin-left: 20%;
}
}
#media(max-width:760px){
#img-logo{
margin-left: 10%;
}
}
#media(max-width:635px){
#img-logo{
margin-left: 5%;
}
}
#media(max-width:580px){
#img-logo{
margin-left: 0;
}
}
#media(max-width:551px){
/* #logo{
width: 20%;
}*/
/* }
#img-logo{
width: 50%;
height: 25%;
}*/
}
HTML:
<div id="principal">
<div id="faixa">
<img src="images/logo4.png" id="img-logo" class="img-responsive">
<div id="contato">
<ul>
<li></li>
<li></li>
<li></li>
</ul>
<h2> (44) 4444-4444 <br><br> <span style="font-size: 18px"> Av. blablabal, 2323 - fer ie jeo <br> cidade - paĆs</span> </h2>
</div>
</div>
</div>
I have two divs. The main , with the background image and the div group , which obviously is a yellow stripe. Within this div group I added the logo, directly by the tag img and a div with sprite and text. I've tried many ways to modify the media but from what I understand, the range of the image appears only when you have some content inside. She alone is not displayed. So when we decrease the image size, the track size is automatically modified as well. I've tried to insert a div with the logo in the background, also leaving soon, the sprite and isolated text div group and nothing. I tried to modify the size of the content in many different ways, but without success /:
Try to put in the query of #media (max-width: 760px) different kind of dimension for the two div ( logo and contato ), At this size you can give to the image a porcentage dimension.
Try to give to delete some information on mobile (so it can fit better), and change the font size.
I am learning how to make an existing site, responsive and something that appears to be so simple, is making me absolutely crazy.
When I apply the max-width-480px style sheet, it is cutting off about 5 px of my left edge. You can tell it is missing because the rounded corners I added in css are cut off abruptly on the left but are nice and smooth on the right. I have spent several hours trying to tweak the wrapper and mainwrapper css and nothing seems to fix it. Any ideas?
Note: that the image for the topwrapper is a set width white background with rounded corners. Since the set sized graphic is not going to be responsive, I have removed it for the smaller screens and just added the border-radius to the mainwrapper div.
NOTE2: I tried to add an image to show you the issue, but because I am a new poster, I was unable to. The site is: www.develdesign.com/WaterWorks Please be sure to view it on your smartphone to see the issue. Thank you.
A snippet of the wrapper related divs in html
<body>
<div id="wrapper">
<div id="topwrapper"></div>
<div id="mainwrapper">
<!-- Header Start -->
<div id="header">
<div class="center">
<!-- Logo Start -->
<div id="logo"><img src="images/wworks/wwlogo239px.png" alt="logo" /></div>
<!-- Logo End -->
<div id="headerright">
<!-- Menu Navigation Start -->
<? require('top-navigation.php'); ?>
<!-- Menu Navigation End -->
</div><!-- end headerright -->
</div><!-- end center -->
</div><!-- end header -->
Regular Desktop Styles (non-responsive css)
#wrapper {
width: 100%;
max-width: 976px;
height: 100%;
margin-left: auto;
margin-right: auto;
margin-top: 20px;
margin-bottom: 20px;
}
#topwrapper {
height: 19px;
width: 100%;
max-width: 976px;
background: url(../images/topwrapper.png) no-repeat;
}
#mainwrapper {
width:100%;
max-width: 976px;
background: url(../images/mainwrapper.png) repeat-y;
}
#bottomwrapper {
margin: 0 auto;
height: 55px;
width: 100%;
max-width: 976px;
background: url(../images/bottomwrapper.png) no-repeat;
}
.center {
margin: 0 auto;
width: 900px;
}
/* ----------------------- HEADER -----------------------*/
#header {
width: 960px;
height: 50px;
padding-bottom: 39px;
background: url(../images/bgheader.jpg) bottom center repeat-x;
margin: 0 auto;
}
#headerright {
padding-top: 20px;
width: 670px;
float: right;
position: relative;
}
#logo {
margin-top: 15px;
float: left;
width: 220px;
}
Responsive for max-width-480px
#wrapper {
width: 100%;
}
#topwrapper {
display:none;
}
#mainwrapper { /*white background for all header and maincontent */
border-radius: 5px 5px 25px 25px;
}
#bottomwrapper {
display: none;
}
.maincontent {
width: 60%;
float: left;
}
<!-- HEADER -->
#header {
/*width: 50%;*/
/*height: 50%;*/
/*background-image: none;*/
}
.center {
width: 95%;
}
#headerright{ /* includes phone numbers and full site navmenu */
display:none;
}
#logo {
width: 100%;
}
Can't say for sure but after a quick look, could it not be possible there is padding somewhere knocking it out. If so make sure to set the box-sizing attribute in your css.
Link:
Box Sizing
Also check there is no whitespace between elements, this also effects display: inline-block in such a way that two divs at 50% width won't fit next to each other. You can either set line height to 0 or comment out the whitespace.
I finally figured it out! The mainwrapper had a background image that was also a set width image (like the topwrapper). Once I realized the mainwrapper's background image repeated only y, I removed it and replaced it with a background-color of white instead and it looks great.
#mainwrapper {
width:100%;
max-width: 976px;
background: url(../images/mainwrapper.png) repeat-y;
}
I am trying out responsive layout with 100% div wrapper and then placing a background image with text above and below it.
Unable to get it to display.
Looking to get the image to resize with browser window.
What am I doing wrong?
.wrapper {
width: 100%;
}
.image {
background: url("http://upload.wikimedia.org/wikipedia/commons/3/35/Rivi%C3%A8re_Coulonge_Pont_Davidson_1024x768.JPG") no-repeat center;
background-size: cover;
}
.text {
text-align: center;
font-size: 50px;
color: yellow;
}
http://jsfiddle.net/f5F6T/
Looks like you need to give height and width to your .image element. As well as a height to your wrapping div.
u need to set the content in middle div or give height. because initial div does nt have any height so how can u see the background??
check the fiddle-
--HTML--
<div class="wrapper">
<div class="text">Give the height to below div!</div>
<div class="image"></div>
<div class="text">So, here u have ur photo</div>
</div>
--CSS--
.image {
background: url("http://upload.wikimedia.org/wikipedia/commons/3/35/Rivi%C3%A8re_Coulonge_Pont_Davidson_1024x768.JPG") no-repeat center;
background-size: cover;
height:100px;
}
You're .image is actually 0px heigh, that's why the image is not displayed.
Check out this :
just moved the .image code into the .text code :
.text {
background: url("http://upload.wikimedia.org/wikipedia/commons/3/35/Rivi%C3%A8re_Coulonge_Pont_Davidson_1024x768.JPG") no-repeat center;
background-size: cover;
text-align: center;
font-size: 50px;
color: yellow;
}
http://jsfiddle.net/f5F6T/1/
Edit :
.image {
height: 30px;
background: url("http://upload.wikimedia.org/wikipedia/commons/3/35/Rivi%C3%A8re_Coulonge_Pont_Davidson_1024x768.JPG") no-repeat center;
background-size: cover;
}
http://jsfiddle.net/f5F6T/3/
I've got a logo on my website that i'm trying to make stay in the middle and be responsive. I've tried tons of CSS code from "magin-left:auto;..." to "top:30..." but the logo wont get smaller and stay in the middle. I was wondering if anyone could help me. Heres my website -- http://www.mediadude.co.uk -- The logo is the big mediadude sign in the middle, Try resizing the browser and you can see that it doesn't stay in the middle and get smaller.
Thanks for you time.
Hantoo
You have set max-width to the image but not to the h1 tag.
h1#LogoMain {
max-width: 100%;
}
Also you have a media query giving body padding: 20
#media (max-width: 767px) {
body {
padding-top: 0;
padding-right: 20px;
padding-left: 20px;
}
Change the above values to 0 for an edge to edge look on your header etc.
This will do what you want: http://jsfiddle.net/TJF8k/1/
<div class="header">
<div class="floater"></div>
<div class="imgwrap">
<img class="image" src="//placehold.it/400x150">
</div>
</div>
For the CSS, you'll need to adjust the negative margin-bottom on .floater based on the dimensions of your image.
.header {
background-color: teal;
height: 300px;
}
.floater {
height: 50%;
width: 100%;
margin-bottom: -10%;
}
.imgwrap {
width: 50%;
margin: 0 auto;
max-width: 400px;
}
.image {
max-width: 100%;
vertical-align: bottom;
}