CSS/Bootstrap div to Fill it's parent height - html

I'm pretty much stuck with making side menu div's of my code filling the parent height to 100%. I've tried alot of googling and testing before comming to ask..
Code snippet: http://jsfiddle.net/zntxaspd/
html, body { height: 100%;}
.row.content { height: 100%; width:70%; margin: auto; }
.sidenav { padding-top: 20px;background-color: #f1f1f1; height: 100%;}
#media screen and (max-width: 767px) {
.sidenav {
height: auto;
padding: 15px;
}
.row.content {height:auto;}
}
h5 { font-size: 14px; border-bottom: 6px solid red; font-weight: bold; }
.rightcontainer { width:100%; height:100% margin: auto; border: 0px solid; border-radius: 4px; margin-bottom: 5px; border-bottom: 6px solid red;}
.rightcontainer .accountpanel .columncontainer .col-sm-6 { padding-right: 0px; padding-left: 0px;}
.leftcontainer {width:100%; margin: auto; margin-bottom: 5px; border-bottom: 6px solid red; }
.leftcontainer .eventinfo {width:100%; height: 38px; margin-bottom: 5px; border: 1px solid gray; }
.leftcontainer .eventinfo .split { height: 17px; }
.leftcontainer .eventinfo .split span { font-size: 12px; }
.leftcontainer .banner {width: 100%; height: 75px; border: 1px solid gray; margin-bottom: 5px; }
I can not understand why both side menu's are filling just the height of their own content instead of filling height of the parent div. Is there something I'm doing wrong? It fills fine if I dont add !DOCTYPE html to my project, but from what I understand its bad solution so I should find other way around..
Best regards

http://jsfiddle.net/zntxaspd/6/
Add display: flex;to .row.content:
.row.content { height: 100%; width:70%; margin: auto; display: flex; }
Add flex: 1; to .sidebar:
.sidenav { padding-top: 20px;background-color: #f1f1f1; flex: 1}
Adjust your media query to keep it responsive:
#media screen and (max-width: 767px) {
.sidenav {
height: auto;
padding: 15px;
}
.row.content {height:auto; display: block;}
}

