I have a header with a logo floating left and a phone number floating right. When the screen is not wide enough for both, the phone number jumps underneath the logo, which is not what I want.
Since most of the logo image is just background gradient anyway, I'd like to position the phone number on top of the logo element, when the screen is narrower than 818px.
How might I do that?
Here's the basic code:
<div id="head-wrap">
<a class="home-link" href="http://example.com">
<img src="logo.png" class="logo">
</a>
<div class="tel">
<a href="tel:555555555" class="phone">
<p class="phone">
<img src="phone-icon.png">555 555 555
</p>
</a>
</div>
</div>
.home-link {
float:left;
}
.tel {
float: right;
}
.logo {
width: 657px;
}
First of all you can solve part of your problem by putting div.tel before your logo. This way it will be displayed on top of the logo if you don't have enough space. Then you could use a media query to put phone number on the left for example like this:
#media screen and (max-width: 818px) {
.tel {
float: left;
}
}
Fiddle: https://jsfiddle.net/s2Lubqqp/1/
Since you need to overlap phone on logo you need to keep their position absolute and same position
also since you have set width of logo to width: 657px; better to make it auto when you resize window... hope it works for you
here is the media query :)
#media screen and (max-width: 818px) {
.tel {
width:auto;
position:absolute;
left:5px;
top:5px;
}
.logo {
width: auto;
position:absolute;
left:5px;
top:5px;
}
}
You could try something like that :
.home-link {
float:left;
}
.tel {
float: right;
}
.logo {
width: 657px;
}
#media only screen and (max-width: 818px) {
.home-link {
width: 30%;
max-width: 300px;
}
.logo {
width: 100%;
}
}
This way you can change the percentage width of the home-link section, and force the logo to fit it with the "width: 100%;"
The fiddle is here
Related
I am new at HTML and CSS and I want to make a responsive header that contains:
logo picture with margin-left in pixels when full resolution
pogo picture must have it's full size when full resolution
navigation menu with 6 and width of 1500 when full resolution
No Bootstrap. What are your suggestion to accomplish that? What I have made so far is not responsive, on full size (width:1920px) measures are fine and it looks exactly how it should, but when I try to resize browser it is not in one row, even if I declare that div "inner" that contains them is width:100%, and both of them are also width:100%.
Code is something like this:
.inner{
width:100%;
}
.navigation {
display: inline-block;
float: right;
text-align: center;
padding-top:47px;
padding-bottom:27px;
max-width:1555px;
width:100%;
}
.navigation li{
display: inline-block;
width: 16%;
}
.navigation ul{
max-width: 1500px;
}
.wrapper-logo{
display: inline-block;
max-width:365px;
width:100%;
}
.small-logo{
max-width: 143px;
width:100%;
padding-left:220px;
}
<div class="inner">
<div class="logo-wrapper">
<div class="small-logo">
<img src="https://99designs-start-attachments.imgix.net/alchemy-pictures/2016%2F02%2F22%2F04%2F24%2F31%2Fb7bd820a-ecc0-4170-8f4e-3db2e73b0f4a%2F550250_artsigma.png?auto=format&ch=Width%2CDPR&w=250&h=250">
</div>
</div>
<div class="navigation">
<ul><li>......</li></ul>
</div>
</div>
Use media queries.
Here goes my Desktop resolution css
#media only screen and (max-width: 600px) {
/* Here goes my Mobile resolution css */
body {
background-color: lightblue;
}
}
You'll want something like the following for bullet 1
.small-logo {
margin-left: 10%;
}
#media only screen and (max-width: 600px) {
.small-logo {
margin-left: 0;
}
}
Bullet 2 I'm guessing should say Logo not Pogo. Based on the code provided .small-logo is your only logo so you'd do something like this.
.small-logo{
width: 100%
}
What does the navigation menu have 6 of? Columns? Buttons? Unicorns?
Set the inner class or preferably an id of the largest content div to the max I generally like to center the content and give some side white space so I put the basics in the comments.
.inner{
max-width: 1500px;
width: 100%;
/*width: 85%;
margin: auto 0;*/
}
Are you trying to have logo-wrapper and navigation horizontally aligned?
display: inline-block;
I have 3 div side by side, my problem is that they don't appear as I intended on a mobile phone. The page looks like it should be on a laptop/wide screen.
Here is the page:
http://dennissøderkvist.dk/?page_id=35
So you see there is the div with a contact formular, a div with the google map, and a div with address info. If you open it on a mobile phone, it looks horrible, the last div at the end jumps down. How can I solve this?
Here is my css:
#conHolderDiv
{
float: left;
width: 35%;
}
#mapHolderDiv
{
float: left;
width:40%;
padding-left: 15px;
}
#adrDiv
{
float: right;
width: 20%;
}
The conHolderDiv is the first div, that holds the contactform. The mapHolderDiv is the div that holds the map, and the adrDiv holds the address
As previously mentioned, you could use Bootstrap. Or learn about responsive design.
For your example, with the three column layout you are on about you can use Media Queries to target divs that meet certain screen sizes.
#media only screen and (max-width:1000px) {
#conHolderDiv, #mapHolderDiv, #adrDiv {
float:none;
width:100%
}
}
This will give you a 1x3 layout, rather than 3x3. We are not floating the elements, and assigning a width that takes up 100% of the space.
or you can always use display:table
<div style="display:table; width:100%;">
<div style="display:table-row">
<div id="conHolderDiv"></div>
<div id="mapHolderDiv"></div>
<div id="adrDiv"></div>
</div>
</div>
and the css will be
#conHolderDiv {
display:table-cell;
width: 35%;
}
#mapHolderDiv {
display:table-cell;
width:40%;
padding-left: 15px;
}
#adrDiv {
display:table-cell;
width: 20%;
}
The header of my site is some text and a logo. The font used isnt standard so the text is image based.
I want the elements of the site to change with the size of the browser window. I believe this is called fluid design?
So I want the text and logo in the header to scale and be evenly spaced horizontally. There are 5 letters, then the logo, then 5 more letters. One more curveball, I want the logo to be dead center of the page at all times.
I've looked around and it seems there are multiple ways out there to do this. And all have their own caveats based on ever evolving functionality of html and css, I'm guessing more css than html.
So what would be the best way to do this as of June 8 2014? =P Obviously I want it to work in as many browsers as possible.
There are basically two ways to change your content depending on the screen size:
1. Use percents
If you have some elements which should change their size whenever the user changes the screensize, I would recommend using percents.
.content {
width: 90%;
height: 50%;
}
In this example the class .content will have always a height of 50% and a width of 90% - it will change its pixel-size whenever the user changes the screensize. You can create a very flexible layout with that.
2. #media-querys
If you want to change something more than sizes, you have a static layout or want to create something like a mobile version, css has a #media-query:
#media (min-width: 600px) and (max-width: 1000px) {
.content {
background-color: red;
}
}
If the screen-width is between 600px and 1000px the background-color of .content will change to red. Just put the changes you want the header to do into a #media-query like this and it will work perfectly.
You'll find a very good noob-tutorial for #media-queries at css-tricks.com
Okay I hope this is what you meant with your description of having your logo/type in center of page. Here's the jsfiddle I made for the solution.
here's the code
HTML:
<header>
<div id="wrap">
<div id="container">
<div id="logo"><img src="http://mattfrey.ca/img/springfarm/sf-preview2.jpg" alt="sample image"></div>
<div id="fiveLets">F I V E R</div>
<div class="clearFix"></div>
</div>
</div>
</header>
CSS
header { width:100%; padding:0; margin:0; }
img { height: auto; max-width: 100%; padding: 0;}
#wrap { width:80%; margin:0 auto; outline: solid 1px red; background-color:#ccc;}
#container { margin: 0 auto; width:50%; background-color:#fff; outline: solid 1px blue;}
#logo { width:49%;}
#logo img { background-color: blue; float: left; }
#fiveLets { font-size: 2em; margin-top: 1.35em; float: right; margin-left: 1%; width:49%; }
.clearFix {clear:both}
/*responsive changes*/
#media screen and (max-width: 600px) {
#fiveLets { font-size: 1em; } /*shrink text*/
#wrap { background-color: #666; }
}
}
#media screen and (max-width: 300px) { /*doesn't seem to respond--jsfiddle*/
#fiveLets { font-size: 0.75em; }
#wrap { background-color: #333; }
}
}
1) You have your header, logo and type.
2) the #container brings both elements (logo and type, both of which are floated) closer together, and is also centered to solve that issue.
3) when you adjust the browser width, the css for the #logo img will adjust automatically, but the type, you need to add some responsive css, using media queries.
The jsfiddle doesn't seem to shrink down to 300px, so you will have to test in your own browser.
Hope this helps!
I have a div stretching the height of my page, with float left, eg:
#leftvignette {
width: 200px;
height: 100%;
float: left;
}
#sitecontent {
margin: auto;
width: 1000px;
}
HTML:
<div id="leftvignette"></div>
<div id="sitecontent">
all other content here
</div>
I want this div to always sit at the left of my content until the window is less then 1000px wide - I dont want the #leftvignette to intrude and cover my content.
Does anyone know a way to do this?
Use CSS Media queries and the CSS clear property to remove the float:
#media all and (max-width: 1000px) {
#leftvignette {
clear:both;
}
}
Anything below 1000px will then have the float: left removed.
#leftvignette {
width: 200px;
height: 100px;
float: left;
background:#000;
}
#sitecontent {
margin: auto;
width: 1000px;
background:#f00;
height:200px;
float:left;
}
.clear{clear:both;}
<div id="leftvignette"></div>
<div id="sitecontent">
all other content here
</div>
<div class="clear">
<!--this will help in clearing float for next comming elements.-->
</div>
I suggest you to create some util classes like for example .clear and use them whenever you need just applying the in html as class.
CSS:
.clear{
clear:both;
}
HTML
<div id="leftvignette" class="clear"></div>
Remember to use it after float; it will clear both sides of your div so no element will be placed to the left and right of your "Box".
In your case is better if you use media queries, like that:
#media screen and (max-width:1000px){
#leftvignette{
clear:both;
}
}
<div class="main">
<div class="cleft">
</div>
<div class="cright">
</div>
</div>
.cleft{
float: left;
padding-left: 1%;
width: 68%;
}
.cright{
float: right;
padding-right: 1%;
width: 28%;
}
I have two box left and right. I want a thing that I want to put left and right box width:100% when someone resize the width and width are less then the main-container (1075px in my case).
How I can make 100% width of left and right and right will shown on bottom.
note: I have made some changes for ipad,iphone and they work fine in that case. but How I can applied for that thing when someone resize the browser.
I think you want to use media queries:
http://css-tricks.com/css-media-queries/
#media screen and (max-width: 1075px) {
.cleft, .cright {
float:none;
width:50%;
padding:none;
}
}