Layout breaks on browser resize - html

Got a weird problem,i.e,Layout of webpage breaks on resize of the browser/when accessed through mobile device/when switched to lower resolution ( 800*600 / 1024*768 )
Temporary link : http://krishnaspirit.hostoi.com/
P.S : Its a full-width website & Works fine on 1366*768.
CSS :
* { padding:0px; margin:0px; }
p,h1,h2,h3,h4,h5,h6,a{ font-family: 'Armata', sans-serif; }
/*header*/
.header { z-index:5000; position:fixed; top:0px; width:100%; min-width:960px; height:100px; background-color:#4E4E56;}
.header #nav li:last-child { margin-right:0px; }
.header #nav li { transition:1s ease all;line-height:40px;
display:inline-block; margin-right:3px; width:116px; height:40px;text-align:center; border-radius:5px;}
.header #nav li a { font-size:15px; color:#DCD0C0; display:block; height:100%; text-decoration:none; }
.header #nav li:hover { background-color: #DA635D; }
.header #nav li a:hover { color:#fff; }
.header #nav { position:absolute; right:10px; top:35px; width:600px; }
.current {background-color: #DA635D; cursor:none;}
.header #nav .current a { color:#fff; }
.header .logo img {width:100px; height:95px; position:absolute; top:5px; left:12px; line-height:100px; font-size:40px; color:#fff;}
.header .logo .name { font-size:40px; color:#ccc;
font-family: 'Armata', sans-serif; position:absolute; left:110px;top:29px; }
/*sub-head*/
.sub-header .top-logo { float:left; }
.sub-header .top-name { float:right; font-size:30px; padding-top:120px; color:#003366; }
.sub-header { width:85%; text-align:center; margin:150px auto; }
/*main-body*/
.content { float:left; }
.news { float:right; margin-right:5px; }
.news { box-shadow:3px 3px 5px #ccc; padding:0px; border-radius:3px; }
.news p { font-weight:bold; font-size:15px; padding-bottom:20px;}
.news { border:1px solid #ccc; width:27%; min-width:27%; padding:5px; height:300px;}
.news .news_body { padding:3px; text-align:center;}
.content { box-shadow:3px 3px 5px 0px #ccc; width:70%; height:300px; border-radius:3px; margin-left:5px; border:1px solid #ccc; font-size:15px; padding:5px;}
.content .sub-main { margin-top:15px; text-align:justify; padding:10px; }
.content #myMenu { width:100%; text-align:center; height:30px; }
.content #myMenu{ list-style-type:none; }
.content #myMenu li { border-bottom:1px solid #ccc; color:#999; display:inline-block; width:30%; line-height:30px;}
.content #myMenu li:hover { font-weight:bold; }
.content #myMenu li a { display:block; width:100%; }
.content #myMenu li a:hover { border-bottom:5px solid #DA635D; color:#DA635D; cursor:pointer;}
.body_wrapper { margin-bottom:500px; margin-top:70px; background-color:#ccc; }
/*footer*/
footer { width:100%; height:50px; line-height:50px; background-color:#4E4E56; }
footer p a{ color:#DA635D; text-decoration:none; font-weight:bold;}

This is not a weird problem. You need to use #media query to fix the problem.
The image on left side is large enough to occupy almost half of total screen width at a resolution 1024x768. You need to define style sheet on different screens using media query.
Example -
#media screen and (max-width: 1024px){
.main .sub-header .top-logo{
width: 250px;
}
.main .sub-header .top-logo img{
width: 100%;
}
}
This snippet will only take action in device screen width less than or equal to 1024px.
As you can see, for this type of device resolution I have reduced the width of .top-logo to make sure it can fit properly in small screen. You need to define .top-name and other elements accordingly to fit them properly for different device width. Hope you get the idea.

Another thing causing this problem is when one #media query has a missing closing brace }.
For example if your CSS has something like:
nav {
position: relative;
width: 95%;
margin: 10px auto 0 auto;
height: auto;
background-color: var(--magnolia);
font-family: Roboto;
}
#media screen and (min-width: 860px) {
nav {
margin: 0 auto;
}
<----------------- /* A closing brace "}" is missing here ! */
.navbar {
display: flex;
list-style-type: none;
flex-flow: row wrap;
justify-content: space-between;
align-content: center;
align-items: center;
margin: 0 auto;
padding: 0;
height: auto;
}
etc.
etc.
This makes all CSS below it revert to default, e.g. width: 100%.
Overflow abounds in such a situation.
Since W3C CSS Validator may not detect this, you have to closely read through all #media queries before the breaking elements looking for missing closing braces. Just one of these can screw up everything below that part of the web page. Fix it and everything is suddenly fine.

Related

Style messing up when screen size is reduced

Please take a look at my practice site - http://codepen.io/silentarrowz/pen/rLJABR
I am having few problems with it:
At reduced screen size the eElectronics and cart at the top are not centered but appear at one side of the screen. I'd like it to be centered for small screen sizes. I am able to center the eElectronics logo but unable to center the cart div, even though I am using media queries.
The navigation bar overflows for small screen sizes and the links at the end such as OTHERS & CONTACT flow on to the next row. How do I fix this?
The carousel caption moves off the screen for reduced size. How do I fix this?
Please offer your suggestions and advice.
.navcolor{
background-color:#1abc9c;
}
.logo a{
padding-bottom:10px;
color:#999;
}
.logo a span{
color:#1abc9c;
}
.cart {
border:1px solid rgb(221,221,221);
font-family:"Titillium Web";
font-size:18px;
width:140px;
height:50px;
padding-top:10px;
padding-left:10px;
}
.cart a{
color:#666;
}
.cart a span{
color:#1abc9c;
font-weight:bold;
}
.cart:hover {
background-color : #1abc9c;
}
.cart:hover span, .cart:hover a{
color:white;
}
.no-underline :hover{
text-decoration:none;
}
.navbar-default .navbar-menu{
height:50px;
}
.navbar-default .navbar-menu li > a{
color:white;
font-weight:bold;
font-size:14px;
}
.navbar-default .navbar-menu > .active > a {
background-color:#333;
color:white;
}
.navbar-default .navbar-menu > .active > a:hover {
background-color:#333;
color:white;
}
.navbar-default .navbar-menu li>a:hover{
background-color:#333;
color:white;
}
#carousel1 img{
width:100%;
height:70%;
}
.logo{
font-family:"Titillium Web";
font-size:40px;
}
.cart{
font-size:18px;
}
.carouse-inner{
position:relative;
}
.carousel-caption{
background-color:rgba(0,0,0,0.5);
color:white;
display:block;
width:600px;
padding-left:20px;
text-align:left;
position:absolute;
left:600px;
bottom:150px;
}
.latest img{
border:1px solid grey;
}
.details p{
height:150px;
display:block;
border:1px solid #17a78b;
margin-top:30px;
margin-bottom:30px;
padding-top:10px;
padding-bottom:10px;
font-size: 30px;
font-weight:200;
color:#fff;
text-align:center;
}
.details p:hover{
background-color:black;
}
.details p>i{
font-size:50px;
font-weight:500;
}
.details{
background-color:rgb(26,188,156);
}
.latest{
text-align:center;
}
#media (max-width: 300px) {
.logo{
text-align:center;
}
.cart{
width:100%;
text-align: center;
}
}
#media (min-width: 501px) {
.logo {
float: left;
}
.cart {
float:right;
}
}
Problem 2: Your OTHER & CONTACT menu buttons go on the next row because your navbar is in a div.container with a width of 750px for resolutions under 768px, and there is no place for themin the same row.
#media (min-width: 768px){
.container {
width: 750px;
}
}
You could give it another class, with different width, since you have the .container class assigned to more divs, and make it wider.
You could also give a min-height of 330px to your .navbar-colapse.in class to make the collapsed menu higher when resolution is under 768px:
#media (min-width: 768px){
.navbar-collapse.in {
overflow-y: auto;
min-height: 330px;
}
}
Problem 3: As Steve said, change your .carousel-caption style, giving width in percents (100%) and margins set to auto.
.carousel-caption {
width: 100%;
left: auto;
right: auto;
}
If you are trying to center divs with text-align that's not the way to go. You need to set up margin on right and left to auto:
#media (max-width: 300px) {
.logo{
text-align: center;
margin: 0 auto;
}
.cart{
width:100%;
margin: 0 auto;
}
}
The thing is your eElectronics is not taking all the space of the div, center div with margin auto on sides and text-align center inside the div.
For the menu in collapse mode, i get a scroll bar and everything is fine except it is a little small. Override with overflow: visible; and set z-index if it overlaps under other items.
.navbar-collapse.in {
overflow-y: visible;
}
The carousel captions are fine for me on Firefox. You just need to set a width in % and set margins on each side to auto. That div needs to be adaptative. Right now it stay at a size of 600px set in .carousel-caption.

CSS: Four Column Div Layout Shrinks to Stacked Two Column Div [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have a four-column div layout.
When viewing the page on mobile, I want the layout to shrink to a two-column div.
JsFiddle
CSS:
.style1 {
font-style:normal;
font-weight:bold;
color:#FFFFFF;
}
#footer {
clear:both;
float:left;
width:100%;
}
#footer p {
margin-left:2%;
padding-right:2%;
}
/* Start of Column CSS */
.container1 {
float:left;
width:100%;
position:relative;
}
#col1 {
float:left;
width:23%;
min-height:268px;
position:relative;
margin-right:10px;
/*left:77%;*/
padding:10px;
overflow:hidden;
background-color:#DDDDDD
}
#col2 {
float:left;
width:23%;
min-height:268px;
position:relative;
margin-right:10px;
/*left:81%;*/
padding:10px;
overflow:hidden;
background-color:#DDDDDD
}
#col3 {
float:left;
width:23%;
min-height:268px;
position:relative;
margin-right:10px;
/*left:85%;*/
padding:10px;
overflow:hidden;
background-color:#DDDDDD;
}
#col4 {
float:left;
width:23%;
min-height:268px;
position:relative;
/*margin-right:10px;
left:89%;*/
padding:10px;
overflow:hidden;
margin-bottom:15px;
background-color:#DDDDDD
}
#year_banner {
width:auto;
margin:0px 10px 0px 10px;
align-self:center;
background-color:#E60000;
text-align:center;
}
img.displayed {
margin:0 auto;
display:block;
max-width:100%;
height:auto;
}
Any help is appreciated! Many thanks!
You have quite a lot of repeating code. You can eliminate that by using classes; this will also make it much easier to change all of the columns at once when the screen changes size.
For example:
.col{
float:left;
width:23%;
min-height:268px;
position:relative;
margin-right:10px;
padding:10px;
overflow:hidden;
background-color:#DDDDDD
}
#media screen and (max-width:380px){
.col{
width:50%;
}
}
I have prepared a simple example: https://jsfiddle.net/rey9xc1h/
body {
margin: 0;
}
.row {
width: 100%;
min-width: 320px;
margin: 0;
}
.col {
box-sizing: border-box;
background-color: #fff;
float: left;
padding: 10px;
margin: 5px 1%;
width: 98%;
}
#media (min-width: 320px) {
.row {
overflow: hidden; /* Clearfix */
}
.col {
width: 48%;
float: left;
}
}
#media (min-width: 768px) {
.col {
width: 23%;
}
}

