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%; }
}
Related
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.
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%;
}
}
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 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;
}
I have a site that needs the placement of an h3 moved depending on the screen size.
The html is currently a table like this:
<table><tr><td><img src="someimage"></td><td><h3>Heading</h3></td></tr></table>
On smaller screens, I would want the h3 to appear above the image, with the image full width, so I start with:
<div class="heading-image">
<h3>Heading</h3>
<img="someimage">
</div>
That just works, but on larger screens I want the h3 to drop to the right of the image, which would be at 50% of the screen:
.heading-image img { max-width: 50% };
.heading-image h3 { max-width: 50%; float:right };
Now the h3 drops next to the image on the right hand side. But then it comes to the age old problem of vertically centering multi-line text inside a div, where the height of the div is unknown (dependent on the size of the image and the current screen width), and the length of the text is unknown (these are entered into a CMS).
I have tried a variety of approaches found on the internet, but I am just not getting my head around it. I tried making both the img and h3 a table-cell to get me back to my original approach but I can't get the alignment to work.
Here's the code. Just change the size you want to collapse in the #media-query.
Working fiddle: http://jsfiddle.net/Hv6x3/
HTML
<div class="heading-image">
<h3>Headline text goes here...</h3>
<img src="http://placeimg.com/640/480/tech" alt=""/>
</div>
CSS
.heading-image img {
float: left;
max-width: 50%;
height: auto;
}
.heading-image h3 {
float: right;
width: 50%;
max-width: 50%;
text-align: left;
}
#media (max-width: 600px) {
.heading-image {
text-align: center;
}
.heading-image img {
float: none;
max-width: 100%
}
.heading-image h3 {
float: none;
max-width: 50%;
}
}
for vertical-align....use display:table-cell
make sure the parent div is set as display:table
jsfiddle demo
html, body {
width:100%;
height:100%;
margin:0;
padding:0;
}
#media only screen and (min-width : 600px) {
.heading-image {
width:100%;
height:100%;
margin:0;
padding:0;
text-align:center;
display: table;
}
.heading-image .img {
float:left;
height:100%;
}
.heading-image .h3 {
float:right;
display: table;
height:100%;
}
.heading-image .h3 h3 {
display: table-cell;
vertical-align: middle;
text-align: center;
}
}
#media only screen and (max-width : 600px) {
.heading-image {
width:100%;
margin:0;
padding:0;
text-align:center
}
.heading-image .img {
width: 100%;
}
.heading-image .img img {
width:auto;
height:auto;
}
.heading-image .h3 {
width: 100%;
vertical-align:middle;
}
}