Use bootstrap-4 CSS to achieve the desired result
Bootstrap 4
Also removed the extra row content div
html,
body {
height: 100%;
}
/* Set height of the grid so .sidenav can be 100% (adjust as needed) */
.row.content {
height: 100%;
width: 70%;
margin: auto;
}
/* Set gray background color and 100% height */
.sidenav {
padding-top: 20px;
background-color: #f1f1f1;
height: 100%;
}
/* On small screens, set height to 'auto' for sidenav and grid */
#media screen and (max-width: 767px) {
.sidenav {
height: auto;
padding: 15px;
}
.row.content {
height: auto;
}
}
h5 {
font-size: 14px;
border-bottom: 6px solid red;
font-weight: bold;
}
.rightcontainer {
width: 100%;
height: 100% margin: auto;
border: 0px solid;
border-radius: 4px;
margin-bottom: 5px;
border-bottom: 6px solid red;
}
.rightcontainer .accountpanel .columncontainer .col-sm-6 {
padding-right: 0px;
padding-left: 0px;
}
.leftcontainer {
width: 100%;
margin: auto;
margin-bottom: 5px;
border-bottom: 6px solid red;
}
.leftcontainer .eventinfo {
width: 100%;
height: 38px;
margin-bottom: 5px;
border: 1px solid gray;
}
.leftcontainer .eventinfo .split {
height: 17px;
}
.leftcontainer .eventinfo .split span {
font-size: 12px;
}
.leftcontainer .banner {
width: 100%;
height: 75px;
border: 1px solid gray;
margin-bottom: 5px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<div class="container-fluid text-center">
<div class="row justify-content-center">
<div class="col-sm-2 sidenav">
<div class="leftcontainer">
<div class="banner"> Get Client Banner </div>
<div class="banner"> Guides Banner </div>
<h5> Event Schedule </h5>
<div class="eventinfo">
<div class="split"><span><strong>Bl</strong></span></div>
<div class="split"><span>0 D 0</span></div>
</div>
<div class="eventinfo">
<div class="split"><span><strong>Bl</strong></span></div>
<div class="split"><span>0 D 0</span></div>
</div>
<div class="eventinfo">
<div class="split"><span><strong>Bl</strong></span></div>
<div class="split"><span>0 D 0 H</span></div>
</div>
<div class="eventinfo">
<div class="split"><span><strong>Bl</strong></span></div>
<div class="split"><span>0 D 0 Hr</span></div>
</div>
<div class="eventinfo">
<div class="split"><span><strong>Bl</strong></span></div>
<div class="split"><span>0 D 0 Hr n</span></div>
</div>
<div class="eventinfo">
<div class="split"><span><strong>B</strong></span></div>
<div class="split"><span>0 D 0 </span></div>
</div>
<div class="eventinfo">
<div class="split"><span><strong>Bl</strong></span></div>
<div class="split"><span>0 D 0</span></div>
</div>
<div class="eventinfo">
<div class="split"><span><strong>Bl</strong></span></div>
<div class="split"><span>0 D 0 </span></div>
</div>
</div>
</div>
<div class="col-sm-7 text-left">
<h1>Welcome</h1>
<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. Excepteur sint
occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum 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>
<hr>
<h3>Test</h3>
<p>Lorem ipsum...</p>
</div>
<div class="col-sm-3 sidenav">
<div class="well">
<p>ADS</p>
</div>
<div class="well">
<p>ADS</p>
</div>
</div>
</div>
</div>

Related

Flex navigation hamburger pushing Flex content when expanded

I have created a web page using flexbox and have included a responsive flex-navigation bar. However, when the hamburger is expanded it pushes the rest of the page down with it. I have tried positioning the .active class to absolute on the "display block" and z-index of 10000, but these do not help.I have also tried wrapping the nav inside the row flex container but that ruined the rest of the layout.
Have considered the the js fiddle found at this link:http://jsfiddle.net/hRKgV/ but it does not have a flex box layout and I am wondering if floats are true to the concept of flexbox as it also removes that element from the normal flow of the document?
Any suggestions would be greatful!
Here is the code for the index page:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Flex</title>
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style type="text/css">
* {
box-sizing: border-box;
}
body {
margin: 0;
font-family: Arial;
background-color: #faf6bf;
}
.header {
background-image: url("images/index.jpg");
max-width: 100%;
height: auto;
background-color: #cccccc;
height: 500px;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
position: relative;
box-shadow: 2px 2px 5px purple;
}
.hero-text {
text-align: center;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: white;
font-size: 30px;
}
#media screen and (max-width: 700px) {
h1 {
font-size: 40px;
}
h3 {
font-size: 26px;
}
}
.navbar {
position: relative;
font-size: 18px;
background-color: navy;
border: 1px solid rgba(0, 0, 0, 0.2);
padding-bottom: 10px;
clear: both;
}
.main-nav {
list-style-type: none;
display: none;
}
.nav-links,
.logo {
text-decoration: none;
color: rgba(255, 255, 255, 0.7);
}
.main-nav li {
text-align: center;
margin: 15px auto;
position:
}
.logo {
display: inline-block;
font-size: 22px;
margin-top: 10px;
margin-left: 20px;
}
.navbar-toggle {
position: absolute;
top: 10px;
right: 20px;
cursor: pointer;
color: rgba(255, 255, 255, 0.8);
font-size: 24px;
}
.active {
display: block;
}
#media screen and (min-width: 768px) {
.navbar {
display: flex;
justify-content: space-between;
padding-bottom: 0;
height: 70px;
align-items: center;
}
.main-nav {
display: flex;
margin-right: 30px;
flex-direction: row;
justify-content: flex-end;
}
.nav-links {
margin-left: 40px;
}
.logo {
margin-top: 0;
}
.navbar-toggle {
display: none;
}
.logo:hover,
.nav-links:hover {
color: rgba(255, 255, 255, 1);
}
}
.row {
display: flex;
margin-left: 80px;
margin-right: 80px;
flex-wrap: wrap;
}
.fakeimg {
background-color: #faf6bf;
width: 100%;
padding: 20px;
}
.side {
-webkit-flex: 20%;
-ms-flex: 20%;
flex: 20%;
background-color: orange;
color: white;
padding: 20px;
}
.side2 {
-webkit-flex: 20%;
-ms-flex: 20%;
flex: 20%;
background-color: orange;
color: white;
padding: 50px;
}
.main {
flex: 60%;
background-color: #fffcc7;
padding: 20px;
}
.footer {
background-color: brown;
text-align: center;
color: white;
padding: 20px;
}
#media (max-width: 700px) {
.row {
flex-direction: column;
}
}
</style>
</head>
<body>
<nav class="navbar">
<span class="navbar-toggle" id="js-navbar-toggle">
<i class="fa fa-bars"></i> </span>
logo
<ul class="main-nav" id="js-menu">
<li>
Home
</li>
<li>
Products
</li>
<li>
About Us
</li>
<li>
Contact Us
</li>
<li>
Blog
</li>
</ul>
</nav>
<script type="text/javascript">
let mainNav = document.getElementById('js-menu');
let navBarToggle = document.getElementById('js-navbar-toggle');
navBarToggle.addEventListener('click', function() {
mainNav.classList.toggle('active');
});
</script>
<div class="header">
<div class="hero-text">
<h1>I am Jane Doe</h1>
<h3>And I'm a Photographer</h3>
<button>Hire me</button>
</div>
</div>
<div class="row">
<div class="side">
<h2>About Me</h2>
<h5>Photo of me:</h5>
<div class="fakeimg" style="height:200px;">Image</div>
<p>Some text about me in culpa qui officia deserunt mollit anim..</p>
<h3>More Text</h3>
<p>Lorem ipsum dolor sit ame.</p>
<div class="fakeimg" style="height:60px;">Image</div><br>
<div class="fakeimg" style="height:60px;">Image</div><br>
<div class="fakeimg" style="height:60px;">Image</div>
</div>
<div class="main">
<h2>TITLE HEADING</h2>
<h5>Title description, Dec 7, 2017</h5>
<div class="fakeimg" style="height:200px;">Image</div>
<p>Some text..</p>
<p>Sunt in culpa qui officia deserunt mollit anim id est laborum consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco.</p>
<br>
<h2>TITLE HEADING</h2>
<h5>Title description, Sep 2, 2017</h5>
<div class="fakeimg" style="height:200px;">Image</div>
<p>Some text..</p>
<p>Sunt in culpa qui officia deserunt mollit anim id est laborum consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco.</p>
</div>
<div class="side2">
<h4>follow me on socila media:</h4><br />
<ul>
<li>Link</li>
<li>Link</li>
<li>Link</li>
<li>Link</li>
</ul>
</div>
</div>
<script type="text/javascript">
let mainNav = document.getElementById('js-menu');
let navBarToggle = document.getElementById('js-navbar-toggle');
navBarToggle.addEventListener('click', function() {
mainNav.classList.toggle('active');
});
</script>
<!-- Footer -->
<div class="footer">
<h2>Footer</h2>
</div>
</body>
</html>
Is it something like this you're looking for:
const nav = document.getElementById('navbar');
const navBarToggle = document.getElementById('js-navbar-toggle');
navBarToggle.addEventListener('click', () => {
nav.classList.toggle('active');
});
* {
box-sizing: border-box;
}
body {
margin: 0;
font-family: Arial;
background-color: #faf6bf;
position: relative;
}
.header {
background-image: url("images/index.jpg");
max-width: 100%;
height: auto;
background-color: #cccccc;
height: 500px;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
position: relative;
box-shadow: 2px 2px 5px purple;
}
.hero-text {
text-align: center;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: white;
font-size: 30px;
}
#media screen and (max-width: 700px) {
h1 {
font-size: 40px;
}
h3 {
font-size: 26px;
}
}
.navbar {
position: absolute;
z-index: 10;
width: 100%;
height: 3rem;
font-size: 18px;
background-color: navy;
border: 1px solid rgba(0, 0, 0, 0.2);
padding-bottom: 10px;
clear: both;
overflow: hidden;
transition: height 250ms ease-in;
}
.main-nav {
display: block;
list-style-type: none;
width: 100%;
}
.nav-links,
.logo {
text-decoration: none;
color: rgba(255, 255, 255, 0.7);
}
.main-nav li {
text-align: center;
margin: 15px auto;
}
.logo {
display: inline-block;
font-size: 22px;
margin-top: 10px;
margin-left: 20px;
}
.navbar-toggle {
position: absolute;
top: 10px;
right: 20px;
cursor: pointer;
color: rgba(255, 255, 255, 0.8);
font-size: 24px;
}
.active {
height: 18rem;
}
#media screen and (min-width: 768px) {
.navbar {
display: flex;
justify-content: space-between;
padding-bottom: 0;
height: 60px;
align-items: center;
}
.main-nav {
display: flex;
margin-right: 30px;
flex-direction: row;
justify-content: flex-end;
}
.nav-links {
margin-left: 40px;
}
.logo {
margin-top: 0;
}
.navbar-toggle {
display: none;
}
.logo:hover,
.nav-links:hover {
color: rgba(255, 255, 255, 1);
}
}
.row {
display: flex;
margin-left: 80px;
margin-right: 80px;
flex-wrap: wrap;
}
.fakeimg {
background-color: #faf6bf;
width: 100%;
padding: 20px;
}
.side {
-webkit-flex: 20%;
-ms-flex: 20%;
flex: 20%;
background-color: orange;
color: white;
padding: 20px;
}
.side2 {
-webkit-flex: 20%;
-ms-flex: 20%;
flex: 20%;
background-color: orange;
color: white;
padding: 50px;
}
.main {
flex: 60%;
background-color: #fffcc7;
padding: 20px;
}
.footer {
background-color: brown;
text-align: center;
color: white;
padding: 20px;
}
#media (max-width: 700px) {
.row {
flex-direction: column;
}
}
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
<nav class="navbar" id="navbar">
<span class="navbar-toggle" id="js-navbar-toggle">
<i class="fa fa-bars"></i> </span>
logo
<ul class="main-nav" id="js-menu">
<li>
Home
</li>
<li>
Products
</li>
<li>
About Us
</li>
<li>
Contact Us
</li>
<li>
Blog
</li>
</ul>
</nav>
<div class="header">
<div class="hero-text">
<h1>I am Jane Doe</h1>
<h3>And I'm a Photographer</h3>
<button>Hire me</button>
</div>
</div>
<div class="row">
<div class="side">
<h2>About Me</h2>
<h5>Photo of me:</h5>
<div class="fakeimg" style="height:200px;">Image</div>
<p>Some text about me in culpa qui officia deserunt mollit anim..</p>
<h3>More Text</h3>
<p>Lorem ipsum dolor sit ame.</p>
<div class="fakeimg" style="height:60px;">Image</div><br>
<div class="fakeimg" style="height:60px;">Image</div><br>
<div class="fakeimg" style="height:60px;">Image</div>
</div>
<div class="main">
<h2>TITLE HEADING</h2>
<h5>Title description, Dec 7, 2017</h5>
<div class="fakeimg" style="height:200px;">Image</div>
<p>Some text..</p>
<p>Sunt in culpa qui officia deserunt mollit anim id est laborum consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco.</p>
<br>
<h2>TITLE HEADING</h2>
<h5>Title description, Sep 2, 2017</h5>
<div class="fakeimg" style="height:200px;">Image</div>
<p>Some text..</p>
<p>Sunt in culpa qui officia deserunt mollit anim id est laborum consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco.</p>
</div>
<div class="side2">
<h4>follow me on socila media:</h4><br />
<ul>
<li>Link</li>
<li>Link</li>
<li>Link</li>
<li>Link</li>
</ul>
</div>
</div>
<!-- Footer -->
<div class="footer">
<h2>Footer</h2>
</div>
</body>
I added a position: absolute; z-index: 10; to the .navbar class (probably a couple other minor changes too to get the snippet running correctly).
Edit
I also added in a transition effect. To do this, I changed how your toggle was working. Now, instead of changing the display attribute of .main-nav it just changes the height of the .navbar. The .active class is now applied to the navbar element.
Let me know if this works for you.

