I'm creating website and I have a small problem. At the end I set min-width: 1200px. When I change my internet browser to smaller resolution and scrolling horizontally, it does not affect to my menu items! How can I fix it?
#page{
width: 1200px; height:1000px;
}
#page #primaryMenu {
min-width: 1200px;
background-color: #151414;
margin: 0 auto;
padding: 0;
list-style: none;
text-align: center;
font-size: 14px;
width: 100%;
position: fixed;
z-index: 10;
box-shadow: 0 0 5px black;
}
#page #primaryMenu li {
display: inline-block;
margin: 20px 10px;
cursor: pointer;
}
#page #primaryMenu li a {
text-decoration: none;
color: white;
transition: 0.65s;
}
#page #primaryMenu li a:hover {
transition: 0.5s;
color: #d10239;
}
<div id="page">
<ul id="primaryMenu">
<li>STRONA GŁÓWNA</li>
<li>FRYZJERSTWO</li>
<li>KOSMETYKA</li>
<li>SOLARIUM</li>
<li>GALERIA</li>
<li>KONTAKT</li>
</ul>
</div>
EDIT
I don't want to do my website responsive, I want to set it with min-width 1200px; to all devices. Its menu sticks to the top and I don't want to follow vertical scroll.Example: When i change web browser resolution to 200x200 and try to scroll to the right, my menu(list items) stays in the same position.
The problem is when you are giving min-width in pixels it actually taking 1200px of the width.
If you are trying to achieve responsive design then use percentage.
Example: for #page #primarymenu use width as 100% or your desired value (in percentage). Then it will work just fine with all size screens
width:100%;
or
min-width:90%
position: fixed; on #page #primaryMenu : you are asking the browser to display your primary menu at a given x, y offset from the top left corner of the screen, scrolling or not.
Check the documentation about css position.
fixed :
Do not leave space for the element. Instead, position it at a specified position relative to the screen's viewport and don't move it when scrolled.
If I understand correctly, you want a fixed position on the vertical scroll so that the menu will be sticky to the viewport's top, and normal positioning on the horizontal scroll so the menu viewed by scrolling.
I don't think it can be done in with a css only solution, but check theses questions :
Position element fixed vertically, absolute horizontally
CSS: fixed position on x-axis but not y?
delete min-width: 1200px; and it will work fine
GOT SOLUTION IN JS: jsfiddle.net/vy8rbsv6/1
Related
I'm trying to position an icon responsively which is part of a plugin in WordPress.
Using margin-top and margin-bottom works to position the icon further down the page, but top and bottom above 10px seems to reduce the height of the icon when used in conjunction with position: relative;
#media(max-width: 768px) {
#a2a_share_save_widget-3 {
position: relative !important;
top: 20px !important;
left: 95%;
margin-left: -37px;
background-color: transparent! important;
color: transparent! important;
}
}
If I reduce top to 10px, the icon goes back to full height again.
Html:
<div id="a2a_share_save_widget- 3" class="widget widget_a2a_share_save_widget">
<div class="a2a_kit a2a_kit_size_32 addtoany_list">
<a class="a2a_dd a2a_counter addtoany_share_save addtoany_share" href="https://www.addtoany.com/share"></a>.
</div>
</div>
What I want is to apply top or bottom to adjust position, not icon height.
Mobile page here
The issue is not with regards to the share widget's height being reduced. The issue is that overflow: hidden is given to its ancestor section - the share widget is technically overflowing and parts of it are hidden.
So to solve this, either remove/override the property overflow: hidden from section
#content section {
overflow: visible;
}
or have the widget's container take X amount of minimum height
div#main {
min-height: 80px;
}
I imagine you want to increase specificity as these examples are generic terms and you are using a wordpress theme
So on a website I'm making a have a navigation bar, I use this code for it.
<div id="container">
<span>Home</span>
<span>Blackmail</span>
<span style="color: #7CFC00">Keeping Safe</span>
<span>Cyberbullying</span>
<span>About</span>
</div>
However this navigation bar is wider than the others, exact same code (Apart from the colour, the colour shows what page you are on)
I would appreciate it if someone told me why this happens or how it could get fixed!
Website - nibble90.github.io
The page with the wider navigation bar is the keeping safe page!
Your #container menu has a fixed width (83em) and a padding. When your content is longer than the page height, it causes a vertical scroll bar to appear and your fixed width elements can't adjust to accommodate it.
You should set its width to be 100% with a min-width of something like 550px and its sizing to be border-box. This will mean it fits your page much more gracefully on different sized browsers and also auto-adjust to the presence or absence of the vertical scroll bar.
So:
#container{
width:100%;
min-width:500px;
box-sizing:border-box;
}
Replace the #container code by this one and it will works. It's better to use % or px instead of em for container width.
#container {
display: block;
width: 25em;
margin: 0 auto;
padding: 10px 0px;
margin-top: 2em;
text-align: center;
background-color: #333;
width: 100%;
}
The width in your CSS is what is throwing you off. Remove the width and the divs will match in size.
#container {
display: block;
margin: 0 auto;
padding: 10px 0px;
margin-top: 2em;
text-align: center;
background-color: #333;
}
Make sure to remove both because you had width in there twice.
I have a fixed footer of 970px width, but when I resize my browser smaller the whole footer keeps going off screen with the center of the footer in the middle. I want my footer to stop going off screen when resizing the browser smaller than 970px width.
CSS
footer{
z-index: 1;
position: fixed;
width: 940px;
line-height: 30px;
background: linear-gradient(#232323, #1f1f1f);
margin: 0 auto 0 -485px;
padding: 0 30px;
bottom: 0;
left: 50%;
text-align: center;
}
HTML
<footer>Footer Text</footer>
Anybody know how I could achieve that?
You have a negative left margin of -485px and a left position of 50%. I would just use
footer {
margin: 0 auto;
}
and remove the left position altogether.
Its hard to say without any HTML, but from what I can guess you have two options:
You want to stop the footer being bigger than the browser if the browser is < 940px, if that is so why not set it to have width:100% and max-width:940px;. You may also want overflow:hidden;,
Your footer isnt centering properly, in that case wrap it within a div with width:100% (or calculated to be as wide as your page) with text-align:center; and give the footer (placed within the div) margin:0 auto;
Something like this fiddle
On http://www.posterlion.com/ the left side disappears when you make the window smaller by the browser. The horizontal scrollbar appears though but I can't get to it anymore by scrolling to the left. The content is centered through a absolute div. How do i prevent this from happening?
position:relative;left:50%;margin-left:-517px;
width:1015px; overflow:visible; background-color: #FFFFFF; padding: 10px;
The best practice to centered tour layout is using margin: 0px auto instead of absolute positioning.
In your case you should remove your absolute positioning, create some div which contain all your layout (<div id='wrapper'></div> can be standard in this case) and set its margin to auto.
By:
#wrapper {
margin: 0px auto;
width: yourWidth;
}
In your given CSS add
min-width: 1050px;
Here is Css to update :-
#lwe {
width: 1015px;
overflow: visible;
background-color: #FFFFFF;
padding: 10px;
margin: 0 auto;
}
Here's what I'd like to do: have a banner across the top of a website which stretches all across. On the left is a menu, and on the right a logo image; the menu floats left, the image floats right.
The problem is the resizing of the browser window. Because the image floats right, it correctly moves as the window gets smaller. However, at some point it begins to float into the menu. Here is a Fiddle that illustrates this effect with two floating images. Resize the browser window to see how the two images overlap.
Setting
body {
min-width: 800px;
}
I can now make sure that the scrollbar appears as the browser window reaches a certain minimum width. However, that doesn't hinder the right-floating image to keep moving as the browser window keeps getting smaller. I tried to change position: relative but that didn't work. I tried to use Javascript to fixate the images once the browser window reaches its min-width but that didn't seem to have an impact either. Using min-width on the DIV and making the images children of the DIV didn't work either.
My question is: how can I make sure that, starting at a certain window size, the right-floating image stays put instead of floating into the left-floating menu?
EDIT: Oh dear, I forgot to mention a rather important detail: the menu bar at the top needs to be sticky. That is why I used the position: fixed property for the DIV. The other page content is supposed to scroll under that menu and out of the window, see the modified fiddle here which is based on ntgCleaner's answer. This kind-of changes the whole thing, doesn't it! Sorry about that...
Thanks!
A couple things I changed:
I made your banner DIV a container instead of just a free floating div. Probably not necessary.
I gave that banner div a min-width:280px and made it overflow:hidden;
I made the images just float left and right, not positioned relatively or absolute (since it's in the div container now).
#banner {
left: 0px;
top: 0px;
width: 100%;
height: 60px;
background-color: lightblue;
z-index: 1;
opacity: 0.8;
overflow:hidden;
min-width:280px;
}
#left {
float:left;
margin:5px;
height:40px;
}
#right {
float:right;
margin:5px;
height:40px;
}
Here's the fiddle
EDITED FOR THE EDITED QUESTION:
You will just need to place all of your content under your header into a div, then give that div a top margin of the height of your fixed div. In this caes, it's 60px.
Add this to your HTML
<div id="content">
this <br>
is <br>
some <br>
test <br>
text <br>
</div>
then add this to your CSS
#content {
margin:60px 0px 0px 0px;
}
Here's the new fiddle
Is this what you are after? http://jsfiddle.net/9wNEx/10/
You are not using the position: fixed correctly. Fixed means 'positioned relative to the viewport or browser window', and that is exactly what you are experiencing.
I removed the position: fixed from the images, and placed them inside the div. This should keep them always on top of the page, as they are inside the div that is still positioned fixed.
Also I tweaked some of the other styling to replicate your example. Note that i removed the fixed height of the head and replaced it by a padding bottom. This way the height will follow the content whenever the screen size becomes to small and the images are forced underneath each other.
The css looks like this now:
#banner {
left: 0px;
top: 0px;
width: 100%;
padding-bottom: 15px;
background-color: lightblue;
z-index: 1;
position: fixed;
opacity: 0.8;
}
#left {
float: left;
margin-left: 10px;
margin-top: 5px;
height: 40px;
}
#right {
float: right;
margin-right: 10px;
margin-top: 5px;
height: 40px;
}
I changed your HTML to put the <img> tags inside the banner, and added the min-width to the #banner since it has position: fixed. You'll still need to add min-width to the body or a container that wraps all other elements if you want there to be a min-width of the entire page.
http://jsfiddle.net/Wexcode/s8bQL/
<div id="banner">
<img id="left" src="http://www.google.com/images/srpr/logo3w.png" />
<img id="right" src="http://www.google.com/images/srpr/logo3w.png" />
</div>
#banner {
width: 100%;
min-width: 800px;
height: 60px;
background-color: lightblue;
z-index: 1;
position: fixed;
opacity: 0.8; }
#left {
float: left;
margin: 5px 0 0 10px;
height: 40px; }
#right {
float: right;
margin: 5px 10px 0 0;
height: 40px; }
When I look at your Fiddle I think your problem isn't the floats at all. position:fixed supersedes float. Those two elements aren't floating at all, they're in a fixed position (similar to an absolute position), which is why they overlap when they don't have enough room.
Take out float:left and float:right, the result will be the same. Also, top, left, bottom, and right don't work on non-positioned elements. So they are superfluous on your banner.
If you use floats, however, when there is not enough room the right image will wrap underneath the left. See http://codepen.io/morewry/pen/rjCGd. Assuming the heights on the images were set for jsfiddle testing only, all you need is:
.banner {
padding: 5px; /* don't repeat padding unnecessarily */
min-width: ??; /* to keep floats from wrapping, set one */
overflow: hidden; /* clearfix */
}
.right { float: right; } /* only need one float, don't over-complicate it with two */