How do I align the NAV to the right side of the page?

I am having an issue with my header on my website.
When I try to float the logo to the left, and float the nav to the right at the same time, it pushes all the content down and the 'header' joins the 'section' tag.
This is the JSFiddle if you would like to play around with it, any help would be greatly appreciated. Thank you.
https://jsfiddle.net/wh7wdpmu/
#logo {
width: 125px;
margin-top: 10px;
display: inline-block;
}
nav {
display: inline-block;
}
(Above is the CSS for the logo and nav so far)
I assume you want the logo to the far left and the menu to the far right?
If so you can try this: Demo
I added the floats left and right for the logo and nav respectively. I then added width: 100% to your header as well as an inline-block display property. Remove the excessive img margin to the logo (or add it to the header instead).
body {
background-image:url("http://i300.photobucket.com/albums/nn18/ojijimanuel/LONDONWALLPAPERBLUR_zpstm3nxnwu.jpg");
background-size:cover;
background-repeat:no-repeat;
background-position:center center;
background-attachment:fixed;
margin-left:100px;
margin-right:100px;
}
#logo {
width:125px;
display:inline-block;
float: left;
}
header {
display: inline-block;
width: 100%;
font-size: 0;
}
section h1 {
color:white;
font-family:arial;
font-weight:bold;
font-size:50px;
}
section {
text-align:center;
margin-top:300px;
}
#learnmore {
border:none;
background-color:#191919;
padding-left:30px;
padding-right:30px;
padding-top:15px;
padding-bottom:15px;
color:white;
float:left;
opacity:0.5;
margin-top:100px;
}
#learnmore:hover {
opacity:1.0;
cursor:pointer;
}
#learnmore a {
text-decoration:none;
color:white;
}
p {
color:white;
font-family:arial;
}
nav {
display:inline-block;
float: right;
}
nav a {
text-decoration:none;
color:#cccccc;
font-family:arial;
padding-right:20px;
font-size:15px;
}
nav a:hover {
color:white;
}
Also, you have an extra <nav> tag in your HTML.
You need to clear the float on your header. Try applying overflow: hidden; on your header.
Updated fiddle
(You also had an extra nav tag in there)

