Keep related text next to floated image - html

I'm working on a responsive webpage that has photos of people's faces as floated IMGs next to some descriptive text about each person.
This works very well at smaller page widths, but when the page gets wide, the text associated with the next person starts next to the previous person's image.
I need a way to force text appear no higher than the top of the particular image.
I've set up a JSFiddle here.
img {
float: left;
clear: both;
margin: 0 20px 20px 0;
}
<img src="https://placehold.it/300x300">
<h1>First person's name</h1>
<p>A few paras of text.</p>
<img src="https://placehold.it/300x300">
<h1>Second person's name</h1>
<p>A few paras of text.</p>
Note: the clear: both is there to make sure the second image doesn't float to the right of the first image.
EDIT: Ideally I would do this without using any special markup, such as DIVs and inline style. The reason for this is that this content is being entered into our CMS by non-technical staff using the TinyMCE editor. Ideally these people wouldn't need to know any HTML. So I would really prefer a CSS-only solution.

You can clear the float after the p element using:
<div style="clear:both"></div>
See demo below:
#container img {
float: left;
margin: 0 20px 20px 0;
}
<div id="container">
<img src="https://placehold.it/360x360">
<h1>
First person's name
</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque id ex ut nunc pharetra congue. Morbi ut lectus vulputate nunc congue convallis. Nunc ultricies quam ac dolor tincidunt feugiat. Integer condimentum metus leo, a interdum felis molestie in.
Ut non diam non ligula aliquam iaculis vestibulum quis urna. Maecenas efficitur purus et elementum auctor. Praesent condimentum id sapien vitae tempor. Ut ultrices accumsan lectus, quis ullamcorper velit auctor at. Suspendisse bibendum, odio gravida
rhoncus pretium, enim elit porta massa, quis sagittis dolor sapien vel nulla. Nullam et enim ac tellus aliquam pulvinar. Proin et bibendum dui.
</p>
<div style="clear:both"></div>
<img src="https://placehold.it/360x360">
<h1>
Second person's name
</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque id ex ut nunc pharetra congue. Morbi ut lectus vulputate nunc congue convallis. Nunc ultricies quam ac dolor tincidunt feugiat. Integer condimentum metus leo, a interdum felis molestie in.
Ut non diam non ligula aliquam iaculis vestibulum quis urna. Maecenas efficitur purus et elementum auctor. Praesent condimentum id sapien vitae tempor. Ut ultrices accumsan lectus, quis ullamcorper velit auctor at. Suspendisse bibendum, odio gravida
rhoncus pretium, enim elit porta massa, quis sagittis dolor sapien vel nulla. Nullam et enim ac tellus aliquam pulvinar. Proin et bibendum dui.
</p>
</div>
If markup can't be changed, you can use a pseudo element to p:
p:after {
display: block;
content: '';
clear: both;
}
See demo below:
#container img {
float: left;
margin: 0 20px 20px 0;
}
p:after {
display: block;
content: '';
clear: both;
}
<div id="container">
<img src="https://placehold.it/360x360">
<h1>
First person's name
</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque id ex ut nunc pharetra congue. Morbi ut lectus vulputate nunc congue convallis. Nunc ultricies quam ac dolor tincidunt feugiat. Integer condimentum metus leo, a interdum felis molestie in.
Ut non diam non ligula aliquam iaculis vestibulum quis urna. Maecenas efficitur purus et elementum auctor. Praesent condimentum id sapien vitae tempor. Ut ultrices accumsan lectus, quis ullamcorper velit auctor at. Suspendisse bibendum, odio gravida
rhoncus pretium, enim elit porta massa, quis sagittis dolor sapien vel nulla. Nullam et enim ac tellus aliquam pulvinar. Proin et bibendum dui.
</p>
<img src="https://placehold.it/360x360">
<h1>
Second person's name
</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque id ex ut nunc pharetra congue. Morbi ut lectus vulputate nunc congue convallis. Nunc ultricies quam ac dolor tincidunt feugiat. Integer condimentum metus leo, a interdum felis molestie in.
Ut non diam non ligula aliquam iaculis vestibulum quis urna. Maecenas efficitur purus et elementum auctor. Praesent condimentum id sapien vitae tempor. Ut ultrices accumsan lectus, quis ullamcorper velit auctor at. Suspendisse bibendum, odio gravida
rhoncus pretium, enim elit porta massa, quis sagittis dolor sapien vel nulla. Nullam et enim ac tellus aliquam pulvinar. Proin et bibendum dui.
</p>
</div>