Give different card element specific width size

I am using css grid where I have a card inside a sidebar div that is inside a container dive. I am also using a inner-container div where I put 3 cards. The sidebar div card has proper width but the cards inside the inner-container do not adjust to 200px. How can I give the inner-container cards a specific width.
HTML
<aside class="sidebar">
<h2><b>Latest Blog Post</b></h2>
<div class="card">
<img class="card-image" src="images/christmas.jpeg" alt="christmas-markets" width="100%">
<div class="card-text">
<p>German Christmas Markets</p>
</div>
</div>
</aside>
<article class="main">
<h1>An American Living in Germany</h1>
<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 class=".inner-container">
<div class="card"><img class="card-image" src="images/pubic-transit.jpeg" alt="public-transit" width="100%">
<div class="card-text">
<p>Public Transit</p>
</div></div>
<div class="card"><img class="card-image" src="images/rothenburg.jpeg" alt="christmas-markets" width="100%">
<div class="card-text">
<p>Rothenburg ob der Tauber</p>
</div></div>
<div class="card"><img class="card-image" src="images/black-forest.jpeg" alt="public-transit" width="100%">
<div class="card-text">
<p>The Black Forest</p>
</div></div>
</div>
</article>
CSS
.card {
box-shadow: 0 8px 8px 8px rgba(0,0,0,0.2);
transition: 0.3s;
width: 90%;
height: auto;
border-radius: 5px;
margin-top: 20px;
}
.card-text {
padding: 2px;
margin-left: 5px;
margin-bottom: 2px;
margin-top: 5px;
line-height: .5em;
}
.card-text a {
color: crimson;
font-size: 1.2em;
}
.card-image {
width: 100%;
bottom: 0px;
}
.inner-container {
height: 50%;
width: 80%;
display: grid;
grid-template-columns: 200px 200px 200px;
grid-template-rows: 200px 200px 200px;
grid-template-areas:
"b b b";
}
.inner-container div {
grid-area: b;
}
.inner-container .card{
box-shadow: 0 8px 8px 8px rgba(0,0,0,0.2);
transition: 0.3s;
width: 200px;
height: auto;
border-radius: 5px;
margin-top: 20px;
}
.inner-container .card-text {
padding: 2px;
margin-left: 5px;
margin-bottom: 2px;
margin-top: 5px;
line-height: .5em;
}
.inner-container .card-text a {
color: crimson;
font-size: 1.2em;
}
.inner-container .card-image {
width: 100%;
bottom: 0px;
}
You've got a typo in your code which is why CSS isn't firing for that class.
<div class=".inner-container">
should be
<div class="inner-container">
Also took the liberty of adding grid-area:auto; to css to make it render properly for you:
Working fiddle: https://jsfiddle.net/ne6vrwyq/
.card {
box-shadow: 0 8px 8px 8px rgba(0,0,0,0.2);
transition: 0.3s;
width: 90%;
height: auto;
border-radius: 5px;
margin-top: 20px;
}
.card-text {
padding: 2px;
margin-left: 5px;
margin-bottom: 2px;
margin-top: 5px;
line-height: .5em;
}
.card-text a {
color: crimson;
font-size: 1.2em;
}
.card-image {
width: 100%;
bottom: 0px;
}
.inner-container {
height: 50%;
width: 80%;
display: grid;
grid-template-columns: 200px 200px 200px;
grid-template-rows: 200px 200px 200px;
grid-template-areas:
"b b b";
}
.inner-container div {
grid-area: b;
}
.inner-container .card{
box-shadow: 0 8px 8px 8px rgba(0,0,0,0.2);
transition: 0.3s;
width: 200px;
height: auto;
border-radius: 5px;
margin-top: 20px;
grid-area: auto;
}
.inner-container .card-text {
padding: 2px;
margin-left: 5px;
margin-bottom: 2px;
margin-top: 5px;
line-height: .5em;
}
.inner-container .card-text a {
color: crimson;
font-size: 1.2em;
}
.inner-container .card-image {
width: 100%;
bottom: 0px;
}
<aside class="sidebar">
<h2><b>Latest Blog Post</b></h2>
<div class="card">
<img class="card-image" src="images/christmas.jpeg" alt="christmas-markets" width="100%">
<div class="card-text">
<p>German Christmas Markets</p>
</div>
</div>
</aside>
<article class="main">
<h1>An American Living in Germany</h1>
<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 class="inner-container">
<div class="card"><img class="card-image" src="images/pubic-transit.jpeg" alt="public-transit" width="100%">
<div class="card-text">
<p>Public Transit</p>
</div></div>
<div class="card"><img class="card-image" src="images/rothenburg.jpeg" alt="christmas-markets" width="100%">
<div class="card-text">
<p>Rothenburg ob der Tauber</p>
</div></div>
<div class="card"><img class="card-image" src="images/black-forest.jpeg" alt="public-transit" width="100%">
<div class="card-text">
<p>The Black Forest</p>
</div></div>
</div>
</article>