Fixed position navigation bar width and overlap issue

Hello fellow community members,
I am currently having a problem where I have set my top navigation bar to be fixed so that it follows users as they scroll down my web page but I am currently faced with two issues.
The content of my site is overlapping my navigation bar and goes ontop of it making it look messy and not function as designed. (The background is not transparent but rather a solid image)
The website is fluid and I have been fiddling with this for hours now trying to get it to work but as I set a min-width and max-width it doesn't seem to obey the min-width and width as a percentage (100% of the container). Sorry if I am a little unclear in explaining this but I have attached some code in jsfiddle for people to see.
If you would like to see where I am stuck at right now you can do so at subnovaled.com (the blue bar along the top) also the jsfiddle link is as follows:
#navMainWrapper {
height: 32px;
font-size: 12px;
position: fixed;
min-width: 1000px;
max-width: 1280px;
width: 100%;
background: cyan;
}
http://jsfiddle.net/jXJMx/23/
Note: the above code was done in a rush, sorry
Thank you to anyone who is able to help me out!!
check this fiddle:
http://jsfiddle.net/jXJMx/26/
CSS:
#navMainWrapper {
height: 32px;
font-size: 12px;
position: fixed;
min-width: 750px;
max-width: 1280px;
width: 100%;
background: cyan;
}
#navMainSearch {
float:left;
width:120px;
}
#navMain {
float:left;
width:750px;
line-height:normal;
height:32px;
}
#navMain ul {
float:right;
list-style:none;
}
#navMain li {
display:inline;
}
#navMain a {
float:left;
text-decoration:none;
}
#navMain a span {
float:left;
display:block;
padding: 7px 15px 0 15px;
text-align:center;
width:90px;
cursor:pointer;
height:25px;
}
/* Commented Backslash Hack hides rule from IE5-Mac \*/
#navMain a span {
float:none;
}
/* End IE5-Mac hack */
#navMain a:hover {
background-position:0% -32px;
}
#navMain a:hover span {
background-position:100% -32px;
}
#content {
background:yellow;
min-width:750px;
width:100%;
height:768px;
position:relative;
margin-top:32px;
}
Update CSS as show
#navMainWrapper {
height: 32px;
font-size: 12px;
position: fixed;
min-width: 1000px;
max-width: 1280px;
width: 100%;
background: cyan;
}
#navMainSearch {
float:left;
width:120px;
}
#navMain {
float:left;
line-height:normal;
height:32px;
}
#navMain ul {
list-style:none;
}
#navMain li {
display:inline;
}
#navMain a {
float:left;
text-decoration:none;
}
#navMain a span {
float:left;
display:block;
padding: 7px 15px 0 15px;
text-align:center;
/*width:90px;*/
cursor:pointer;
height:25px;
}
/* Commented Backslash Hack hides rule from IE5-Mac \*/
#navMain a span {
float:none;
}
/* End IE5-Mac hack */
#navMain a:hover {
/* background-position:0% -32px;*/
}
#navMain a:hover span {
/* background-position:100% -32px;*/
}
#content {
background:yellow;
width:100%;
float:left;
height:1500px;
}