Try using Bootstrap column structure
#container img {
margin-bottom: 20px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div id="container">
<div class="row">
<div class="col-xs-6 col-sm-6">
<img src="https://placehold.it/360x360">
</div>
<div class="col-xs-6 col-sm-6">
<h1>First person's name</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque id ex ut nunc pharetra congue. Morbi ut lectus vulputate nunc congue convallis. Nunc ultricies quam ac dolor tincidunt feugiat. Integer condimentum metus leo, a interdum felis molestie in. Ut non diam non ligula aliquam iaculis vestibulum quis urna. Maecenas efficitur purus et elementum auctor. Praesent condimentum id sapien vitae tempor. Ut ultrices accumsan lectus, quis ullamcorper velit auctor at. Suspendisse bibendum, odio gravida rhoncus pretium, enim elit porta massa, quis sagittis dolor sapien vel nulla. Nullam et enim ac tellus aliquam pulvinar. Proin et bibendum dui.
</p>
</div>
</div>
<div class="row">
<div class="col-xs-6 col-sm-6">
<img src="https://placehold.it/360x360">
</div>
<div class="col-xs-6 col-sm-6">
<h1>Second person's name</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque id ex ut nunc pharetra congue. Morbi ut lectus vulputate nunc congue convallis. Nunc ultricies quam ac dolor tincidunt feugiat. Integer condimentum metus leo, a interdum felis molestie in. Ut non diam non ligula aliquam iaculis vestibulum quis urna. Maecenas efficitur purus et elementum auctor. Praesent condimentum id sapien vitae tempor. Ut ultrices accumsan lectus, quis ullamcorper velit auctor at. Suspendisse bibendum, odio gravida rhoncus pretium, enim elit porta massa, quis sagittis dolor sapien vel nulla. Nullam et enim ac tellus aliquam pulvinar. Proin et bibendum dui.
</p>
</div>
</div>

Try using divs and clear elements pseudo selector before and after
Demo link
.top-content:after, .top-content:before {
display: block;
content: "";
clear: both;
margin-bottom: 30px;
}

Related

CSS Grid: Text outside the div

