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%;
}
}
Related
I am using this CSS for a really simple image gallery:
.product_container {
width:100%;
display:block;
}
.product_images {
width:45%;
display:inline-block;
border:1px solid black;
}
.product_images .large {
}
.product_images .small img {
display:inline;
float:left;
margin:5px;
width:151px;
}
i want to have a large image and then rows of 3 under that image, i created an example in a fiddle here
https://jsfiddle.net/jdd9hzqo/
when the page is resized, the small images are moving but i want them to stay in rows of 3 and resize themselves but keeping to the same size as the .product_container
Fiddle:https://jsfiddle.net/jdd9hzqo/2/
Changes to be made:
.product_images {
width:100%;
display:inline-block;
border:1px solid black;
}
.product_images .large img {
width:100%;
}
.product_images .small img {
display: inline;
float: left;
width: 33%;
box-sizing: border-box;
}
https://jsfiddle.net/jdd9hzqo/1/
Remove float:left; in .product_images .small img {
And add:
.small {
white-space: nowrap;
}
For the resize add something like width: 30%; in .product_images .small img {
I found what im looking for ALMOST, (http://codepen.io/anon/pen/PqxQVN).
But the only problem is i need the container to have height of auto and the sidebar to have a height of 100%. When i do that the sidebar disappears.
#container { height:500px; width:100% }
.sidebar { background:red; float:right; height:100%; width:20% }
.content { background:green; height: 100px; width:80%; float:left; margin-top: 20px;}
#media screen and (max-width: 1000px) {
.sidebar { clear:both; width:100% }
.content { width:100%; }
}
Any help would be appreciated. :)
I have used the universal selector (*) to remove padding and margin, therefore the sidebar will be 100% of height.
For what concerns the green container, by simply removing the height from 100px to "auto" it will automatically fill the content.
Link to codepen
*{
margin: 0;
padding: 0;
}
#container { height:500px; width:100% }
.sidebar { background:red; float:right; height:100%; width:20% }
.content { background:green; height: auto; width:80%; float:left; margin-top: 20px}
#media screen and (max-width: 1000px) {
.sidebar { clear:both; width:100% }
.content { width:100%; }
}
This design isn't perfect as you might find some text going under the sidebar, but should be a good start.
Regards,
-Gallo
give the height to sidebar as .sidebar{height:500px;} not to container
*{
margin: 0;
padding: 0;
}
#container { height:auto; width:100% }
.sidebar { background:red; float:right; height:500px; width:20% }
.content { background:green; height: 100px; width:80%; float:left; margin-top: 20px;}
#media screen and (max-width: 1000px) {
.sidebar { clear:both; width:100% }
.content { width:100%; }
}
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.
I have a grid of thumbnails:
.thumbnail-container {
border: 1px solid red;
float: left;
width: 25%; (depending on screen size)
}
.thumbnail {
display: block;
height: auto;
width: 200px;
margin: 0 auto;
padding: 0px;
}
you get the idea...
Sometimes there are 5 thumbs, sometimes 4, 3, 2... in the same row depending on the #media device screen width.
So as you can see in the picture, my problem is the horizontal spacing between the thumbnails. Since the width of each thumb-container is equal (25% in the picture) and thumbnails are centered, there is double spacing betwet 1st and 2nd, 2nd-3d, 3rd-4th. On the contrary, the 1st thumb has half of that space to the left, and the 4th has it to the right:
It's like this: 1(A)2(B)2(C)2(D)1
And I want it like this: 1(A)1(B)1(C)1(D)1
Any ideas of how to make the spacing the same?
Many thanks!
I made this responsive grid that does what you need using CSS.
It uses media queries and nth-child().
The horizontal and vertical margins are equal.
FIDDLE
It shows you can use calculation to position grid elements with equal margins between each other. The margin between elements and window is also the same.
Code for screens wider than 751px isn't written yet though but you get the idea. Here is the code :
HTML :
<div id="container">
<div class="wrap">
<div class="foto">1</div>
</div>
<div class="wrap">
<div class="foto">2</div>
</div>
<div class="wrap">
<div class="foto">3</div>
</div>
... And so on ...
</div>
CSS :
html, body {
margin:0;
padding:0;
min-width:150px;
}
.wrap {
float:left;
position:relative;
}
.foto {
width: 150px;
height: 150px;
background: gold;
position:absolute;
}
#warning{display:none;}
#media screen and (min-width: 631px) {
.wrap {
width:20%;
padding-bottom:25%;
}
.wrap:nth-child(4n+2), .wrap:nth-child(4n+3){
}
.wrap .foto {
top:-75px;
margin-top:100%;
right:-30px;
}
.wrap:nth-child(4n+2){
margin:0 5% 0 7.5%;
}
.wrap:nth-child(4n+3){
margin-right:7.5%;
}
.wrap:nth-child(4n+2) .foto{
left:50%;
margin-left:-75px;
}
.wrap:nth-child(4n+3) .foto{
right:50%;
margin-right:-75px;
}
.wrap:nth-child(4n) .foto{
left:-30px;
}
#container{
margin-top:-45px;
}
}
#media screen and (min-width: 481px) and (max-width: 631px) {
.wrap {
width:25%;
padding-bottom:33.3%;
}
.wrap:nth-child(3n+2){
margin:0 12.5%;
}
.wrap .foto {
top:-75px;
margin-top:100%;
right:-37px;
}
.wrap:nth-child(3n+2) .foto{
left:50%;
margin-left:-75px;
}
.wrap:nth-child(3n) .foto{
left:-37px;
}
#container{
margin-top:-37px;
}
}
#media screen and (min-width: 331px) and (max-width: 480px) {
.wrap {
width:33.3%;
padding-bottom:50%;
clear:left;
}
.wrap:nth-child(even) {
float:right;
clear:right;
}
.wrap .foto {
top:-75px;
margin-top:100%;
right:-50px;
}
.wrap:nth-child(even) .foto {
left:-50px;
}
.wrap:nth-child(4n+3) .foto, .wrap:nth-child(4n+4) .foto {
bottom:-75px;
margin-bottom:100%;
}
#container{
margin-top:-25px;
}
}
#media screen and (max-width: 330px) {
.wrap {
width:50%;
padding-bottom:100%;
clear:left;
}
.wrap:nth-child(odd) .foto {
right:-75px;
bottom:0;
bottom:-75px;
margin-bottom:100%;
}
.wrap:nth-child(even) .foto {
top:0px;
right:-75px;
top:-75px;
margin-top:100%;
}
}
#media screen and (min-width: 751px) {
#warning{
color:#fff;
display:block;
position:fixed;
width:100%;
height:50%;
top:25%;
left:0;
background:#000;
text-align:center;
font-size:30px;
}
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;
}