I am trying to design a responsive web design using media queries, while doing so I have designing this for both large and medium size devices, everything is working perfectly fine but for the medium size device when I squeeze my browser below 992 pixels the box with the title sushi comes down and takes the space of 50% as specified in the media query code, but I want it so that when it comes down it stretches the full browser width.
I tried to do by specifying sushi class in a media-query and setting width to 196% but that didn't work as it should with responsive design.
* {
box-sizing: border-box;
}
h1 {
font-weight: bold;
font-size: 2em;
text-align: center;
}
.chicken {
border: solid 1px black;
background-color: grey;
margin: 10px;
}
.box1title {
border: 2px solid black;
background-color: pink;
width: 88px;
float: right;
}
.b1content {
text-align: center;
}
.beef {
border: solid 1px black;
background-color: grey;
margin: 10px;
}
.box2title {
border: 2px solid black;
background-color: rgb(170, 57, 57);
width: 88px;
float: right;
}
.b2content {
text-align: center;
}
.sushi {
border: solid 1px black;
background-color: grey;
margin: 10px;
}
.box3title {
border: 2px solid black;
background-color: rgb(255, 255, 170);
width: 88px;
float: right;
}
.b3content {
text-align: center;
}
p {
clear: both;
padding: 5px;
}
.container {
width: 100%;
}
#media(min-width: 992px) {
.col-lg-1,
.col-lg-2,
.col-lg-3,
.col-lg-4,
.col-lg-5,
.col-lg-6,
.col-lg-7,
.col-lg-8,
.col-lg-9,
.col-lg-10,
.col-lg-11,
.col-lg-12 {
float: left;
}
.col-lg-1 {
width: 8.83%;
}
.col-lg-2 {
width: 16.66%;
}
.col-lg-3 {
width: 25%;
}
.col-lg-4 {
width: 33%;
}
.col-lg-5 {
width: 41.66%;
}
.col-lg-6 {
width: 50%;
}
.col-lg-7 {
width: 66.66%;
}
.col-lg-8 {
width: 74.99%;
}
.col-lg-9 {
width: 8.83%;
}
.col-lg-10 {
width: 83.33%;
}
.col-lg-11 {
width: 91.66%;
}
.col-lg-12 {
width: 100%;
}
}
#media (min-width: 768px) and (max-width: 991px) {
.col-md-1,
.col-md-2,
.col-md-3,
.col-md-4,
.col-md-5,
.col-md-6,
.col-md-7,
.col-md-8,
.col-md-9,
.col-md-10,
.col-md-11,
.col-md-12 {
float: left;
}
.col-md-1 {
width: 8.83%;
}
.col-md-2 {
width: 16.66%;
}
.col-md-3 {
width: 25%;
}
.col-md-4 {
width: 33%;
}
.col-md-5 {
width: 41.66%;
}
.col-md-6 {
width: 50%;
clear: right;
}
.col-md-7 {
width: 66.66%;
}
.col-md-8 {
width: 74.99%;
}
.col-md-9 {
width: 8.83%;
}
.col-md-10 {
width: 83.33%;
}
.col-md-11 {
width: 91.66%;
}
.col-md-12 {
width: 100%;
}
}
<div class="container">
<div class="col-lg-4 col-md-6">
<div class="chicken">
<div class="box1title">
<div class="b1content">Chicken</div>
</div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
</div>
<div class="col-lg-4 col-md-6">
<div class="beef">
<div class="box2title">
<div class="b2content">Beef</div>
</div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
</div>
<div class="col-lg-4 col-md-6">
<div class="sushi">
<div class="box3title">
<div class="b3content">Sushi</div>
</div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
</div>
</div>
My table with sushi title should stretch to the max when the browser is squeezed to below 992 pixels like the following image.
You can change the col-md-6 for the sushi box to col-md-12 so that when your screen reaches the correct dimensions your container will span all 12 columns:
<div class="col-lg-4 col-md-12"> <!-- <- change col-md-6 to col-md-12 -->
<div class="sushi">
...
</div>
</div>
See example below:
* {
box-sizing: border-box;
}
h1 {
font-weight: bold;
font-size: 2em;
text-align: center;
}
.chicken {
border: solid 1px black;
background-color: grey;
margin: 10px;
}
.box1title {
border: 2px solid black;
background-color: pink;
width: 88px;
float: right;
}
.b1content {
text-align: center;
}
.beef {
border: solid 1px black;
background-color: grey;
margin: 10px;
}
.box2title {
border: 2px solid black;
background-color: rgb(170, 57, 57);
width: 88px;
float: right;
}
.b2content {
text-align: center;
}
.sushi {
border: solid 1px black;
background-color: grey;
margin: 10px;
}
.box3title {
border: 2px solid black;
background-color: rgb(255, 255, 170);
width: 88px;
float: right;
}
.b3content {
text-align: center;
}
p {
clear: both;
padding: 5px;
}
.container {
width: 100%;
}
#media(min-width: 992px) {
.col-lg-1,
.col-lg-2,
.col-lg-3,
.col-lg-4,
.col-lg-5,
.col-lg-6,
.col-lg-7,
.col-lg-8,
.col-lg-9,
.col-lg-10,
.col-lg-11,
.col-lg-12 {
float: left;
}
.col-lg-1 {
width: 8.83%;
}
.col-lg-2 {
width: 16.66%;
}
.col-lg-3 {
width: 25%;
}
.col-lg-4 {
width: 33%;
}
.col-lg-5 {
width: 41.66%;
}
.col-lg-6 {
width: 50%;
}
.col-lg-7 {
width: 66.66%;
}
.col-lg-8 {
width: 74.99%;
}
.col-lg-9 {
width: 8.83%;
}
.col-lg-10 {
width: 83.33%;
}
.col-lg-11 {
width: 91.66%;
}
.col-lg-12 {
width: 100%;
}
}
#media (min-width: 768px) and (max-width: 991px) {
.col-md-1,
.col-md-2,
.col-md-3,
.col-md-4,
.col-md-5,
.col-md-6,
.col-md-7,
.col-md-8,
.col-md-9,
.col-md-10,
.col-md-11,
.col-md-12 {
float: left;
}
.col-md-1 {
width: 8.83%;
}
.col-md-2 {
width: 16.66%;
}
.col-md-3 {
width: 25%;
}
.col-md-4 {
width: 33%;
}
.col-md-5 {
width: 41.66%;
}
.col-md-6 {
width: 50%;
clear: right;
}
.col-md-7 {
width: 66.66%;
}
.col-md-8 {
width: 74.99%;
}
.col-md-9 {
width: 8.83%;
}
.col-md-10 {
width: 83.33%;
}
.col-md-11 {
width: 91.66%;
}
.col-md-12 {
width: 100%;
}
}
<div class="container">
<div class="col-lg-4 col-md-6">
<div class="chicken">
<div class="box1title">
<div class="b1content">Chicken</div>
</div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
</div>
<div class="col-lg-4 col-md-6">
<div class="beef">
<div class="box2title">
<div class="b2content">Beef</div>
</div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
</div>
<div class="col-lg-4 col-md-12">
<div class="sushi">
<div class="box3title">
<div class="b3content">Sushi</div>
</div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
</div>
</div>
If we change <div class="col-lg-4 col-md-6"> to <div class="col-lg-4"> it will work... Check https://stackblitz.com/edit/js-w2je7d?file=index.html
Related
I'm new to web development and I'm trying to replicate this website on my own.
And now I'm encountering a problem.
I'm not sure why the float: left (under #media) is not correctly working. I made sure to apply box-sizing: border-box to allow the inclusion of the padding and border in an element's total width and height.
Below is my code:
* {
box-sizing: border-box;
}
body{
margin-top: 40px;
background-color: #F9F9FB;
}
.container-fluid {
margin-top: 50px;
}
h3 {
border-left: 1px solid black;
border-bottom: 1px solid black;
margin: 0px;
padding: 1px;
width: 33.33%;
height: 28px;
float: right;
text-align: center;
background-color: #B59F84;
}
.row div {
border: 1px solid black;
padding: 0px;
margin: 10px;
background-color: #FFFFF5;
}
p {
margin: 0px;
padding: 10px;
clear: right;
}
/********** Large devices only **********/
#media (min-width: 992px) {
.col-lg-1, .col-lg-2, .col-lg-3, .col-lg-4, .col-lg-5, .col-lg-6, .col-lg-7, .col-lg-8, .col-lg-9, .col-lg-10, .col-lg-11, .col-lg-12 {
float: left;
}
.col-lg-1 {
width: 8.33%;
}
.col-lg-2 {
width: 16.66%;
}
.col-lg-3 {
width: 25%;
}
.col-lg-4 {
width: 33.33%;
}
.col-lg-5 {
width: 41.66%;
}
.col-lg-6 {
width: 50%;
}
.col-lg-7 {
width: 58.33%;
}
.col-lg-8 {
width: 66.66%;
}
.col-lg-9 {
width: 74.99%;
}
.col-lg-10 {
width: 83.33%;
}
.col-lg-11 {
width: 91.66%;
}
.col-lg-12 {
width: 100%;
}
}
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="style.css">
<title>Assignment Solution for Module 2</title>
</head>
<body>
<h1 style="text-align: center;">Our Menu</h1>
<div class="container-fluid">
<div class="row">
<div class="col-lg-4">
<h3>Div 1</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
<div class="col-lg-4">
<h3>Div 2</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
<div class="col-lg-4">
<h3>Div 3</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
</div>
</div>
</body>
</html>
I made sure to apply box-sizing: border-box to allow the inclusion of the padding and border in an element's total width and height.
Edit: it should be float: left not float: right
You need to set the card's width first of all. For responsiveness, go for max-width.
In this example, Im using flexbox along with max-with:400px (change to your needs) for each card. With those few extra lines, your row will be responsive. (In my example, they are centered in the middle of the page, you can change that by playing with justify-content).
.row {
width: 100%;
display: flex;
flex-wrap: wrap;
flex-direction: row;
justify-content: center;
}
.row div {
border: 1px solid black;
max-width: 400px;
padding: 0px;
margin: 10px;
background-color: #FFFFF5;
}
I am planning to create this layout:
I am using wrapper as a class and planning to center everything on the screen.
Aside from the wrapper how can I also put some equal sizes for the text and form.
So far here is my css:
.wrapper {
display: grid;
grid-gap: 20px;
border: 1px solid red;
}
.navbar {
display: grid;
}
a#logo {
width: 212px;
height: 41px;
}
.hero {
display: grid;
grid-template-areas: "hero-text hero-video";
}
.hero-text {
grid-area: hero-text;
border: 1px solid green;
}
.hero-form {
grid-area: hero-video;
border: 1px solid green;
}
Any idea how can I achieve the layout below quickly?
You can checkout my codes here: https://jsfiddle.net/f14qxLf5/1/
Feel free to modify it. Sorry newbie here.
Minimal approach through CSS Grid . Moreover you will get useful tutorial here CSS Grid- by Rachel Andrew.
-Thank You
body {
background-color: #fff;
}
.wrapper {
display: grid;
grid-gap: 20px;
border: 1px solid red;
padding: 20px;
}
.navbar {
display: grid;
text-align: center;
width: 100%;
}
a#logo {
display: inline-block;
width: 212px;
height: 41px;
border: 1px solid gray;
color: #000;
font-size: 22px;
text-decoration: none;
}
.hero {
display: grid;
grid-gap: 5px;
grid-template-areas: "hero-text hero-video";
}
.title {
text-align: center;
border: 1px solid gray;
}
.student-list {
display: grid;
grid-template-areas: "student-info student-info student-info";
grid-gap: 5px;
}
.student-info {
text-align: center;
justify-content: center;
border: 1px solid gray;
min-height: 80px;
}
.hero-text {
grid-area: hero-text;
border: 1px solid green;
padding: 20px;
}
.hero-form {
grid-area: hero-video;
border: 1px solid green;
padding: 20px;
}
footer {
border: 1px solid gray;
text-align: center;
}
<div class="wrapper">
<div class="navbar">
LOGO
</div>
<header class="hero">
<div class="hero-text">
<h2> How to create money online </h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </p>
</div>
<div class="hero-form">
<h2> TEXT FORM FOR NOW</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </p>
</div>
</header>
<div class="title">
<h2>Some Heading</h2>
</div>
<section class="student-list">
<div class="student-info">
<h2>Student Name</h2>
<p>text</p>
</div>
<div class="student-info">
<h2>Student Name</h2>
<p>text</p>
</div>
<div class="student-info">
<h2>Student Name</h2>
<p>text</p>
</div>
</section>
<footer>
<p>footer text</p>
</footer>
</div>
I am a new html & CSS learner and my first assignment (creating a responsive design page) is giving headache. Please see my code in this url: https://jsfiddle.net/prhjfsLs/
<h1>RESPONSIVE DESIGN LAYOUT</h1>
<div>
<div class="col-lg-4 col-md-6 col-sl-12" id="Section1"><h7>Section 1</h7><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p></div>
<div class="col-lg-4 col-md-6 col-sl-12" id="Section2"><h7>Section 2</h7><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p></div>
<div class="col-lg-4 col-md-12 col-sl-12"id="Section3"><h7>Section 3</h7><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p></div>
</div>
* {
box-sizing: border-box;
}
h1 {
font-family: georgia;
text-align: center;
color: coral;
}
#Section1 {
/*width: 420px;*/
border: 1px solid red;
margin-bottom: 5px;
margin-right: 2.5px;
margin-left: 5px;
padding: 5px;
background-color: bisque;
font-family: georgia;
}
#Section2 {
/* width: 420px;*/
border: 1px solid red;
margin-bottom: 5px;
margin-left: 2.5px;
margin-right: 2.5px;
padding: 5px;
background-color: bisque;
font-family: georgia;
}
#Section3 {
/*width: 420px;*/
margin-bottom: 5px;
margin-left: 2.5;
margin-right: 5px;
border: 1px solid red;
padding: 5px;
background-color: bisque;
font-family: georgia;
}
h7 {
background-color: chocolate;
position: relative;
border: 1px solid red;
left: 80%;
padding: inherit;
margin-top: 10px;
}
.row {
width: 100%;
}
#media (min-width: 992px) {
.col-lg-1, .col-lg-2, .col-lg-3, .col-lg-4, .col-lg-5, .col-lg-6, .col-lg-7, .col-lg-8, .col-lg-9, .col-lg-10, .col-lg-11, .col-lg-12 {
float: left;
border: 1px solid blue;
}
.col-lg-1 {
width: 8.33%;
}
.col-lg-2 {
width: 16.66%;
}
.col-lg-3 {
width: 25%;
}
.col-lg-4 {
width: 33.33%;
}
.col-lg-5 {
width: 41.66%;
}
.col-lg-6 {
width: 50%;
}
.col-lg-7 {
width: 58.33%;
}
.col-lg-8 {
width: 66.66%;
}
.col-lg-9 {
width: 74.99%;
}
.col-lg-10 {
width: 83.33%;
}
.col-lg-11 {
width: 91.66%;
}
.col-lg-12 {
width: 100%;
}
}
#media (min-width: 768px) and (max-width: 991px) {
.col-md-1, .col-md-2, .col-md-3, .col-md-4, .col-md-5, .col-md-6, .col-md-7, .col-md-8, .col-md-9, .col-md-10, .col-md-11, .col-md-12 {
float: left;
border: 1px solid blue;
}
.col-md-1 {
width: 8.33%;
}
.col-md-2 {
width: 16.66%;
}
.col-md-3 {
width: 25%;
}
.col-md-4 {
width: 33.33%;
}
.col-md-5 {
width: 41.66%;
}
.col-md-6 {
width: 50%;
}
.col-md-7 {
width: 58.33%;
}
.col-md-8 {
width: 66.66%;
}
.col-md-9 {
width: 74.99%;
}
.col-md-10 {
width: 83.33%;
}
.col-md-11 {
width: 91.66%;
}
.col-md-12 {
width: 100%;
}
}
#media (max-width: 767px) {
.col-sl-1, .col-sl-2, .col-sl-3, .col-sl-4, .col-sl-5, .col-sl-6, .col-sl-7, .col-sl-8, .col-sl-9, .col-sl-10, .col-sl-11, .col-sl-12 {
float: left;
border: 1px solid blue;
}
.col-sl-1 {
width: 8.33%;
}
.col-sl-2 {
width: 16.66%;
}
.col-sl-3 {
width: 25%;
}
.col-sl-4 {
width: 33.33%;
}
.col-sl-5 {
width: 41.66%;
}
.col-sl-6 {
width: 50%;
}
.col-sl-7 {
width: 58.33%;
}
.col-sl-8 {
width: 66.66%;
}
.col-sl-9 {
width: 74.99%;
}
.col-md-10 {
width: 83.33%;
}
.col-sl-11 {
width: 91.66%;
}
.col-sl-12 {
width: 100%;
}
}
Whenever I add margin between my div elements boxes, it is making them shift. It is my third day looking on the net for a solution.
Counting on your help,
Thanks,
Whenever I add margin between my div elements boxes, it is making them shift.
The reason for such behavior is because you have the media queries set as
.col-lg-4 {
width: 33.33%;
}
And you have a 3 div tags with col-lg-4 class. With this rule it occupies 99.99% width on its parent(all 3 div's together).
Now if you add a extra margin on any one div, There is no space on the parent to contain your div. So it is shifted.
To resolve this issue, You can wrap your divs and provide padding as another answer already suggested.
Wrap them in a container div and give that some padding. Here I removed border from your responsive classes (.col-xs-4 and so on) then it would look all good, like they have margin in between.
See in this example :
* {
box-sizing: border-box;
}
h1 {
font-family: georgia;
text-align: center;
color: coral;
}
.container{
padding:10px;
}
#Section1 {
/*width: 420px;*/
border: 1px solid red;
padding: 5px;
background-color: bisque;
font-family: georgia;
}
#Section2 {
/* width: 420px;*/
border: 1px solid red;
padding: 5px;
background-color: bisque;
font-family: georgia;
}
#Section3 {
/*width: 420px;*/
border: 1px solid red;
padding: 5px;
background-color: bisque;
font-family: georgia;
}
h7 {
background-color: chocolate;
position: relative;
border: 1px solid red;
left: 80%;
padding: inherit;
margin-top: 10px;
}
.row {
width: 100%;
}
#media (min-width: 992px) {
.col-lg-1, .col-lg-2, .col-lg-3, .col-lg-4, .col-lg-5, .col-lg-6, .col-lg-7, .col-lg-8, .col-lg-9, .col-lg-10, .col-lg-11, .col-lg-12 {
float: left;
}
.col-lg-1 {
width: 8.33%;
}
.col-lg-2 {
width: 16.66%;
}
.col-lg-3 {
width: 25%;
}
.col-lg-4 {
width: 33.33%;
}
.col-lg-5 {
width: 41.66%;
}
.col-lg-6 {
width: 50%;
}
.col-lg-7 {
width: 58.33%;
}
.col-lg-8 {
width: 66.66%;
}
.col-lg-9 {
width: 74.99%;
}
.col-lg-10 {
width: 83.33%;
}
.col-lg-11 {
width: 91.66%;
}
.col-lg-12 {
width: 100%;
}
}
#media (min-width: 768px) and (max-width: 991px) {
.col-md-1, .col-md-2, .col-md-3, .col-md-4, .col-md-5, .col-md-6, .col-md-7, .col-md-8, .col-md-9, .col-md-10, .col-md-11, .col-md-12 {
float: left;
}
.col-md-1 {
width: 8.33%;
}
.col-md-2 {
width: 16.66%;
}
.col-md-3 {
width: 25%;
}
.col-md-4 {
width: 33.33%;
}
.col-md-5 {
width: 41.66%;
}
.col-md-6 {
width: 50%;
}
.col-md-7 {
width: 58.33%;
}
.col-md-8 {
width: 66.66%;
}
.col-md-9 {
width: 74.99%;
}
.col-md-10 {
width: 83.33%;
}
.col-md-11 {
width: 91.66%;
}
.col-md-12 {
width: 100%;
}
}
#media (max-width: 767px) {
.col-sl-1, .col-sl-2, .col-sl-3, .col-sl-4, .col-sl-5, .col-sl-6, .col-sl-7, .col-sl-8, .col-sl-9, .col-sl-10, .col-sl-11, .col-sl-12 {
float: left;
}
.col-sl-1 {
width: 8.33%;
}
.col-sl-2 {
width: 16.66%;
}
.col-sl-3 {
width: 25%;
}
.col-sl-4 {
width: 33.33%;
}
.col-sl-5 {
width: 41.66%;
}
.col-sl-6 {
width: 50%;
}
.col-sl-7 {
width: 58.33%;
}
.col-sl-8 {
width: 66.66%;
}
.col-sl-9 {
width: 74.99%;
}
.col-md-10 {
width: 83.33%;
}
.col-sl-11 {
width: 91.66%;
}
.col-sl-12 {
width: 100%;
}
}
<h1>RESPONSIVE DESIGN LAYOUT</h1>
<div>
<div class="col-lg-4 col-md-6 col-sl-12 container">
<div id="Section1"><h7>Section 1</h7><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div></div>
<div class="col-lg-4 col-md-6 col-sl-12 container">
<div id="Section2"><h7>Section 2</h7><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div></div>
<div class="col-lg-4 col-md-12 col-sl-12 container">
<div id="Section3"><h7>Section 3</h7><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
</div>
</div>
I am stuck on one part of a question for a homework assignment.
We're producing 3 responsive layouts (I called them lg, md, xs) for a simple site consisting of 3 boxes.
We are not allowed to use bootstrap for this. You can see my implementation so far here: https://jennlhay.github.io/coursera-test/assn1/index.html
On the medium sized layout, meant for tablet devices (you can see it by resizing the box), the 3 box layout wraps around.
I'm trying to figure out how to make the third box take up an entire row. As in, take up a different area of the grid than the 2 boxes above it.
I've tried many different ways of doing this (changing the container divs to individual ids, adding some extra column definitions to css for col-md etc) but can't figure it out. HTML and CSS are as follows:
HTML
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="css/style.css">
<title>Assignment Solution for Module 2</title>
</head>
<body>
<h1>Our Menu</h1>
<div class="row">
<div class="col-lg-4 col-md-6 col-xs-12"><div class="container"><h2 id="left">Chicken</h2><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p></div></div>
<div class="col-lg-4 col-md-6 col-xs-12"><div class="container"><h2 id="middle">Meat</h2><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p></div></div>
<div class="col-lg-4 col-md-6 col-xs-12"><div class="container"><h2 id="right">Eggs</h2><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </p></div></div>
</div>
</html>
CSS
* {
box-sizing: border-box;
}
body {
font-family: Arial, Helvetia, sans-serif;
}
h1 {
text-align: center;
font-size: 175%;
margin-bottom: 30px;
}
h2 {
position: relative;
float: right;
border: 1px solid black;
margin: 0;
padding: 10px;
font-size: 125%;
}
#left {
background-color: white;
}
#middle {
background-color: blue;
}
#right {
background-color: gray;
}
.container {
border: 1px solid black;
background-color: yellow;
width: 90%;
margin-right: auto;
margin-left: auto;
margin-bottom: 10%;
overflow: hidden;
}
p {
padding-top: 15px;
font-size: 100%;
clear: right;
}
.row {
width: 100%;
}
#media (min-width: 992px) {
.col-lg-1, .col-lg-2, .col-lg-3, .col-lg-4, .col-lg-5, .col-lg-6,
.col-lg-7, .col-lg-8, .col-lg-9, .col-lg-10, .col-lg-11, .col-lg-12 {
float: left;
}
.col-lg-1 {
width: 8.33%;
}
.col-lg-2 {
width: 16.66%;
}
.col-lg-3 {
width: 25%;
}
.col-lg-4 {
width: 33.33%;
}
.col-lg-5 {
width: 41.66%;
}
.col-lg-6 {
width: 50%;
}
.col-lg-7 {
width: 58.33%;
}
.col-lg-8 {
width: 66.66%;
}
.col-lg-9 {
width: 74.99%;
}
.col-lg-10 {
width: 83.33%;
}
.col-lg-11 {
width: 91.66%;
}
.col-lg-12 {
width: 100%;
}
}
#media (min-width: 768px) and (max-width: 991px) {
.col-md-1, .col-md-2, .col-md-3, .col-md-4, .col-md-5, .col-md-6,
.col-md-7, .col-md-8, .col-md-9, .col-md-10, .col-md-11, .col-md-12 {
float: left;
}
.col-md-1 {
width: 8.33%;
}
.col-md-2 {
width: 16.66%;
}
.col-md-3 {
width: 25%;
}
.col-md-4 {
width: 33.33%;
}
.col-md-5 {
width: 41.66%;
}
.col-md-6 {
width: 50%;
}
.col-md-7 {
width: 58.33%;
}
.col-md-8 {
width: 66.66%;
}
.col-md-9 {
width: 74.99%;
}
.col-md-10 {
width: 83.33%;
}
.col-md-11 {
width: 91.66%;
}
.col-md-12 {
width: 100%;
}
}
#media (max-width: 767px) {
.col-xs-1, .col-xs-2, .col-xs-3, .col-xs-4, .col-xs-5, .col-xs-6, .col-xs-7, .col-xs-8, .col-xs-9, .col-xs-10, .col-xs-11, .col-xs-12 {
}
.col-xs-1 {
width: 8.33%;
}
.col-xs-2 {
width: 16.66%;
}
.col-xs-3 {
width: 25%;
}
.col-xs-4 {
width: 33.33%;
}
.col-xs-5 {
width: 41.66%;
}
.col-xs-6 {
width: 50%;
}
.col-xs-7 {
width: 58.33%;
}
.col-xs-8 {
width: 66.66%;
}
.col-xs-9 {
width: 74.99%;
}
.col-xs-10 {
width: 83.33%;
}
.col-xs-11 {
width: 91.66%;
}
.col-xs-12 {
width: 100%;
}
}
Are you trying to make the third row full width in a medium sized screen? If so you would just change change the col-md class from:
<div class="col-lg-4 col-md-6 col-xs-12"><div class="container"><h2 id="right">Eggs</h2><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </p></div></div>
to:
<div class="col-lg-4 col-md-12 col-xs-12"><div class="container"><h2 id="right">Eggs</h2><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </p></div></div>
If you are looking for this http://prntscr.com/cq7osg
then below the code that show you how I did this
* {
box-sizing: border-box;
}
body {
font-family: Arial, Helvetia, sans-serif;
}
h1 {
text-align: center;
font-size: 175%;
margin-bottom: 30px;
}
h2 {
position: relative;
float: right;
border: 1px solid black;
margin: 0;
padding: 10px;
font-size: 125%;
}
#left {
background-color: white;
}
#middle {
background-color: blue;
}
#right {
background-color: gray;
}
.container {
border: 1px solid black;
background-color: yellow;
/* width: 90%; */
margin-right: 15px;
margin-left: 15px;
margin-bottom: 10%;
overflow: hidden;
}
p {
padding-top: 15px;
font-size: 100%;
clear: right;
}
.row {
width: 100%;
}
#media (min-width: 992px) {
.col-lg-1, .col-lg-2, .col-lg-3, .col-lg-4, .col-lg-5, .col-lg-6,
.col-lg-7, .col-lg-8, .col-lg-9, .col-lg-10, .col-lg-11, .col-lg-12 {
float: left;
}
.col-lg-1 {
width: 8.33%;
}
.col-lg-2 {
width: 16.66%;
}
.col-lg-3 {
width: 25%;
}
.col-lg-4 {
width: 33.33%;
}
.col-lg-5 {
width: 41.66%;
}
.col-lg-6 {
width: 50%;
}
.col-lg-7 {
width: 58.33%;
}
.col-lg-8 {
width: 66.66%;
}
.col-lg-9 {
width: 74.99%;
}
.col-lg-10 {
width: 83.33%;
}
.col-lg-11 {
width: 91.66%;
}
.col-lg-12 {
width: 100%;
}
}
#media (min-width: 768px) and (max-width: 991px) {
.col-md-1, .col-md-2, .col-md-3, .col-md-4, .col-md-5, .col-md-6,
.col-md-7, .col-md-8, .col-md-9, .col-md-10, .col-md-11, .col-md-12 {
float: left;
}
.col-md-1 {
width: 8.33%;
}
.col-md-2 {
width: 16.66%;
}
.col-md-3 {
width: 25%;
}
.col-md-4 {
width: 33.33%;
}
.col-md-5 {
width: 41.66%;
}
.col-md-6 {
width: 50%;
}
.col-md-7 {
width: 58.33%;
}
.col-md-8 {
width: 66.66%;
}
.col-md-9 {
width: 74.99%;
}
.col-md-10 {
width: 83.33%;
}
.col-md-11 {
width: 91.66%;
}
.col-md-12 {
width: 100%;
}
.entire-row {
width: 100%;
}
}
#media (max-width: 767px) {
.col-xs-1, .col-xs-2, .col-xs-3, .col-xs-4, .col-xs-5, .col-xs-6, .col-xs-7, .col-xs-8, .col-xs-9, .col-xs-10, .col-xs-11, .col-xs-12 {
}
.col-xs-1 {
width: 8.33%;
}
.col-xs-2 {
width: 16.66%;
}
.col-xs-3 {
width: 25%;
}
.col-xs-4 {
width: 33.33%;
}
.col-xs-5 {
width: 41.66%;
}
.col-xs-6 {
width: 50%;
}
.col-xs-7 {
width: 58.33%;
}
.col-xs-8 {
width: 66.66%;
}
.col-xs-9 {
width: 74.99%;
}
.col-xs-10 {
width: 83.33%;
}
.col-xs-11 {
width: 91.66%;
}
.col-xs-12 {
width: 100%;
}
}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="css/style.css">
<title>Assignment Solution for Module 2</title>
</head>
<body>
<h1>Our Menu</h1>
<div class="row">
<div class="col-lg-4 col-md-6 col-xs-12">
<div class="container"><h2 id="left">Chicken</h2><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p></div>
</div>
<div class="col-lg-4 col-md-6 col-xs-12"><div class="container"><h2 id="middle">Meat</h2><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p></div></div>
<div class="col-lg-4 col-md-6 col-xs-12 entire-row"><div class="container"><h2 id="right">Eggs</h2><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </p></div></div>
</div>
</html>
I'm working on this block of HTML CSS, I need the image to overlap slightly the header div (in blue).
I'm doing this as shown in the jsfiddle here: https://jsfiddle.net/49zcmf4z/3/
the HTML
<div class="container">
<div class="row">
<div class="col-md-12 block-header">
<div class="col-md-offset-6 col-md-6 text-center block-header">
<h1>Title</h1>
</div>
</div>
<div class="row">
<div class="col-md-6 image text-center">
<img src="http://placehold.it/350x150">
</div>
<div class="col-md-6">
<div class="content">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </p>
</div>
</div>
</div>
</div>
</div>
and the CSS
body {
margin: 10px;
}
.container {
border: solid 1px red;
}
.image {
position: relative;
z-index: 10;
}
#media (min-width: 200px) {
.image img {
transform: translateY(-5em);
}
}
.image img {
width: 100%;
border: solid 1px black;
margin-left: 1em;
}
.block-header {
background-color: blue;
height: 85px;
padding-left: 0px;
padding-right: 0px;
}
#media (max-width: 992px) {
.block-header {
padding-top: 1px;
}
}
.block-header h1 {
color: white;
}
my problem is that after translating up the image, the div that contains it remains unchanged, and has lots of white space in the place where the image used to be.
Hey you could try to use margins instead of transform, it's easier :
.image {
position: relative;
z-index: 10;
#media (min-width: 200px) {
img {
margin-top: -5em;
}
}
img {
width: 100%;
border: solid 1px black;
margin-left: 1em;
}
}
https://jsfiddle.net/49zcmf4z/4/
You can always "hardcode" the margins of the image (probably not best solution):
img {
width: 100%;
border: solid 1px black;
margin-left: 1em;
margin-bottom: -4em;}
https://jsfiddle.net/49zcmf4z/5/