I have an issue with css grid
<div class="container">
<div class="q1">
<h4>Short Text</h2>
</div>
<div class="a1">
<p>LONG TEXT</p>
</div>
</div>
The LONG TEXT is going outside the div, I would like to keep it inside (it doesn't matter the height of the column). My css is:
.container {
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap: 20px;
background-color: #ffe8d6;
filter: brightness(90%);
padding: 5px;
}
So the idea is having 2 columns of the same width and with the height defined by the LONG TEXT in the second one. Now the text is going outside the container.
You did not close your first div. In the Short Text you opened h4 but closing tag is h2. Fix these typo first. Here is the working code below. I have added q1 and a1 classes to check whether the text is inside the div or not.
.container {
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap: 20px;
background-color: #ffe8d6;
filter: brightness(90%);
padding: 5px;
}
.q1 {
background: gray;
}
.a1 {
background: darkgray;
}
<div class="container">
<div class="q1">
<h4>Short Text</h4>
</div>
<div class="a1">
<p>LONG TEXT dsfsdfsd sdf sdfsdf sdfs dsdf sdfsdf dsf sdfsdf sdfs dfsdfsdf s</p>
</div>
</div>
I have just copy/pasted your code here and fixed one <h4> tag and one <div> tag. The div problem was that your <div class="container"> had no </div> to match it. The "Short Text" <h4> tag had a closing tag, but it was of the wrong type (h2). It looked like: <h4>Short Text</h2> and I changed it to: <h4>Short Text</h4>.
Additionally, I supplied sample text in each section to show the long and short sections more clearly.
Other than that, the code in this snippet is identical to yours. I didn't do anything to the CSS, but it seems that even with long text and short text, nothing is overflowing the containing div.
.container {
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap: 20px;
background-color: #ffe8d6;
filter: brightness(90%);
padding: 5px;
}
<div class="container">
<div class="q1">
<h4>Short Text</h4>
<p>
Lorem ipsum dolor sit amet, consectetur
adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
Fames ac turpis egestas maecenas pharetra
convallis posuere. Quam nulla porttitor
massa id neque aliquam vestibulum morbi
blandit. Ligula ullamcorper malesuada proin
libero. Donec adipiscing tristique risus nec
feugiat.
</p>
</div>
<div class="a1">
<h4>Long Text</h4>
<p>
Lorem ipsum dolor sit amet, consectetur
adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
Nec sagittis aliquam malesuada bibendum arcu
vitae elementum. Tempor nec feugiat nisl
pretium. Libero justo laoreet sit amet. Ut
ornare lectus sit amet est. Ipsum dolor sit
amet consectetur. Et netus et malesuada
fames ac turpis. Tellus rutrum tellus
pellentesque eu tincidunt tortor aliquam. Et
ultrices neque ornare aenean euismod
elementum. Eu ultrices vitae auctor eu augue
ut lectus arcu bibendum. Velit sed
ullamcorper morbi tincidunt ornare.
Pellentesque habitant morbi tristique
senectus et netus. Mattis molestie a iaculis
at erat pellentesque adipiscing commodo
elit. Sit amet purus gravida quis blandit
turpis cursus in hac. Eget duis at tellus at
urna condimentum. Nunc mattis enim ut tellus
elementum sagittis. Dignissim enim sit amet
venenatis urna. Mauris cursus mattis
molestie a iaculis at erat. Malesuada nunc
vel risus commodo viverra.
</p>
<p>
In metus vulputate eu scelerisque felis
imperdiet proin fermentum. Tellus id
interdum velit laoreet id donec. Cras
adipiscing enim eu turpis egestas. Eget
nullam non nisi est sit amet facilisis.
Tristique nulla aliquet enim tortor at
auctor. Eu non diam phasellus vestibulum
lorem sed risus. Odio aenean sed adipiscing
diam donec adipiscing tristique. Fermentum
et sollicitudin ac orci phasellus egestas.
Placerat orci nulla pellentesque dignissim
enim sit amet venenatis urna. Donec pretium
vulputate sapien nec sagittis aliquam
malesuada bibendum arcu. Diam vel quam
elementum pulvinar etiam non quam. Aliquam
sem et tortor consequat id porta nibh
venenatis. Hac habitasse platea dictumst
vestibulum rhoncus est. Amet consectetur
adipiscing elit pellentesque habitant morbi
tristique senectus. Urna molestie at
elementum eu. Donec et odio pellentesque
diam volutpat commodo. Nibh sed pulvinar
proin gravida hendrerit lectus a.
</p>
<p>
Amet consectetur adipiscing elit duis
tristique sollicitudin nibh sit. Risus at
ultrices mi tempus imperdiet nulla
malesuada. Et pharetra pharetra massa massa
ultricies mi. Quam nulla porttitor massa id
neque aliquam vestibulum. Donec ac odio
tempor orci dapibus ultrices in iaculis.
Pharetra vel turpis nunc eget lorem dolor
sed viverra ipsum. Arcu non sodales neque
sodales ut. Vitae nunc sed velit dignissim
sodales ut eu sem integer. Cursus risus at
ultrices mi tempus imperdiet. Enim neque
volutpat ac tincidunt vitae semper quis.
Rhoncus urna neque viverra justo. Mattis
rhoncus urna neque viverra justo nec
ultrices.
</p>
<p>
Pellentesque adipiscing commodo elit at
imperdiet. Donec ac odio tempor orci dapibus
ultrices in iaculis nunc. Lacus vestibulum
sed arcu non odio. Elit ullamcorper
dignissim cras tincidunt. Aliquet sagittis
id consectetur purus. Nunc sed velit
dignissim sodales. Amet mattis vulputate
enim nulla aliquet porttitor lacus luctus.
Donec enim diam vulputate ut pharetra sit
amet aliquam. Purus in massa tempor nec
feugiat nisl pretium. Lacus laoreet non
curabitur gravida arcu ac tortor dignissim
convallis. Turpis massa sed elementum tempus
egestas sed sed risus pretium. Ut enim
blandit volutpat maecenas volutpat blandit
aliquam etiam.
</p>
<p>
Fermentum odio eu feugiat pretium nibh ipsum
consequat nisl. Euismod elementum nisi quis
eleifend quam adipiscing vitae proin. Id
neque aliquam vestibulum morbi blandit
cursus risus at ultrices. Libero nunc
consequat interdum varius sit amet.
Facilisis volutpat est velit egestas dui.
Ornare suspendisse sed nisi lacus sed
viverra tellus in. Rhoncus est pellentesque
elit ullamcorper. Eleifend quam adipiscing
vitae proin sagittis nisl rhoncus mattis
rhoncus. Pharetra sit amet aliquam id diam
maecenas ultricies. Tincidunt nunc pulvinar
sapien et ligula ullamcorper. Sed risus
ultricies tristique nulla aliquet enim
tortor at. Erat pellentesque adipiscing
commodo elit at imperdiet dui accumsan sit.
Eget nunc scelerisque viverra mauris.
</p>
</div>
</div>

Full screen image over the container on Bootstrap 3

Ok. I am trying to achieve a "Medium.com style" image alignment, making it larger than it's container and full width. I did what I knew I had to do with the CSS:
img {
position: relative;
left: 50%;
height: auto;
margin: 0px 0 0 -50vw;
width: 100vw;
max-width: 100vw;
}
It almost do what I want it to do, except that, when I use all the 12 grids of Bootstrap, for some reason, it adds a border on the left, as you can see in this fiddle: https://jsfiddle.net/35f4ntqq/
If I change the col-sm-11 to col-sm-10 (making it 11 cols in total), though, it works perfectly fine.
What am I missing here? Or doing wrong...? :/
I think you can changies margin property for img tag:
Like this:
img {
position: relative;
left: 52%;
height: auto !important;
margin: 0px 0 0 -55vw;
width: 100vw;
max-width: 100vw !important;
height: auto !important;
}
See Updated Bootply
You can use container-fluid to achieve the desired result.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<style>
img {
height: auto;
width: 100%;
}
</style>
<div class="container">
<div class="row">
<div class="col-sm-1">
Boo
</div>
<div class="col-sm-11">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sed ligula nec erat dapibus ullamcorper. Aliquam egestas, justo nec dictum vestibulum, dui eros ullamcorper mauris, non facilisis lorem ligula ut ex. Mauris scelerisque libero nulla, eget luctus velit fringilla ut. Etiam ut magna eget elit gravida ultrices. Quisque a enim id leo tincidunt lobortis. Pellentesque nulla mi, aliquet non mauris et, aliquam egestas leo. Nulla convallis tincidunt gravida. Suspendisse aliquam lacinia eros sit amet pretium. Nam eu ipsum sit amet velit suscipit consectetur vel sit amet dolor. Sed ac aliquam est, dictum gravida est. Donec pellentesque condimentum est at bibendum. Aliquam erat volutpat. Nulla id urna non mauris faucibus fermentum. Phasellus quam ante, bibendum eget orci a, aliquam fringilla tortor. In vitae nulla nec leo tincidunt convallis. Integer ac ipsum a lorem sagittis pretium tincidunt id erat.</p>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row">
<img src="http://www.lpzoo.org/sites/default/files/images/multimedia/kapukikingnosetonose1200.jpg">
</div>
</div>
<div class="container">
<div class="row">
<div class="col-sm-1">
</div>
<div class="col-sm-11">
<p>Duis maximus est nec eros euismod, quis volutpat magna pellentesque. Maecenas orci sapien, gravida quis commodo a, pharetra at sapien. Etiam scelerisque nunc sit amet ligula volutpat convallis. Nam egestas commodo tortor at pellentesque. Pellentesque vitae dictum urna. Etiam tincidunt magna et aliquam tincidunt. Vestibulum blandit arcu a pulvinar auctor. Phasellus malesuada, tortor sit amet mollis pulvinar, felis felis lacinia tellus, tempus ultricies urna magna et augue. Fusce ut ipsum eget odio sodales viverra. Morbi sit amet hendrerit purus, sit amet porttitor sapien. Quisque ut quam eu erat elementum lobortis. Proin sit amet nisl eget est feugiat vulputate. Morbi eu orci semper, rhoncus lacus eget, fringilla lorem.</p>
</div>
</div>
</div>
https://jsfiddle.net/glebkema/pn8jbk8p/
try this.
"medium.com style"
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-xs-1">
Boo
</div>
<div class="col-xs-11">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sed ligula nec erat dapibus ullamcorper. Aliquam egestas, justo nec dictum vestibulum, dui eros ullamcorper mauris, non facilisis lorem ligula ut ex. Mauris scelerisque libero nulla, eget luctus velit fringilla ut. Etiam ut magna eget elit gravida ultrices. Quisque a enim id leo tincidunt lobortis. Pellentesque nulla mi, aliquet non mauris et, aliquam egestas leo. Nulla convallis tincidunt gravida. Suspendisse aliquam lacinia eros sit amet pretium. Nam eu ipsum sit amet velit suscipit consectetur vel sit amet dolor. Sed ac aliquam est, dictum gravida est. Donec pellentesque condimentum est at bibendum. Aliquam erat volutpat. Nulla id urna non mauris faucibus fermentum. Phasellus quam ante, bibendum eget orci a, aliquam fringilla tortor. In vitae nulla nec leo tincidunt convallis. Integer ac ipsum a lorem sagittis pretium tincidunt id erat.</p>
</div>
<div class="col-sm-12">
<img class="img-responsive" src="http://www.lpzoo.org/sites/default/files/images/multimedia/kapukikingnosetonose1200.jpg">
</div>
<div class="col-sm-12">
<p>Duis maximus est nec eros euismod, quis volutpat magna pellentesque. Maecenas orci sapien, gravida quis commodo a, pharetra at sapien. Etiam scelerisque nunc sit amet ligula volutpat convallis. Nam egestas commodo tortor at pellentesque. Pellentesque vitae dictum urna. Etiam tincidunt magna et aliquam tincidunt. Vestibulum blandit arcu a pulvinar auctor. Phasellus malesuada, tortor sit amet mollis pulvinar, felis felis lacinia tellus, tempus ultricies urna magna et augue. Fusce ut ipsum eget odio sodales viverra. Morbi sit amet hendrerit purus, sit amet porttitor sapien. Quisque ut quam eu erat elementum lobortis. Proin sit amet nisl eget est feugiat vulputate. Morbi eu orci semper, rhoncus lacus eget, fringilla lorem.</p>
</div>
</div>
</div>

Div disappearing under another div

Sorry for the vague title, but I have an issue that I've been unable to find a fix to. I'm trying to create a 2 column website with equal length columns. I've been following this tutorial and it is mostly working but one part breaks. The content of the right hand column is disappearing under the background. My apologies beforehand, I'm really new to this.
container below contains the entire page; Header, Nav, Content and footer. If you need the rest of the code, let me know. The webpage in operation can be viewed here;
#container {
float: left;
margin-left: 5px;
width: 1023px;
height: 100%;
}
#containerLeft {
float: left;
background: #fff;
width: 100%;
position: relative;
overflow: hidden;
right: 24%;
height: 100%;
}
#containerRight {
float: left;
background: #e7e1d7;
width: 100%;
position: relative;
overflow: hidden;
height: 100%;
}
#rightContent {
float: left;
width: 24%;
overflow: hidden;
position: relative;
z-index: 5;
}
#leftContent {
float: left;
width: 76%;
position: relative;
overflow: hidden;
}
<div id="containerRight">
<div id="containerLeft">
<div id="rightContent">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam arcu enim, laoreet nec orci sed, sagittis condimentum libero. Interdum et malesuada fames ac ante ipsum primis in faucibus. Ut tempus tellus nisi, ut bibendum quam eleifend nec. Integer
semper eu dui id vestibulum. Mauris porttitor ullamcorper laoreet. Integer non nunc sit amet tortor porta bibendum vel sed enim. Maecenas elit mauris, consectetur mollis varius vitae, dignissim non purus. Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Phasellus eu ligula ligula. Nulla posuere quis nisl sed tincidunt. Praesent vel nisi orci. Pellentesque congue vel enim eu pulvinar. Vivamus massa ante, malesuada eget rutrum varius, placerat ut arcu. Pellentesque rutrum lacinia
ex sit amet sollicitudin.</p>
<p>Integer rhoncus, enim eu iaculis commodo, nulla arcu porta tortor, a pellentesque ante justo ut nisi. Donec ex libero, consequat at ligula vitae, sodales maximus eros. Aenean feugiat porttitor dui a cursus. Aliquam aliquam et sapien a auctor. Suspendisse
placerat sem quis dui feugiat accumsan. Maecenas ultrices sagittis augue, et dictum sem imperdiet quis. In purus nisl, interdum ac dolor vitae, eleifend hendrerit justo. Nullam facilisis, orci in fermentum condimentum, velit diam pulvinar magna,
ut ornare nibh nunc vel sapien. Phasellus aliquet massa justo, a eleifend diam pharetra vel. Integer sem dui, elementum eget orci eget, feugiat feugiat velit. Aenean eget dapibus metus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices
posuere cubilia Curae; Etiam efficitur ipsum nisl, eu hendrerit tellus ultricies sit amet. Donec pulvinar interdum ante, in malesuada lacus consequat vel. Aliquam commodo tellus vel metus accumsan facilisis. Nulla facilisi.</p>
<p>Nulla facilisi. Donec vitae gravida orci, vitae sollicitudin nisl. Sed sed metus risus. Donec porttitor, augue quis elementum pellentesque, libero arcu pretium est, ut placerat enim quam nec quam. Nam vel mauris dapibus, commodo nibh ac, cursus
eros. Curabitur tristique mauris nec justo laoreet laoreet. Nam nisi elit, fermentum eu egestas sollicitudin, molestie sed diam. Nulla at quam nec purus varius scelerisque non eget augue. In quis ex ac felis iaculis lobortis at vel sem. Ut luctus
quam ac blandit sodales. Etiam sodales arcu eu tellus interdum mollis. Integer feugiat dui quis magna scelerisque, vel fringilla nulla aliquam. Fusce et rhoncus libero. Aliquam nibh nunc, consectetur et ipsum sit amet, vulputate hendrerit sapien.
Sed orci elit, euismod in libero nec, ornare feugiat erat.</p>
<p>Suspendisse potenti. Morbi consectetur, dui eu rutrum luctus, dui diam laoreet ex, ut fermentum enim eros at urna. Nulla at luctus tortor, quis euismod libero. Cras sodales augue at dui fermentum facilisis. Nullam vehicula sapien semper neque euismod,
non convallis sem iaculis. Cras ultricies convallis ex, nec varius tellus consectetur ut. Maecenas efficitur vestibulum est at ultrices. Nulla sit amet est iaculis, fringilla justo a, suscipit orci. Etiam rutrum auctor bibendum. Donec molestie
diam at lacus eleifend lacinia. Proin sit amet enim elementum, egestas odio quis, euismod nibh. In hac habitasse platea dictumst. Ut quis ante id elit semper aliquam. Aliquam a tempus justo. Aenean finibus nulla augue, eget dictum magna congue
at.</p>
<p>Praesent nisl neque, rutrum non mauris et, hendrerit iaculis odio. Fusce nisi elit, ultrices rhoncus magna nec, pulvinar luctus ex. Mauris id ante eget arcu suscipit efficitur. Aliquam imperdiet lectus ante, eget laoreet metus mollis ut. Praesent
volutpat suscipit arcu, at finibus dolor. Sed vitae pulvinar mi, quis condimentum justo. Donec sed tincidunt justo. Mauris non semper justo. Sed facilisis libero eget lorem gravida, ac consectetur eros pulvinar.</p>
</div>
<div id="leftContent">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam arcu enim, laoreet nec orci sed, sagittis condimentum libero. Interdum et malesuada fames ac ante ipsum primis in faucibus. Ut tempus tellus nisi, ut bibendum quam eleifend nec. Integer
semper eu dui id vestibulum. Mauris porttitor ullamcorper laoreet. Integer non nunc sit amet tortor porta bibendum vel sed enim. Maecenas elit mauris, consectetur mollis varius vitae, dignissim non purus. Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Phasellus eu ligula ligula. Nulla posuere quis nisl sed tincidunt. Praesent vel nisi orci. Pellentesque congue vel enim eu pulvinar. Vivamus massa ante, malesuada eget rutrum varius, placerat ut arcu. Pellentesque rutrum lacinia
ex sit amet sollicitudin.</p>
<p>Integer rhoncus, enim eu iaculis commodo, nulla arcu porta tortor, a pellentesque ante justo ut nisi. Donec ex libero, consequat at ligula vitae, sodales maximus eros. Aenean feugiat porttitor dui a cursus. Aliquam aliquam et sapien a auctor. Suspendisse
placerat sem quis dui feugiat accumsan. Maecenas ultrices sagittis augue, et dictum sem imperdiet quis. In purus nisl, interdum ac dolor vitae, eleifend hendrerit justo. Nullam facilisis, orci in fermentum condimentum, velit diam pulvinar magna,
ut ornare nibh nunc vel sapien. Phasellus aliquet massa justo, a eleifend diam pharetra vel. Integer sem dui, elementum eget orci eget, feugiat feugiat velit. Aenean eget dapibus metus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices
posuere cubilia Curae; Etiam efficitur ipsum nisl, eu hendrerit tellus ultricies sit amet. Donec pulvinar interdum ante, in malesuada lacus consequat vel. Aliquam commodo tellus vel metus accumsan facilisis. Nulla facilisi.</p>
<p>Nulla facilisi. Donec vitae gravida orci, vitae sollicitudin nisl. Sed sed metus risus. Donec porttitor, augue quis elementum pellentesque, libero arcu pretium est, ut placerat enim quam nec quam. Nam vel mauris dapibus, commodo nibh ac, cursus
eros. Curabitur tristique mauris nec justo laoreet laoreet. Nam nisi elit, fermentum eu egestas sollicitudin, molestie sed diam. Nulla at quam nec purus varius scelerisque non eget augue. In quis ex ac felis iaculis lobortis at vel sem. Ut luctus
quam ac blandit sodales. Etiam sodales arcu eu tellus interdum mollis. Integer feugiat dui quis magna scelerisque, vel fringilla nulla aliquam. Fusce et rhoncus libero. Aliquam nibh nunc, consectetur et ipsum sit amet, vulputate hendrerit sapien.
Sed orci elit, euismod in libero nec, ornare feugiat erat.</p>
<p>Suspendisse potenti. Morbi consectetur, dui eu rutrum luctus, dui diam laoreet ex, ut fermentum enim eros at urna. Nulla at luctus tortor, quis euismod libero. Cras sodales augue at dui fermentum facilisis. Nullam vehicula sapien semper neque euismod,
non convallis sem iaculis. Cras ultricies convallis ex, nec varius tellus consectetur ut. Maecenas efficitur vestibulum est at ultrices. Nulla sit amet est iaculis, fringilla justo a, suscipit orci. Etiam rutrum auctor bibendum. Donec molestie
diam at lacus eleifend lacinia. Proin sit amet enim elementum, egestas odio quis, euismod nibh. In hac habitasse platea dictumst. Ut quis ante id elit semper aliquam. Aliquam a tempus justo. Aenean finibus nulla augue, eget dictum magna congue
at.</p>
<p>Praesent nisl neque, rutrum non mauris et, hendrerit iaculis odio. Fusce nisi elit, ultrices rhoncus magna nec, pulvinar luctus ex. Mauris id ante eget arcu suscipit efficitur. Aliquam imperdiet lectus ante, eget laoreet metus mollis ut. Praesent
volutpat suscipit arcu, at finibus dolor. Sed vitae pulvinar mi, quis condimentum justo. Donec sed tincidunt justo. Mauris non semper justo. Sed facilisis libero eget lorem gravida, ac consectetur eros pulvinar.</p>
</div>
</div>
</div>
As you can see, I tried using z-index but it didn't appear to work. I also tried margins and padding, but that broke things entirely, and left/right as directed in the tutorial didn't do anything useful.
Here is the code you need for your 2 columns layout. You made several mistakes:
Your first containerLeft doesn't need an height: 100% and position: relative;.
Your second containerRight doesn't need an height: 100%.
You just need two containers as you only have 2 columns.
Check the code to see how to calculate the width of your columns with left and right.
However, make sure you do need this kind of layout (having equal columns height) because this is a lot of extra code for a layout. You can also check this article for extra techniques depending on the browser support you need: http://css-tricks.com/fluid-width-equal-height-columns/
Check the corrected code below:
.header {
background-color: AliceBlue;
}
.footer {
clear: both;
background-color: Beige;
}
#containerLeft {
clear: left;
float: left;
width: 100%;
overflow: hidden;
background-color: #999;
}
#containerRight {
float: left;
width: 100%;
position: relative;
right: 24%; /* this will make your right column 24% width */
background-color: #e4e4e4;
}
#leftContent {
float: left;
width: 68%; /* Your left container is now 100% - 24% (containerRight) = 76%. I have included a padding of 8% to make your content breathe so 76% - 8% = 68% */
position: relative;
left: 28%; /* Your content in your left container will start at 100% - 76% (left container width) = 24%. I have included a paading-left of 4% which makes it 24 + 4 = 28% */
overflow: hidden;
}
#rightContent {
float: left;
width: 20%; /* Your right column width is 24% and I have included a 4% padding so 24 - 4 = 20% */
position: relative;
left: 34%; /* Your content will start at 100% - 68% (width of leftContent) = 32%. I have included a 2% padding so 32 + 2 = 34% */
overflow: hidden;
}
<section class="header">
<div class="banner">
Your banner
</div>
<nav>
Your nav
</nav>
</section>
<section class="main">
<div id="containerLeft">
<div id="containerRight">
<div id="leftContent">
<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 id="rightContent">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt.</p>
</div>
</div>
<!-- /end container2 -->
</div>
<!-- /end container1 -->
</section>
<section class="footer">
Your footer
</section>

