I'm using the table method to centre multiple lines of text in a table cell. But despite following multiple SO posts and other online guides, I'm unable to centre the text.
What I want is to centre the text inside the grey part of the divs background (see image below), then when I resize the browser, I want it to span across the entire width of the div (but that's a future problem). For now, can someone take a long at my CSS code (maybe it's the HTML code setup) and tell me why it isn't centring?
HTML
<div id = "about">
<div id = "header">
<h3>About.</h3>
<div id = "about-background">
<div id = "about-text" class="left-grid">
<p>Lorem ipsum dolor sit amet, malesuada magna, justo nisl consectetuer diam litora enim. Faucibus at aenean vitae, tristique curabitur sed tempus ligula, quam pellentesque in dui pede cras, nonummy feugiat justo tempor condimentum tincidunt. A cursus facilisi sed, sem magna, pharetra facilisis vestibulum pellentesque repellat turpis. Nam phasellus, purus ut magna amet. Sit adipiscing duis eget hendrerit, nec egestas magna a odio augue sapien, magna a elementum rutrum placerat mauris, sed in.</p>
</div>
</div>
</div>
</div>
CSS
#about #header {
padding: 10px 0px;
text-align: center;
font-size: 36px;
}
#about-background {
height: 525px;
background: linear-gradient(90deg, #bbc6cb 50%, #ffffff 50%);
}
#about-text {
font-family: Quicksand;
font-size: 22px;
line-height: 35px;
font-weight: 300;
width: 45%;
display: table;
}
#about-text p {
display: table-cell;
text-align: center;
vertical-align: middle;
}
#about #header {
padding: 10px 0px;
text-align: center;
font-size: 36px;
}
#about-background {
height: 525px;
background: lightgrey;
display: table;
}
#about-text {
font-family: Quicksand;
font-size: 18px;
line-height: 35px;
font-weight: 300;
width: 45%;
margin: 0 auto;
display: table-cell;
text-align: center;
vertical-align: middle;
}
<div id = "about">
<div id = "header">
<h3>About.</h3>
<div id = "about-background">
<div id = "about-text">
<p>Lorem ipsum dolor sit amet, malesuada magna, justo nisl consectetuer diam litora enim. Faucibus at aenean vitae, tristique curabitur sed tempus ligula, quam pellentesque in dui pede cras, nonummy feugiat justo tempor condimentum tincidunt. A cursus facilisi sed, sem magna, pharetra facilisis vestibulum pellentesque repellat turpis. </p>
</div>
</div>
</div>
</div>
The width property in #about-text is causing your text to be only shown at 45% of the page. Once you remove that and increase your background length to 100% it will be centered.
#about #header {
padding: 10px 0px;
text-align: center;
font-size: 36px;
}
#about-background {
margin: auto;
background: linear-gradient(90deg, #bbc6cb 100%, #ffffff 100%);
}
#about-text {
font-family: Quicksand;
font-size: 22px;
line-height: 35px;
font-weight: 300;
display: table;
}
#about-text p {
display: table-cell;
text-align: center;
}
<div id = "about">
<div id = "header">
<h3>About.</h3>
<div id = "about-background">
<div id = "about-text" class="left-grid">
<p >Lorem ipsum dolor sit amet, malesuada magna, justo nisl consectetuer diam litora enim. Faucibus at aenean vitae, tristique curabitur sed tempus ligula, quam pellentesque in dui pede cras, nonummy feugiat justo tempor condimentum tincidunt. A cursus facilisi sed, sem magna, pharetra facilisis vestibulum pellentesque repellat turpis. Nam phasellus, purus ut magna amet. Sit adipiscing duis eget hendrerit, nec egestas magna a odio augue sapien, magna a elementum rutrum placerat mauris, sed in.</p>
</div>
</div>
</div>
</div>
Related
I want the containers to stick while you scroll down the page, but when I add "position:fixed" it breaks the layout for some reason, making everything go over to the left. i added the code with position:fixed added to the containers, and here's an example of what it's supposed to look like without:
enter image description here
body {
font-family: arial;
background: #222;
}
img {
width: 100%;
display: block;
}
#wrapper {
width: 1000px;
margin: 100px 0 100px 0;
}
#container_left {
border: 1px solid red;
background: #fff;
font-size: 14;
width: 150px;
height: auto;
text-align: center;
float: left;
position: fixed;
}
.post {
border: 1px solid red;
background: #fff;
font-size: 20px;
padding: 10px;
width: 500px;
height: auto;
text-align: center;
float: left;
margin: 0 80px 0 80px;
}
#container_right {
border: 1px solid red;
background: #fff;
font-size: 14;
width: 150px;
height: auto;
text-align: center;
float: left;
position: fixed;
}
.text_container {
border: 1px solid red;
margin: 10px 10px 10px 10px;
}
.text {
vertical-align: bottom;
}
.text p {
margin: 0;
}
<body>
<div align="center">
<div id="wrapper">
<div id="container_left">
<div class="text_container">
<div class="text">
{block:Description}
<div
style="height:auto;max-height:112px;overflow:auto;scrollbar-width:thin;padding:0 3px 0 3px;">
{text:Description}</div>
{/block:Description}
</div> <!-- text -->
</div> <!-- text container -->
</div> <!-- container left -->
<div class="post">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et
dolore magna aliqua. Pellentesque habitant morbi tristique senectus et netus. Viverra suspendisse
potenti nullam ac tortor vitae purus. In metus vulputate eu scelerisque felis. Odio morbi quis commodo
odio aenean sed. Amet consectetur adipiscing elit duis. Eget arcu dictum varius duis at consectetur
lorem. Mattis rhoncus urna neque viverra justo nec ultrices dui sapien. Mollis nunc sed id semper.
Bibendum arcu vitae elementum curabitur vitae nunc sed. Nibh tellus molestie nunc non blandit massa enim
nec. Id donec ultrices tincidunt arcu. Adipiscing tristique risus nec feugiat in fermentum. Pretium quam
vulputate dignissim suspendisse in est ante. Tincidunt ornare massa eget egestas purus viverra accumsan
in. Suspendisse faucibus interdum posuere lorem ipsum dolor sit amet. Tellus at urna condimentum mattis
pellentesque id nibh tortor id. Morbi tristique senectus et netus et malesuada fames ac. Amet facilisis
magna etiam tempor orci eu. Ut tellus elementum sagittis vitae et leo duis ut diam.
</div> <!-- post -->
<div id="container_right">
<div class="text_container">
<div class="text">
<div
style="height:auto;max-height:112px;overflow:auto;scrollbar-width:thin;padding:0 3px 0 3px;">
{text:Extra Box}</div>
</div> <!-- text -->
</div> <!-- text container -->
</div> <!-- container right -->
</div> <!-- wrapper -->
</div> <!-- center -->
</body>
I have found some issues and have fixed that. Some points that I have noticed are.
Specify right/left with bottom/top values for fixed positioned elements to make them fixed at a position.
Use margin: 0 auto inorder to align the center portion.
Never make use of float along with margin: 0 auto. Using float will prevent margin: 0 auto from its desired behaviour.
Hope this is helpful.
body {
font-family: arial;
background: #222;
}
img {
width: 100%;
display: block;
}
#wrapper {
/* width: 1000px;
margin: 100px 0 100px 0; */
width: 100%; /* Use your desired width*/
}
#container_left {
border: 1px solid red;
background: #fff;
font-size: 14;
width: 150px;
height: auto;
text-align: center;
position: fixed;
left: 0;
top: 0;
}
.post {
border: 1px solid red;
background: #fff;
font-size: 20px;
padding: 10px;
width: 500px;
height: auto;
text-align: center;
/* float: left; :Using float will break the margin:0 auto to break*/
margin: 0 auto;
}
#container_right {
border: 1px solid red;
background: #fff;
font-size: 14;
width: 150px;
height: auto;
text-align: center;
/* float: left; :Using float will break the margin:0 auto to break*/
position: fixed;
right: 0;
top: 0;
}
.text_container {
border: 1px solid red;
margin: 10px 10px 10px 10px;
}
.text {
vertical-align: bottom;
}
.text p {
margin: 0;
}
<body>
<div align="center">
<div id="wrapper">
<div id="container_left">
<div class="text_container">
<div class="text">
{block:Description}
<div
style="height:auto;max-height:112px;overflow:auto;scrollbar-width:thin;padding:0 3px 0 3px;">
{text:Description}</div>
{/block:Description}
</div> <!-- text -->
</div> <!-- text container -->
</div> <!-- container left -->
<div class="post">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et
dolore magna aliqua. Pellentesque habitant morbi tristique senectus et netus. Viverra suspendisse
potenti nullam ac tortor vitae purus. In metus vulputate eu scelerisque felis. Odio morbi quis commodo
odio aenean sed. Amet consectetur adipiscing elit duis. Eget arcu dictum varius duis at consectetur
lorem. Mattis rhoncus urna neque viverra justo nec ultrices dui sapien. Mollis nunc sed id semper.
Bibendum arcu vitae elementum curabitur vitae nunc sed. Nibh tellus molestie nunc non blandit massa enim
nec. Id donec ultrices tincidunt arcu. Adipiscing tristique risus nec feugiat in fermentum. Pretium quam
vulputate dignissim suspendisse in est ante. Tincidunt ornare massa eget egestas purus viverra accumsan
in. Suspendisse faucibus interdum posuere lorem ipsum dolor sit amet. Tellus at urna condimentum mattis
pellentesque id nibh tortor id. Morbi tristique senectus et netus et malesuada fames ac. Amet facilisis
magna etiam tempor orci eu. Ut tellus elementum sagittis vitae et leo duis ut diam.
</div> <!-- post -->
<div id="container_right">
<div class="text_container">
<div class="text">
<div
style="height:auto;max-height:112px;overflow:auto;scrollbar-width:thin;padding:0 3px 0 3px;">
{text:Extra Box}</div>
</div> <!-- text -->
</div> <!-- text container -->
</div> <!-- container right -->
</div> <!-- wrapper -->
</div> <!-- center -->
</body>
Want to get rid of this positioning overheads? Go for flex. its just awesome. Here is a sample implementation for your question.
body {
font-family: arial;
background: #222;
overflow: hidden;
}
img {
width: 100%;
display: block;
}
#wrapper {
width: 100%;
display: flex;
}
#container_left {
border: 1px solid red;
background: #fff;
font-size: 14;
/* width: 150px; */
/* height: auto; */
text-align: center;
}
.post {
border: 1px solid red;
background: #fff;
font-size: 20px;
padding: 10px;
/* width: 500px; */
height: auto;
text-align: center;
margin: 0 auto;
max-height: 100vh;
overflow: auto;
box-sizing: border-box;
}
#container_right {
border: 1px solid red;
background: #fff;
font-size: 14;
/* width: 150px; */
/* height: auto; */
text-align: center;
}
.text_container {
border: 1px solid red;
margin: 10px 10px 10px 10px;
}
.text {
vertical-align: bottom;
}
.text p {
margin: 0;
}
<body>
<div align="center">
<div id="wrapper">
<div>
<div id="container_left">
<div class="text_container">
<div class="text">
{block:Description}
<div
style="height:auto;max-height:112px;overflow:auto;scrollbar-width:thin;padding:0 3px 0 3px;">
{text:Description}</div>
{/block:Description}
</div> <!-- text -->
</div> <!-- text container -->
</div> <!-- container left -->
</div>
<div class="post">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et
dolore magna aliqua. Pellentesque habitant morbi tristique senectus et netus. Viverra suspendisse
potenti nullam ac tortor vitae purus. In metus vulputate eu scelerisque felis. Odio morbi quis commodo
odio aenean sed. Amet consectetur adipiscing elit duis. Eget arcu dictum varius duis at consectetur
lorem. Mattis rhoncus urna neque viverra justo nec ultrices dui sapien. Mollis nunc sed id semper.
Bibendum arcu vitae elementum curabitur vitae nunc sed. Nibh tellus molestie nunc non blandit massa enim
nec. Id donec ultrices tincidunt arcu. Adipiscing tristique risus nec feugiat in fermentum. Pretium quam
vulputate dignissim suspendisse in est ante. Tincidunt ornare massa eget egestas purus viverra accumsan
in. Suspendisse faucibus interdum posuere lorem ipsum dolor sit amet. Tellus at urna condimentum mattis
pellentesque id nibh tortor id. Morbi tristique senectus et netus et malesuada fames ac. Amet facilisis
magna etiam tempor orci eu. Ut tellus elementum sagittis vitae et leo duis ut diam.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et
dolore magna aliqua. Pellentesque habitant morbi tristique senectus et netus. Viverra suspendisse
potenti nullam ac tortor vitae purus. In metus vulputate eu scelerisque felis. Odio morbi quis commodo
odio aenean sed. Amet consectetur adipiscing elit duis. Eget arcu dictum varius duis at consectetur
lorem. Mattis rhoncus urna neque viverra justo nec ultrices dui sapien. Mollis nunc sed id semper.
Bibendum arcu vitae elementum curabitur vitae nunc sed. Nibh tellus molestie nunc non blandit massa enim
nec. Id donec ultrices tincidunt arcu. Adipiscing tristique risus nec feugiat in fermentum. Pretium quam
vulputate dignissim suspendisse in est ante. Tincidunt ornare massa eget egestas purus viverra accumsan
in. Suspendisse faucibus interdum posuere lorem ipsum dolor sit amet. Tellus at urna condimentum mattis
pellentesque id nibh tortor id. Morbi tristique senectus et netus et malesuada fames ac. Amet facilisis
magna etiam tempor orci eu. Ut tellus elementum sagittis vitae et leo duis ut diam.
</div> <!-- post -->
<div>
<div id="container_right">
<div class="text_container">
<div class="text">
<div
style="height:auto;max-height:112px;overflow:auto;scrollbar-width:thin;padding:0 3px 0 3px;">
{text:Extra Box}</div>
</div> <!-- text -->
</div> <!-- text container -->
</div> <!-- container right -->
</div>
</div> <!-- wrapper -->
</div> <!-- center -->
</body>
With position fixed you need to set a left/right property instead of a float.
Try changing the right container to the code below and then adjust your other css accordingly:
#container_right {
border:1px solid red;
background:#fff;
font-size:14;
width:150px;
height:auto;
text-align:center;
position:fixed;
right: 10px;
}
This is happening right now: The footer text is weirdly aligned (text-align is on center here, text-align left puts it slightly left of the center and text-align right works properly.
I also tried display: table-cell which aligns my text properly but puts the footer itself in an awkward spot and it cant be moved using margins.
Here's my (related) code:
.footer {
display: table-cell;
background-color: aqua;
width: 1000px;
max-width: 1000px;
margin: auto;
border: 5px solid #ccc;
margin-top: 30px;
line-height: 12px;
text-align: center;
}
<footer>
<div class="footer">
<h2>Footer stuff</h2>
</div>
</footer>
Hopefully this is all you need I prefer to keep my post as short as possible, tell me if you need more and thanks in advance for any help.
EDIT: My entire code
Body {
background-color: darkred;
}
.header {
text-align: center;
width: 100%;
}
#navbar {
width: 100%;
float: left;
margin: 0 0 3em 0;
padding: 0;
list-style: none;
background-color: darkblue;
border-bottom: 1px solid #ccc;
border-top: 1px solid #ccc;
}
#navbar li {
float: left;
}
#navbar li a {
display: block;
padding: 8px 160px;
font-weight: bold;
color: white;
border-right: 1px solid #ccc;
}
#navbar li a:hover {
color: #c00;
background-color: #fff;
}
.container {
background-color: aqua;
width: 100%;
max-width: 1000px;
margin-top: 50px;
margin-bottom: auto;
margin-right: auto;
margin-left: auto;
border: 5px solid #ccc;
text-align: center;
height: 100%; /* BE ADVISED! (????) */
}
#ipsumpic1 {
width: 150px;
float: right;
}
#ipsumpic2 {
width: 100px;
float: left;
}
#sidebarleft {
margin: 0px auto;
position: relative;
left: 1000px;
padding-top: 0px;
width: 240px;
float: left;
border: 5px solid #ccc;
background-color: aqua;
margin-top: -350px;
}
#sidebarright {
padding-top: 0px;
width: 240px;
float: right;
border: 5px solid #ccc;
background-color: aqua;
margin-top: -537px;
margin-right: 1100px;
}
.footer {
display: table;
background-color: aqua;
width: 1000px;
max-width: 1000px;
margin: auto;
border: 5px solid #ccc;
margin-top: 30px;
line-height: 12px;
text-align: center;
}
<!DOCTYPE html>
<html>
<head>
<title>Prachtige website</title>
<meta charset="utf-8">
<link rel="Stylesheet"type="text/css" href="css/style.css">
<script type=text/javascript src="script.js"></script>
</head>
<body>
<header>
<div class="header">
<img src="img/logo.svg" width="200">
</div>
</header>
<ul id="navbar">
<li>Home</li>
<li>Producten</li>
<li>Diensten</li>
<li>Over Ons</li>
<li>Contact</li>
</ul>
<div class="container">
<main>
<h1>Lorem Ipsum</h1>
<img id="ipsumpic1" src="img/ipsum1.svg">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus a pulvinar dolor, a rutrum tortor. Vestibulum auctor finibus odio id efficitur. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Curabitur ullamcorper risus neque, sed vehicula augue finibus sed. Donec pretium ornare libero a venenatis. Donec sed ex id tellus posuere interdum. Nullam tincidunt egestas odio non gravida. Sed ut felis aliquet eros commodo elementum. Aliquam ullamcorper, diam quis aliquet tempor, magna nisi laoreet nisl, at vestibulum arcu enim quis elit. </p>
<img id="ipsumpic2" src="img/ipsum2.svg">
<p>Ut faucibus dui lectus, vitae pharetra magna maximus quis. Donec sollicitudin sem non ornare vulputate. Suspendisse pretium lacus nec gravida tristique. Sed sed nibh et eros facilisis accumsan. Nam mi elit, fermentum eu laoreet vel, venenatis sit amet leo. Curabitur erat arcu, dictum eu massa quis, hendrerit mattis turpis. Etiam ultrices quam dolor, a interdum erat eleifend eu. Cras sed blandit nunc. In dictum dignissim enim, vel gravida nisl sagittis pellentesque. Quisque fermentum pellentesque velit a faucibus. Nulla facilisi. In fermentum, mi id feugiat ultricies, nulla lorem elementum felis, et pretium velit mauris sit amet odio. Curabitur facilisis, mi in eleifend commodo, enim ex dignissim quam, ut pulvinar magna nisl et orci. Duis pulvinar imperdiet pretium. Nullam vehicula tortor in ex volutpat egestas. </p>
</main>
<div id="sidebarleft">
<aside>
<h2>Nieuw nieuws!</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed velit leo, finibus sed risus eget, semper molestie lacus. Integer dictum laoreet erat a facilisis. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Vestibulum luctus diam a est accumsan, eget maximus sem bibendum. Pellentesque efficitur tellus maximus elit egestas bibendum. Cras efficitur enim tortor, a fringilla lacus tristique quis. Pellentesque neque felis, faucibus nec nibh vel, dapibus congue lorem. Sed scelerisque ligula vitae convallis condimentum. Nulla a ante pulvinar, tristique turpis a, sagittis ipsum. Aliquam fringilla convallis justo, eu eleifend quam placerat ac. Fusce sit amet turpis id lacus consectetur sollicitudin. </p>
</aside>
</div>
<div id="sidebarright">
<aside>
<h2>Social media!</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed velit leo, finibus sed risus eget, semper molestie lacus. Integer dictum laoreet erat a facilisis. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Vestibulum luctus diam a est accumsan, eget maximus sem bibendum. Pellentesque efficitur tellus maximus elit egestas bibendum. Cras efficitur enim tortor, a fringilla lacus tristique quis. Pellentesque neque felis, faucibus nec nibh vel, dapibus congue lorem. Sed scelerisque ligula vitae convallis condimentum. Nulla a ante pulvinar, tristique turpis a, sagittis ipsum. Aliquam fringilla convallis justo, eu eleifend quam placerat ac. Fusce sit amet turpis id lacus consectetur sollicitudin.</p>
</aside>
</div>
</div>
<footer>
<div class="footer">
<h2>Footer stuff</h2>
</div>
</footer>
</body>
</html>
Apply table to parent (.footer) and table-cell to children (.footer h2)
.footer {
display: table;
background-color: aqua;
width: 100%;
border: 5px solid #ccc;
height: 100px;
}
.footer h2 {
display: table-cell;
vertical-align: middle;
text-align: center;
}
<footer>
<div class="footer">
<h2>Footer stuff</h2>
</div>
</footer>
Solution with flexboxes:
display: flex;
flex-flow: row;
justify-content: center; --> centering horizontally
align-items: center; --> centering vertically
if you use table-cell try:
vertical-align: center;
I need some help to hide the background color of my container div.
The main content area is structure in such a way that the article tags stack on top of each other and then after that the footer should take up whatever space is left.
I have tried to get rid of the space between the article tag and the footer while still keeping the margin. In order words I want to get rid of the blue line while.
Can someone give me a hint of how to achieve this?
#container {
background-color: #004bb8;
min-width: 320px;
max-width: 960px;
}
/*------Header-----*/
header {
background-color: lightsalmon;
border-bottom: solid #65ff09 2px;
}
h1, h2 {
font-family: "Impact";
margin: 0px;
padding: 0px;
color: darkred;
text-align: left;
text-transform: uppercase;
letter-spacing: 4px;
}
#image-container {
float: left;
width: 46%;
margin: 0 1% 0 1%;
padding: 1%;
}
#sitename{
float: left;
width: 46%;
margin: 0 1% 0 1%;
padding: 8% 1% 1% 1%;
}
header::after {
content: "";
display: block;
clear: left;
}
header img {
width: 250px;
margin: 0 auto;
}
header h1 {
font-family: "Abel", sans-serif;
text-transform: uppercase;
font-size: 1.5em;
padding: 10px 10px;
color: #f9db00;
}
header h2 {
font-family: "Abel", sans-serif;
text-transform: uppercase;
font-size: 0.8em;
padding: 10px 10px;
color: #ff2a86;
}
/*-------navigation------*/
nav {
width: 100%;
background-color:
}
nav ul li {}
nav ul li a {
display: block;
text-align: center;
border-radius: 5px;
padding: 0.5em;
margin: .3em;
border: 1px solid #fff;
background-color: #004bb8;
text-decoration: none;
color: #fff;
}
nav ul li.active a {
background-color: #b8005c;
}
nav ul li a:hover {
background-color: #f9db00;
color: #323C40
}
/*-------content------*/
#content {
min-height: 5em;
background-color: #fff;
}
#content article {
margin: 0 2%;
}
#content article.News, #content article.Tweets {
background-color: #ddd;
margin-top: 0.5em;
margin-bottom: 0.5em;
}
article.News h2, article.Tweets h2 {
background-color: darkgray;
color: #fff;
padding: 0.5em;
font-size: 0.8em;
}
article.News h2 {background-color: #004bb8;}
article.Tweets h2 {background-color: #b8005c;}
article.News h3, article.Tweets h3 {
padding: 0.5em 0 0 1%;
font-size: 1.0em;
}
article.News h3 {color: #004bb8;}
article.Tweets h3 {color: #b8005c;}
article.News p, article.Tweets p {
color: #666;
font-size: 0.8em;
padding-left: 1%;
padding-right: 1%;
line-height: 120%;
}
#contents article.Tweets::after {
content: "";
display: block;
clear: left;
}
/*-------footer------*/
footer {
clear: both;
text-align: center;
padding: 1em;
background-color: #111;
color: #fff;
font-size: 0.6em;
}
/*---------IMAGES------------*/
figure.w100 {
overflow: hidden;
width: 100%;
}
figure.w33 {
width: 96%;
border: 1px solid #999;
margin: 0.3em 0 0.3em 2%;
}
figure.w33 img {
width: 100%;
}
figure.w100 img {
width: 100%;
}
#content figcaption {
text-align: center;
font-size: 0.6em;
color: #777;
padding: 0.3em;
}
<body>
<div id="wrapper">
<div id="container">
<header>
<div id="image-container">
<img src="img/logo.png" alt="logo">
</div>
<div id="sitename">
<h1>Responsive Design</h1>
<h2>Don't Settle for Less</h2>
</div>
</header>
<!--------Page Navigation Links -->
<nav>
<ul>
<li>Desktop Work Around</li>
<li class="active">Phone-Default</li>
<li>Tablet Enhancement</li>
<li>Reset CSS</li>
</ul>
</nav>
<!--------Page Content -->
<div id="content">
<figure class="w100">
<img src="img/lake.jpeg" alt="lake">
</figure>
<article>
<h2> Lorem Ipsum</h2>
<figure class="w33">
<img src="img/car.jpeg" alt="car">
<figcaption> what i wish to drive when i get super rich</figcaption>
</figure>
<p> Lorem ipsum dolor sit amet, posuere erat quis tellus, pede non maecenas convallis dapibus ut, ipsum arcu facilisi nunc mollis eu risus, fermentum volutpat maecenas convallis etiam, et eget ut aliquet phasellus sagittis metus. Nulla vel wisi a eu in. Diam sociis eros. Aliquet vitae commodo ante, rutrum praesent odio urna pellentesque. Metus viverra volutpat etiam lorem nesciunt, sapien pellentesque, massa nec. Nec congue aliquam a lobortis sed, dui imperdiet vestibulum magnis aenean sed sit, dignissim sem sodales.
</p>
</article>
<div class="row">
<article class="News">
<h2>News</h2>
<h3>A list apart finally goes responsive</h3>
<p> Lorem ipsum dolor sit amet, posuere erat quis tellus, pede non maecenas convallis dapibus ut, ipsum arcu facilisi nunc mollis eu risus, fermentum volutpat maecenas convallis etiam, et eget ut aliquet phasellus sagittis metus. Nulla vel wisi a eu in. Diam sociis eros. Aliquet vitae commodo ante, rutrum praesent odio urna pellentesque. Metus viverra volutpat etiam lorem nesciunt, sapien pellentesque, massa nec. Nec congue aliquam a lobortis sed, dui imperdiet vestibulum magnis aenean sed sit, dignissim sem sodales.
</p>
<h3>A list apart finally goes responsive</h3>
<p> Lorem ipsum dolor sit amet, posuere erat quis tellus, pede non maecenas convallis dapibus ut, ipsum arcu facilisi nunc mollis eu risus, fermentum volutpat maecenas convallis etiam, et eget ut aliquet phasellus sagittis metus. Nulla vel wisi a eu in. Diam sociis eros. Aliquet vitae commodo ante, rutrum praesent odio urna pellentesque. Metus viverra volutpat etiam lorem nesciunt, sapien pellentesque, massa nec. Nec congue aliquam a lobortis sed, dui imperdiet vestibulum magnis aenean sed sit, dignissim sem sodales.
</p>
</article>
<article class="Tweets">
<h2>Tweets</h2>
<h3>A list apart finally goes responsive</h3>
<p> Lorem ipsum dolor sit amet, posuere erat quis tellus, pede non maecenas convallis dapibus ut, ipsum arcu facilisi nunc mollis eu risus, fermentum volutpat maecenas convallis etiam, et eget ut aliquet phasellus sagittis metus. Nulla vel wisi a eu in. Diam sociis eros. Aliquet vitae commodo ante, rutrum praesent odio urna pellentesque. Metus viverra volutpat etiam lorem nesciunt, sapien pellentesque, massa nec. Nec congue aliquam a lobortis sed, dui imperdiet vestibulum magnis aenean sed sit, dignissim sem sodales.
</p>
<h3>A list apart finally goes responsive</h3>
<p> Lorem ipsum dolor sit amet, posuere erat quis tellus, pede non maecenas convallis dapibus ut, ipsum arcu facilisi nunc mollis eu risus, fermentum volutpat maecenas convallis etiam, et eget ut aliquet phasellus sagittis metus. Nulla vel wisi a eu in. Diam sociis eros. Aliquet vitae commodo ante, rutrum praesent odio urna pellentesque. Metus viverra volutpat etiam lorem nesciunt, sapien pellentesque, massa nec. Nec congue aliquam a lobortis sed, dui imperdiet vestibulum magnis aenean sed sit, dignissim sem sodales.
</p>
</article>
</div>
</div>
<!-----End of Content --->
<footer>
<p>© Buko Ogbobe Responsive Start File</p>
</footer>
</div> <!----end of Container ---->
</div> <!----end of Wrapper ---->
</body>
Here's two solutions, you can use :
footer {
margin-top:-13px;
}
or :
#content article.Tweets, article.Tweets p {
margin-bottom:0px;
}
This will fix the gap in between your footer and content.
I'm trying to align a div at the bottom right corner inside a specific column, but all instead it aligns at the bottom right corner of the main parent.
https://jsfiddle.net/jonnijonnason/L9vg468g/
If you check the fiddle, I want it to align beneath the image.
HTML
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width" />
<title>Arbetsprov | Baldvin Haraldsson</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
</head>
<body>
<div class="page">
<div class="row">
<div class="item">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed congue enim sed tristique interdum. Integer id lectus et risus pulvinar ornare. Donec congue tortor non risus ullamcorper vestibulum. Nullam in hendrerit tellus. Vestibulum lorem nulla, maximus non pretium a, tincidunt id quam. Donec quis sollicitudin urna, sed sagittis purus. Pellentesque sapien libero, blandit a nunc in, iaculis viverra ipsum</p>
</div>
<div class="item">
<p>Nullam maximus pretium arcu at sodales. Sed id venenatis ante. Nullam sollicitudin id nisl quis dictum. Duis imperdiet diam at nibh laoreet egestas. Integer volutpat, dolor a pulvinar mollis, nisl lorem hendrerit tortor, sit amet posuere ante odio quis lorem. Vivamus luctus sem quis eros elementum pretium. Sed facilisis sem at velit euismod pretium. Maecenas posuere sapien elit, at accumsan orci pretium non. Suspendisse id sem nisi.</p>
</div>
<div class="item">
<H3>Image</H3>
<img src="https://upload.wikimedia.org/wikipedia/commons/8/88/Stockholm_Port.jpg" width="140px" height = "140px" />
Donec bibendum nibh a odio venenatis, vel ultricies turpis varius. Vestibulum varius sollicitudin rutrum. Nam eleifend ac nisl non aliquet. Donec vel scelerisque sapien. Donec ultrices vel neque ut bibendum. Suspendisse bibendum, ex sed congue dapibus, nibh magna malesuada dolor, at scelerisque dolor ex quis lectus. Curabitur rhoncus elit efficitur hendrerit malesuada. Morbi condimentum convallis laoreet.
<div class = "foo">Read More</div>
</div>
</div>
</div>
</body>
</html>
CSS
#charset "UTF-8";
.item {
width: 33%;
background: rgba(0, 0, 0, 0.1);
display: table-cell;
}
.row {
border: 1px solid red;
display: table;
border-spacing: 20px;
}
.page {
max-width: 900px;
margin: 0px auto 0px auto;
position: relative;
background-color: #fff;
}
img {
float: right;
margin: 0 0 10px 10px;
padding: 10px;
}
.foo {
font-family: Impact, Haettenschweiler, "Franklin Gothic Bold", Charcoal, "Helvetica Inserat", "Bitstream Vera Sans Bold", "Arial Black", "sans serif";
color: #fff;
text-align: center;
vertical-align: middle;
line-height: 50px;
background-color: #4a4a4a;
height: 50px;
width: 162px;
position: absolute;
bottom: 0;
right: 0;
}
Add to <div class="item"> column a position:relative;
The button inside has an absolute position so it is relative to the next parent element with relative (or absolute) positioning.
Also, to make it not overlap the text you can also set padding-bottom
.item.contains-button {
position:relative;
padding-bottom:60px;
}
Your updated JSFiddle
What you need to do is just add Position: relative; to the last column. This will make Read more div to be at bottom right corner of the direct parent DIV instead of the main DIV.
Updated jsFiddle: https://jsfiddle.net/L9vg468g/4/
HTML:
<body>
<div class="page">
<div class="row">
<div class="item">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed congue enim sed tristique interdum. Integer id lectus et risus pulvinar ornare. Donec congue tortor non risus ullamcorper vestibulum. Nullam in hendrerit tellus. Vestibulum lorem nulla, maximus non pretium a, tincidunt id quam. Donec quis sollicitudin urna, sed sagittis purus. Pellentesque sapien libero, blandit a nunc in, iaculis viverra ipsum</p>
</div>
<div class="item">
<p>Nullam maximus pretium arcu at sodales. Sed id venenatis ante. Nullam sollicitudin id nisl quis dictum. Duis imperdiet diam at nibh laoreet egestas. Integer volutpat, dolor a pulvinar mollis, nisl lorem hendrerit tortor, sit amet posuere ante odio quis lorem. Vivamus luctus sem quis eros elementum pretium. Sed facilisis sem at velit euismod pretium. Maecenas posuere sapien elit, at accumsan orci pretium non. Suspendisse id sem nisi.</p>
</div>
<div class="item lastcol">
<H3>Image</H3>
<img src="https://upload.wikimedia.org/wikipedia/commons/8/88/Stockholm_Port.jpg" width="140px" height = "140px" />
Donec bibendum nibh a odio venenatis, vel ultricies turpis varius. Vestibulum varius sollicitudin rutrum. Nam eleifend ac nisl non aliquet. Donec vel scelerisque sapien. Donec ultrices vel neque ut bibendum. Suspendisse bibendum, ex sed congue dapibus, nibh magna malesuada dolor, at scelerisque dolor ex quis lectus. Curabitur rhoncus elit efficitur hendrerit malesuada. Morbi condimentum convallis laoreet.
<div class = "foo">Read More</div>
</div>
</div>
</div>
</body>
CSS:
#charset "UTF-8";
.item {
width: 33%;
background: rgba(0, 0, 0, 0.1);
display: table-cell;
position: relative;
}
.item.lastcol {
position: relative;
}
.row {
border: 1px solid red;
display: table;
border-spacing: 20px;
}
.page {
max-width: 900px;
margin: 0px auto 0px auto;
position: relative;
background-color: #fff;
}
img {
float: right;
margin: 0 0 10px 10px;
padding: 10px;
}
.foo {
font-family: Impact, Haettenschweiler, "Franklin Gothic Bold", Charcoal, "Helvetica Inserat", "Bitstream Vera Sans Bold", "Arial Black", "sans serif";
color: #fff;
text-align: center;
vertical-align: middle;
line-height: 50px;
background-color: #4a4a4a;
height: 50px;
width: 162px;
position: absolute;
bottom: 0;
right: 0;
}
As you have placed other two columns description inside paragraph tag, you can keep third description also inside a paragraph and it can be achievable by using css flexbox if your browser support is IE10 +.
Updated code below.
.item {
width: 33%;
background: rgba(0, 0, 0, 0.1);
display: table-cell;
display: flex;
flex-direction: column;
}
.row {
border: 1px solid red;
display: flex;
flex-direction: row;
flex-wrap: wrap;
border-spacing: 20px;
}
.page {
max-width: 900px;
margin: 0px auto 0px auto;
position: relative;
background-color: #fff;
}
img {
float: right;
margin: 0 0 10px 10px;
padding: 10px;
}
.foo {
font-family: Impact, Haettenschweiler, "Franklin Gothic Bold", Charcoal, "Helvetica Inserat", "Bitstream Vera Sans Bold", "Arial Black", "sans serif";
color: #fff;
text-align: center;
vertical-align: middle;
line-height: 50px;
background-color: #4a4a4a;
height: 50px;
width: 162px;
position: relative;
bottom: 0;
right: 0;
}
.item h3 {
order: 1;
}
.item img {order: 2;}
.item div {order: 3;}
.item p {order: 4;}
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width" />
<title>Arbetsprov | Baldvin Haraldsson</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
</head>
<body>
<div class="page">
<div class="row">
<div class="item">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed congue enim sed tristique interdum. Integer id lectus et risus pulvinar ornare. Donec congue tortor non risus ullamcorper vestibulum. Nullam in hendrerit tellus. Vestibulum lorem nulla, maximus non pretium a, tincidunt id quam. Donec quis sollicitudin urna, sed sagittis purus. Pellentesque sapien libero, blandit a nunc in, iaculis viverra ipsum</p>
</div>
<div class="item">
<p>Nullam maximus pretium arcu at sodales. Sed id venenatis ante. Nullam sollicitudin id nisl quis dictum. Duis imperdiet diam at nibh laoreet egestas. Integer volutpat, dolor a pulvinar mollis, nisl lorem hendrerit tortor, sit amet posuere ante odio quis lorem. Vivamus luctus sem quis eros elementum pretium. Sed facilisis sem at velit euismod pretium. Maecenas posuere sapien elit, at accumsan orci pretium non. Suspendisse id sem nisi.</p>
</div>
<div class="item lastcol">
<H3>Image</H3>
<img src="https://upload.wikimedia.org/wikipedia/commons/8/88/Stockholm_Port.jpg" width="140px" height = "140px" />
<p>Donec bibendum nibh a odio venenatis, vel ultricies turpis varius. Vestibulum varius sollicitudin rutrum. Nam eleifend ac nisl non aliquet. Donec vel scelerisque sapien. Donec ultrices vel neque ut bibendum. Suspendisse bibendum, ex sed congue dapibus, nibh magna malesuada dolor, at scelerisque dolor ex quis lectus. Curabitur rhoncus elit efficitur hendrerit malesuada. Morbi condimentum convallis laoreet.</p>
<div class = "foo">Read More</div>
</div>
</div>
</div>
</body>
</html>
My assignment requires me to have two tags on top of each other. but there is this annoying gap between the two that I would like to get rid of. Between the gap is the background image that does not look good with the rest of the website. Thanks to everyone that can help me.
#profileSection {
margin-top: 300px;
padding-right: 400px;
padding-left: 400px;
background-color: #F5F5F5;
height: auto;
width: 100%:
}
#profileTitle {
display: inline-block;
margin-top: 25px;
font-family: 'Francois One', sans-serif;
text-decoration: underline;
}
#profileDesc {
float: left;
width: 50%;
margin-top: 70px;
font-family: 'Open Sans', sans-serif;
}
#profilePic {
float: right;
margin-top: 70px;
width: 200px;
height: 200px;
}
#mainTitle {
text-align: center;
margin-top: 300px;
}
#skillsSection {
padding-right: 400px;
padding-left: 400px;
background-color: #181818;
}
<section>
<div id="profileSection">
<div class="row">
<div class="col-xs-4 col-sm-8 col-md-12">
<h1 id="profileTitle">About Me</h1>
<p id="profileDesc">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer eu justo quam. Donec et magna ante. Integer ullamcorper sit amet erat a pharetra. Aliquam euismod, mauris sit amet ultricies sodales, purus enim dictum dui, in mattis quam ex non
neque. Suspendisse quis tristique tellus. Vestibulum dignissim eros non arcu sollicitudin, a auctor augue faucibus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Mauris sit amet dui pulvinar, interdum
arcu et, consequat dui. Fusce velit elit, molestie sed tincidunt eget, ornare in nibh. Nunc aliquet dapibus odio sit amet varius. Suspendisse nec ipsum odio. Morbi iaculis velit eget mi tristique dignissim. Donec rutrum gravida ex, vel molestie
sapien condimentum quis. Morbi convallis placerat eros ac volutpat.</p>
<img id="profilePic" src="pics/profilePicture.png" />
</div>
</div>
</div>
</section>
<section>
<div id="skillsSection">
<h1 id="skillsTitle">Skills</h1>
<ul>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>
</div>
</section>
Thanks to anyone that can help
You should remove/override the top margin of the heading.
#skillsTitle {
margin-top: 0;
}