Is there a way to get a fixed width of 100% in CSS?

I am trying to make my site more scalable, and would like all of my divs to take up the whole width of the page. If not, I would like them all to be centered and 960px. The problem is that none of the divs are actually centered when I try margin-left:auto, margin-right:auto;. When I try to make the width 100%, and then try to resize the window, everything gets wacky.
Here is the site:
http://eitanrosenberg.com/newsite/index.html
Here is my CSS:
*
{
margin:0;
padding:0;
}
.everythang
{
margin-left:auto;
margin-right:auto;
}
.topbar
{
background-color:#000;
height:75px;
margin-left:auto;
margin-right:auto;
position:fixed;
width:100%;
z-index:10;
}
.logo
{
color:#FFF;
float:left;
font-family:HarabaraRegular,helvetica;
font-size:45px;
margin:15px auto 0 20px;
padding-left:100px;
position:relative;
width:160px;
}
.navbar ul
{
color:#FFF;
display:inline;
float:right;
list-style-type:none;
margin-right:25px;
margin-top:15px;
text-decoration:none;
}
.navbar ul li
{
display:block;
float:left;
margin:15px auto 0 5px;
padding-right:32px;
}
.navbar ul li a
{
color:#FFF;
font-family:HitchcockRegular, helvetica;
font-size:25px;
text-decoration:none;
}
.navbar ul li a:hover
{
color:#0CF;
}
.white
{
background-color:#F8F8F8;
background-image:url(gradients/radialg_200.png);
background-position:30% 0;
background-repeat:no-repeat;
height:300px;
margin:0;
padding:50px 0 0;
width:960px;
}
.hello
{
color:red;
font-family:CoolveticaRegular, helvetica;
font-size:50px;
margin-left:auto;
margin-right:auto;
padding-top:50px;
text-align:center;
}
.hello2
{
color:red;
font-family:CoolveticaRegular, helvetica;
font-size:35px;
margin-left:auto;
margin-right:auto;
padding-top:10px;
text-align:center;
}
.hello3
{
color:#0CF;
font-family:CoolveticaRegular, helvetica;
font-size:35px;
margin-left:auto;
margin-right:auto;
padding-top:10px;
text-align:center;
}
.orange
{
background-color:#F93;
background-image:url(gradients/radialg_400.png);
background-position:30% 0;
background-repeat:no-repeat;
height:500px;
margin:0;
padding:50px 0 0;
width:960px;
}
.workbar ul
{
color:#FFF;
float:left;
line-height:25px;
list-style-type:none;
margin-left:100px;
margin-right:25px;
margin-top:100px;
text-decoration:none;
}
.workbar ul li
{
margin:2px auto 0 35px;
padding-right:32px;
}
.workbar ul li a
{
color:#FFF;
font-family:helvetica;
font-size:25px;
font-style:bold;
text-decoration:none;
}
.workbar ul li a:hover
{
color:red;
}
.red
{
background-color:red;
background-image:url(gradients/radialg_400.png);
background-position:30% 0;
background-repeat:no-repeat;
height:500px;
margin:0;
padding:50px 0 0;
position:static;
width:960px;
}
.red h2
{
color:#FFF;
font-family:Helvetica;
font-size:45px;
margin-left:100px;
padding-top:40px;
}
.red ul
{
color:#FFF;
float:left;
list-style-type:none;
margin-left:100px;
margin-right:25px;
margin-top:15px;
text-decoration:none;
}
.red ul li a
{
color:#FFF;
font-family:helvetica;
font-size:20px;
font-style:bold;
text-decoration:none;
}
.faves img
{
display:inline;
float:left;
height:50px;
padding-top:15px;
position:relative;
width:50px;
}
.faves
{
padding-top:25px;
}
.faves h2
{
display:inline;
float:left;
margin-top:25px;
padding-top:15px;
}
.lists
{
margin-top:100px;
}
.list1
{
float:left;
width:320px;
}
.list2
{
float:left;
width:320px;
}
.list3
{
width:320px;
}
.gray
{
background-color:#2e3031;
background-image:url(gradients/radialg_400.png);
background-position:30% 0;
background-repeat:no-repeat;
height:700px;
margin:0;
padding:50px 0 0;
position:static;
width:960px;
}
.gray h2
{
color:#FFF;
font-family:Helvetica;
font-size:45px;
margin-left:100px;
padding-top:40px;
}
.resumeImg img
{
display:block;
height:550px;
margin-left:auto;
margin-right:auto;
width:900px;
}
Making an element centered using margin requires the element to have a layout. When using margin-left and margin-right, that would be the width property.
An alternate way to center your elements is :
position: absolute;
width: 800px;
left: 50%;
margin-left: -400px;
You would move the element 50% from the left and then 400px (half the width) back. This also works for heights.
Have your wrapper divs ('white', 'orange', etc) be set to width: 100%; and have your content inside (preferably in another div, set to width: 960px; margin: 0 auto;:
.white, .orange {
width: 100%;
}
.white-wrapper {
width: 960px;
margin: 0 auto;
}
And use the following HTML:
<div class="white">
<div class="white-wrapper">
-- content --
</div>
</div>
In this way, your backgrounds will appropriately fill the page, and your content will float in the center and work correctly when shrinking the page. I'd recommend against dynamically changing the width of your content, as it presents readability issues (and tends to look gross), but if you really want to, try min-width:
.white {
min-width: 960px;
}
This will ensure that your divs are always at least 960px wide;
If I understand your question correctly, you want a fixed centered layout that is 960px wide UNLESS the browser window is less than 960px, then you want the layout to be full width.
To do this, wrap your entire html code in a container, like so:
<body>
<div id="container">
<!-- your code here -->
</div>
</body>
And apply this css:
#container {margin:0 auto;max-width:960px;}
Internet Explorer 6 doesn't understand max-width, so if that's a concern you could either give IE6 a fixed width of 960px:
#container {margin:0 auto;max-width:960px;}
* html #container {width:960px;} /* IE6 hack */
or force max-width in IE6 with an even uglier hack:
* html #container {width: expression(document.body.clientWidth > 962? "960px");