List item position for responsive webdesign

I'd like to create a list that looks good on every devices.
The image shows what I want to achieve.
My first problem is that the description is under the image.
The second one is that the image isn't centered on mobile device.
Thanks for helping me in advance.
Here is my code:
.title {
margin: 0;
}
.tabpage-list {
padding: 0;
width: 100%;
}
.tabpage-list {
display: inline;
}
.tabpage-list-item {
margin-top: 1em;
padding: 1em;
background-color: #f5f5f5;
}
.tli-image-container {
height: 100%;
margin-right: 1%;
float: left;
}
#media screen and (max-width : 480px) {
.tli-image-container {
float: none;
text-align: center;
}
}
And the HTML
<div>
<ul class="tabpage-list">
<li>
<div class="tabpage-list-item">
<div class="tli-image-container">
<img src="http://im10.trueachievements.com/imagestore/0001319900/1319949.jpg" />
</div>
<div>
<p class="title">some title</p>
<a>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer velit augue, porttitor in neque vitae, sodales commodo ligula. Pellentesque massa urna, sagittis nec ullamcorper vitae, pharetra a elit. Nullam eu lectus vel justo interdum elementum non faucibus lacus. Vivamus placerat, augue vel egestas rutrum, eros nisi mattis arcu, quis cursus mi leo quis est. Sed nulla quam, mollis vel elit ac, varius gravida felis. Donec elementum felis at lacus eleifend, a placerat eros auctor. Proin laoreet ornare nisl, blandit lobortis ipsum porttitor ac. Ut elit dolor, egestas vitae est nec, tristique adipiscing lorem. Pellentesque lacinia justo et nisl fermentum molestie quis et est. Proin at volutpat dui, vel sollicitudin turpis. Sed eu placerat lectus. Aenean dictum lacinia eros, vitae consequat nisl. Ut vitae nisi ut nulla mattis ultrices non quis felis. Proin vestibulum sit amet nunc sit amet volutpat.</a>
</div>
</div>
</li>
<li>
<div class="tabpage-list-item">
<div class="tli-image-container">
<img src="http://im10.trueachievements.com/imagestore/0001319900/1319949.jpg" />
</div>
<div>
<p class="title">some title</p>
<a>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer velit augue, porttitor in neque vitae, sodales commodo ligula. Pellentesque massa urna, sagittis nec ullamcorper vitae, pharetra a elit. Nullam eu lectus vel justo interdum elementum non faucibus lacus. Vivamus placerat, augue vel egestas rutrum, eros nisi mattis arcu, quis cursus mi leo quis est. Sed nulla quam, mollis vel elit ac, varius gravida felis. Donec elementum felis at lacus eleifend, a placerat eros auctor. Proin laoreet ornare nisl, blandit lobortis ipsum porttitor ac. Ut elit dolor, egestas vitae est nec, tristique adipiscing lorem. Pellentesque lacinia justo et nisl fermentum molestie quis et est. Proin at volutpat dui, vel sollicitudin turpis. Sed eu placerat lectus. Aenean dictum lacinia eros, vitae consequat nisl. Ut vitae nisi ut nulla mattis ultrices non quis felis. Proin vestibulum sit amet nunc sit amet volutpat.</a>
</div>
</div>
<li>
</ul>
</div>
I think you were looking for: width:calc(100% - px); to keep the ratio of the image. Also, it was quicker to rewrite the code based your wireframes. http://jsfiddle.net/NinoLopezWeb/twq87mj9/