Creating a responsive horizontal content thumbnail with Bootstrap

I'm having a problem creating a responsive "card" similar to the Custom Content Thumbnail in Bootstrap but horizontal. The main problem is that I want the image to be a square and 100% of the height of the card. Also, I want all the cards to have the same width and height.
This is my work so far:
body {
background-color:#ededed;
font-family:"Segoe UI";
}
/*----------2.Headings & Buttons----------*/
h3 {
font-size:1.2em;
font-weight:600;
text-transform:capitalize;
margin:0 0 10px 0;
padding:0;
color:#555555;
}
.btn-styled {
background-color:transparent;
border:#666666 1.9px solid;
color:#666666;
font-size:0.85em;
border-radius:30px;
padding:5px 13px 4px 13px;
margin:10px 0 10px 0;
}
.btn-styled:hover, .btn-styled:active {
background-color:#ededed;
border-color:#ededed;
color:#555555;
}
.btn-styled:focus {
outline:0 !important;
}
/*----------3.Cards----------*/
.card {
position: relative;
margin:2% 5px 2% 5px;
background-color: #fff;
transition: box-shadow .25s;
border-radius: 2px;
box-shadow: 0 2px 5px 0 rgba(0,0,0,0.16),0 2px 10px 0 rgba(0,0,0,0.12);
padding:0;
min-width:400px;
max-width:500px;
}
.card .card-image img {
display: block;
border-radius: 2px 2px 0 0;
position: relative;
left: 0;
right: 0;
top: 0;
bottom: 0;
width: 100%;
}
.card .card-content {
padding: 15px 10px 0 0;
border-radius: 0 0 2px 2px;
}
.card .card-content p {
margin:0;
font-size:1.45rem;
color: #555555;
}
/*----3.a.Horizontal----*/
.card.horizontal .card-image img {
height:100px;
width:100px;
}
.card.horizontal {
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
}
.card.horizontal.small .card-image,
.card.horizontal.medium .card-image,
.card.horizontal.large .card-image {
height: 100%;
max-height: none;
overflow: visible;
}
.card.horizontal .card-image img {
width:150px;
height:150px;
margin-right:20px;
}
.card.horizontal .card-stacked {
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
-webkit-flex: 1;
-ms-flex: 1;
flex: 1;
position: relative;
}
.card.horizontal .card-stacked .card-content {
-webkit-flex-grow: 1;
-ms-flex-positive: 1;
flex-grow: 1;
}
.card .card-image {
position: relative;
}
<head>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-5 col-md-offset-1">
<h3>MAIN TITLE</h3>
</div>
</div>
<div class="row">
<div class="col-md-offset-1 col-md-5 col-xs-12">
<div class="card horizontal">
<div class="card-image">
<img src="https://upload.wikimedia.org/wikipedia/en/thumb/f/ff/Morning_Glory_Flower_square.jpg/1024px-Morning_Glory_Flower_square.jpg">
</div>
<div class="card-stacked">
<div class="card-content">
<h3>Title Goes Here</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed doeiusmod tempor incididunt.</p>
<button class="btn btn-styled">START COPY</button>
</div>
</div>
</div>
</div>
<div class="col-md-offset-1 col-md-5 col-xs-12">
<div class="card horizontal">
<div class="card-image">
<img src="https://upload.wikimedia.org/wikipedia/en/thumb/f/ff/Morning_Glory_Flower_square.jpg/1024px-Morning_Glory_Flower_square.jpg">
</div>
<div class="card-stacked">
<div class="card-content">
<h3>Title Goes Here</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed doeiusmod tempor incididunt.</p>
<button class="btn btn-styled">START COPY</button>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
Also, I made an example of how the cards should look in a grid:
When I tried to create this cards they were not responsive. On different screen widths the left-right-margin was too big or they were on top of each other.
Can someone help get started or give me some ideas how I should do it?
Thanks in advance.
use bootstrap. Ihave provided a demo link just experiment with the code and read the documentation of bootstrap to get better understanding
Here is your Demo Link
Html Code
<div class="container">
<div class="col-md-4">
<div class="card">
<div class="image pull-left">
</div>
<div class="content pull-left">
<h4>
Title Goes Here
</h4> 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.
<br>
<button class="btn btn-default btn-read">
Read more
</button>
</div>
<div class="clearfix">
</div>
</div>
</div>
</div>
Css code
.card {
background: #fff;
display: inline-block;
border: 1px solid #ddd;
}
.image {
float: left;
background: #000;
width: 25%;
height: 150px
}
.content {
float: left;
height: 140px;
width: 73%;
overflow: hidden;
padding: 5px;
}
.content h4 {
margin: 5px 0;
}