how to fix this layout

i have been trying to get the singer/songwriter title to float to the right of the name on top of page. i also want a separate row with img and the paragraph of text to the right of that.
the problem i am now having is that i cant create a black navigation menu that floats to the right of the girls image and stays below the paragraph of text
ive coded the following up in dreamweaver, this is excluding the nav menu. When i view the document in dreamweaver it all displays correctly. however when i open it in a browser it displays wierd and the paragraph of text is displayed underneath the big image.
could somebody provide help as to why this is happening and once fixing it, how i would add a navigation menu directly underneath the paragraph of text, cheers
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<style type="text/css">
body{margin:0px; padding:0px;}
#footer{ background:black; height:100px;}
#top{height:50px; background:black; }
.logo{float:left;}
.title{float:left;}
.alice{float:left;}
.info{float:left;}
</style>
</head>
<body>
<div class="wrapper">
<div id="top">
Content for id "top" Goes Here
</div>
<div class="logo">
<img src="http://digitalgenesis.com.au/sites/alice/img/namelogo.png" />
</div>
<div class="title">
<h2>Singer/Songwriter</h2>
</div>
<div style="clear:both;">
</div>
<div class="alice">
<img src="http://digitalgenesis.com.au/sites/alice/img/alice.png" />
</div>
<div class="info">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec massa est, ultrices quis volutpat vitae, volutpat id mauris. In lacinia, nisi sit amet tincidunt rhoncus, nunc augue pharetra neque, eget sagittis orci justo tincidunt lectus. Phasellus sollicitudin lacus sed nisl eleifend bibendum. Vivamus imperdiet porttitor facilisis. Pellentesque quis metus risus, ac sagittis augue. Vivamus vehicula lacus ullamcorper sapien tincidunt congue. Vivamus diam tellus, faucibus sit amet rutrum ut, mattis eu orci. Fusce ullamcorper, odio et ultricies posuere, lorem orci faucibus orci, vel vehicula mauris arcu vitae metus. Cras congue nulla id quam elementum porttitor. Praesent dapibus odio nec nisl pretium quis pharetra leo suscipit. <br /><br />
Phasellus vestibulum magna ut tortor sagittis ut pretium tellus feugiat. Integer ullamcorper enim vitae odio ultricies tempor. Donec ullamcorper erat tincidunt tortor laoreet ultricies. Nullam volutpat sollicitudin est, et hendrerit metus aliquam in. Nunc convallis tempus velit, a interdum ipsum ultricies eu. Integer ultrices mollis molestie. Donec augue sem, lacinia quis tempor id, rutrum quis sapien. Nullam sit amet velit vitae justo tempus fermentum sit amet et sapien. Ut pretium metus odio, a tempus nisi. Ut fringilla semper justo. <br /><br />
Aliquam pellentesque libero sit amet nisi feugiat sagittis. Integer in purus magna. Suspendisse at ipsum id ante fringilla vehicula id eget nibh. Morbi consequat ligula quis mauris sagittis egestas. Maecenas quam odio, posuere nec venenatis non, posuere ut elit. Nulla tincidunt tristique tellus in commodo. Donec aliquet libero et enim porta vel auctor ipsum aliquet. Aenean eget nisl non quam auctor malesuada vitae id felis. In scelerisque massa eu turpis fringilla congue. Cras odio sem, aliquam et blandit nec, semper ut turpis. Curabitur bibendum, magna sed rhoncus placerat, justo quam scelerisque sem, et varius massa nisi ac ligula. In pharetra tincidunt odio, sodales mollis sem congue non. Integer ullamcorper nibh augue, sit amet semper eros. Nunc malesuada odio vel nisi venenatis quis dictum nisi lacinia. Sed imperdiet dapibus sem, a suscipit justo fringilla at. Fusce quis lacus a diam porttitor auctor. Suspendisse potenti.
</p>
</div>
<!-- end info -->
<div style="clear:both;">
</div>
<div id="footer">
Content for id "footer" Goes Here
</div>
</div>
<!-- end wrapper -->
</body>
</html>
(EDIT: See this fiddle)
Hi dazza_au,
Very rough fix but will do the job: http://jsfiddle.net/MedDj/4/
Basically, you need to add a width to your floated elements if you want them to float next to each other.
Check out the live example above and let me know if you need a further explanation?
Regards,
Dan
Here's the code in case you need it straight away:
HTML
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>
<body>
<div id="top">Content for id "top" Goes Here</div>
<div class="wrapper">
<div class="logo"><img src="http://digitalgenesis.com.au/sites/alice/img/namelogo.png" /></div>
<div class="title"><h2>Singer/Songwriter</h2></div>
<div style="clear:both;"></div>
<div class="alice"><img src="http://digitalgenesis.com.au/sites/alice/img/alice.png" /></div>
<div class="info"><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec massa est, ultrices quis volutpat vitae, volutpat id mauris. In lacinia, nisi sit amet tincidunt rhoncus, nunc augue pharetra neque, eget sagittis orci justo tincidunt lectus. Phasellus sollicitudin lacus sed nisl eleifend bibendum. Vivamus imperdiet porttitor facilisis. Pellentesque quis metus risus, ac sagittis augue. Vivamus vehicula lacus ullamcorper sapien tincidunt congue. Vivamus diam tellus, faucibus sit amet rutrum ut, mattis eu orci. Fusce ullamcorper, odio et ultricies posuere, lorem orci faucibus orci, vel vehicula mauris arcu vitae metus. Cras congue nulla id quam elementum porttitor. Praesent dapibus odio nec nisl pretium quis pharetra leo suscipit.
<br /><br />
Phasellus vestibulum magna ut tortor sagittis ut pretium tellus feugiat. Integer ullamcorper enim vitae odio ultricies tempor. Donec ullamcorper erat tincidunt tortor laoreet ultricies. Nullam volutpat sollicitudin est, et hendrerit metus aliquam in. Nunc convallis tempus velit, a interdum ipsum ultricies eu. Integer ultrices mollis molestie. Donec augue sem, lacinia quis tempor id, rutrum quis sapien. Nullam sit amet velit vitae justo tempus fermentum sit amet et sapien. Ut pretium metus odio, a tempus nisi. Ut fringilla semper justo.
<br /><br />
Aliquam pellentesque libero sit amet nisi feugiat sagittis. Integer in purus magna. Suspendisse at ipsum id ante fringilla vehicula id eget nibh. Morbi consequat ligula quis mauris sagittis egestas. Maecenas quam odio, posuere nec venenatis non, posuere ut elit. Nulla tincidunt tristique tellus in commodo. Donec aliquet libero et enim porta vel auctor ipsum aliquet. Aenean eget nisl non quam auctor malesuada vitae id felis. In scelerisque massa eu turpis fringilla congue. Cras odio sem, aliquam et blandit nec, semper ut turpis. Curabitur bibendum, magna sed rhoncus placerat, justo quam scelerisque sem, et varius massa nisi ac ligula. In pharetra tincidunt odio, sodales mollis sem congue non. Integer ullamcorper nibh augue, sit amet semper eros. Nunc malesuada odio vel nisi venenatis quis dictum nisi lacinia. Sed imperdiet dapibus sem, a suscipit justo fringilla at. Fusce quis lacus a diam porttitor auctor. Suspendisse potenti. </p>
<ul class="nav">
<li>Nav button one</li>
<li>Nav button two</li>
</ul>
</div><!-- end info -->
<div style="clear:both;"></div>
</div><!-- end wrapper -->
<div id="footer">Content for id "footer" Goes Here</div>
</body>
</html>
CSS
.wrapper{min-width:800px;width:800px;}
body{margin:0px; padding:0px;}
#footer{ background:black; height:100px;}
#top{height:50px; background:black; }
.logo{float:left;}
.title{float:right;padding:40px 10px 0 0; font-size:130%;}
.alice{float:left;width:400px; overflow:hidden;}
.info{float:left;width:400px;}
.info ul.nav{
list-style:none;
padding:0;
margin:10px 0;
overflow:hidden;
}
.info ul.nav li{
float:left;
padding-right:10px;
}
.info ul.nav li a{
background-color:#000;
color:#fff;
padding:10px;
text-decoration:none;
display:block;
}