CSS how to translate an image up, and have the div adjust to the new size?

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/

Cannot make html page responsive using bootstrap

I am trying to make two sections called, get started and about us responsive, and I am a beginner at using bootstrap so I am making some mistakes.
I tried to make the get started section work, but the buttons are not responsive at all. The about us section, I used 2 images for laptop and cellphone but even that is creating some problems as the margin doesn't stay the same for picture and image, so need help.
HTML Code:
<section class="cont_1">
<div class="container">
<h2>Get started!</h2>
<div class="row">
<div class="col-md-7">
<p>Now that you now the process it's time to check out recent offer.
it only take 5 min to get ypur loan or invest</p>
</div>
<div class="col-md-1"></div>
<div class="col-xs-6 col-md-2 borrow"> Borrow </div>
<div class="col-xs-6 col-md-2 borrow"> <a style="background-color:#fff; color:#66cccc; border: 1px solid #66cccc;" href="#">invest</a> </div>
</div>
</div>
</section>
<section class="about">
<div class="container">
<div class="row">
<div class="col-md-6">
<div class="about_tx">
<h4>About Us</h4>
<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. 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-md-6"> <img src="img/corporate3.jpg"> </div>
</div>
</div>
<div class="about_tx"> <img src="img/corporate3.jpg"> </div>
</section>
CSS:
.cont_1 {
float: left;
width: 100%;
color: #676767;
padding: 82px 0px;
border-bottom: 2px solid #eeeeee;
border-top: 2px solid #eeeeee;
}
.cont_1 h2 {
font-family: 'Lato', Helvetica, Arial, sans-serif;
font-size: 25px;
font-weight: 600;
}
.cont_1 .col-md-7 p {
font-family: 'Lato', Helvetica, Arial, sans-serif;
font-size: 23px;
}
/*.cont_1 .col-md-2 a{font-family: 'Lato', Helvetica, Arial, sans-serif; font-size:28px;background:#66cccc; color:#FFF;padding:14px 30px 17px 37px; display:block; margin-bottom:10px;}
.cont_1 .col-md-2:last-child a {background: #fff; border: 1px solid #66cccc; color: #66cccc; display:block;}*/
.cont_1 .col-md-2 a {
font-family: 'Lato', Helvetica, Arial, sans-serif;
font-size: 28px;
background: #66cccc;
color: #FFF;
padding: 6px 40px;
float: left;
margin-bottom: 10px;
text-transform: capitalize;
border: 1px solid #fff;
}
.cont_1 .col-md-2 a:hover {
background: #fff;
border: 1px solid #66cccc;
color: #66cccc;
}
/******************************
*******************************
*********ABOUT US***************
*******************************
******************************/
.about {
float: left;
position: relative;
width: 100%;
}
.about_tx {
width: 100%;
float: left;
text-align: left;
margin-bottom: 25px;
}
.about_tx h4 {
font-family: 'Lato', Helvetica, Arial, sans-serif;
font-size: 25px;
color: #666;
font-weight: 600;
margin-top: 45px;
margin-bottom: 35px;
}
.about_tx p {
font-family: 'Lato', Helvetica, Arial, sans-serif;
font-size: 18px;
color: #666;
font-weight: 400;
margin: 0;
}
.about_tx img {
width: 100%;
height:80%;
float: left;
}
.about_tx img:last-child {
margin-top: 113px;
}
.about img {
bottom: 0;
position: absolute;
right: 0;
width: 49%;
}
.about .col-md-6 img {
display: none;
}
/******************************
*******************************
*********RESPONSIVE DIV********
*******************************
******************************/
#media only screen and (max-width: 1024px) {
.borrow {
width: auto;
padding: 0;
}
}
#media only screen and (max-width: 992px) {
.about img {
display: none;
}
.about .col-md-6 img {
display: block;
float: left;
position: relative;
width: 100%;
}
}
#media only screen and (max-width: 980px) {
.col-md-2 > a {
display: block;
margin: 0 10px 0 0;
}
}
#media only screen and (max-width: 768px) {
.copy_tx p {
text-align: center;
}
.sm {
text-align: center;
}
}
#media only screen and (max-width: 480px) {
}
#media only screen and (max-width: 320px) {
.cont_1 .col-md-2 a {
padding: 6px 25px;
}
}
If there is a very easy way of making it responsive with just bootstrap classes please do help me out, and is it possible using just one image and making it responsive for about us? And the files are also attached if you want to take a look at it.File
Try replacing your section (cont_1) by below:
<section class="cont_1">
<div class="container">
<h2>Get started!</h2>
<div class="row">
<div class="col-md-12">
<div class="col-md-7">
<p>Now that you now the process it's time to check out recent offer.
it only take 5 min to get ypur loan or invest</p>
</div>
<div class="col-md-2 borrow"> Borrow </div>
<div class="col-md-2 borrow"> <a style="background-color:#fff; color:#66cccc; border: 1px solid #66cccc;" href="#">invest</a> </div>
</div>
</div>
</div>
</section>