Is it possible to wrap text around a christmas tree and have the text touch the edges?
I have a block of text on the left and a block of text on the right, I would like to put the tree in the middle and have text wrap around the left and right side edges, is this possible?
HTML:
<div class="main-content">
<div class="left-text">
<p class="left">Sed pretium dapibus lorem. Morbi sed diam eu dolor fermentum pharetra. Aliquam quis erat maximus ligula tincidunt tincidunt vel sed dolor. Curabitur sed aliquet mi. Morbi quis ipsum non ante consectetur varius. Fusce dapibus posuere metus, nec interdum ante. Curabitur magna odio, interdum at est nec, vulputate faucibus quam. Aliquam est nisi, ultricies in mauris quis, venenatis tristique urna. Integer tristique, orci lobortis egestas feugiat, enim massa hendrerit turpis, quis dictum purus tortor ac augue.</p>
<p class="left">Sed pretium dapibus lorem. Morbi sed diam eu dolor fermentum pharetra. Aliquam quis erat maximus ligula tincidunt tincidunt vel sed dolor. Curabitur sed aliquet mi. Morbi quis ipsum non ante consectetur varius. Fusce dapibus posuere metus, nec interdum ante. Curabitur magna odio, interdum at est nec, vulputate faucibus quam. Aliquam est nisi, ultricies in mauris quis, venenatis tristique urna. Integer tristique, orci lobortis egestas feugiat, enim massa hendrerit turpis, quis dictum purus tortor ac augue.</p>
</div>
<div class="right-text">
<p class="right">Sed pretium dapibus lorem. Morbi sed diam eu dolor fermentum pharetra. Aliquam quis erat maximus ligula tincidunt tincidunt vel sed dolor. Curabitur sed aliquet mi. Morbi quis ipsum non ante consectetur varius. Fusce dapibus posuere metus, nec interdum ante. Curabitur magna odio, interdum at est nec, vulputate faucibus quam. Aliquam est nisi, ultricies in mauris quis, venenatis tristique urna. Integer tristique, orci lobortis egestas feugiat, enim massa hendrerit turpis, quis dictum purus tortor ac augue.</p>
<p class="right">Sed pretium dapibus lorem. Morbi sed diam eu dolor fermentum pharetra. Aliquam quis erat maximus ligula tincidunt tincidunt vel sed dolor. Curabitur sed aliquet mi. Morbi quis ipsum non ante consectetur varius. Fusce dapibus posuere metus, nec interdum ante. Curabitur magna odio, interdum at est nec, vulputate faucibus quam. Aliquam est nisi, ultricies in mauris quis, venenatis tristique urna. Integer tristique, orci lobortis egestas feugiat, enim massa hendrerit turpis, quis dictum purus tortor ac augue.</p>
</div>
<div class="christmas-tree"><img src="http://www.raidersleafs.com/images/christmas-tree.png" /></div>
</div>
CSS:
.main-content {
}
.main-content .left-text {
width:25%;
float:left;
}
.main-content .left-text p.left {
}
.main-content .right-text {
width:25%;
float:right;
}
.main-content .right-text p.right {
}
.main-content .christmas-tree {
text-align: center;
}
.main-content .christmas-tree img {
width: 90%;
}
FIDDLE:
http://jsfiddle.net/63p19cbc/1/
UPDATE
I was able to get the left div of text to along the edge of the tree...still cant get the right side to do the same:
.main-content .christmas-tree img {
width: 90%;
shape-outside: polygon(50% 0, 100% 100%, 0% 100%, 0 100%) content-box;
float: right;
}
<div class="main-content">
<div class="christmas-tree"><img src="http://www.raidersleafs.com/images/christmas-tree.png" /></div>
<div class="left-text">
<p class="left">Sed pretium dapibus lorem. Morbi sed diam eu dolor fermentum pharetra. Aliquam quis erat maximus ligula tincidunt tincidunt vel sed dolor. Curabitur sed aliquet mi. Morbi quis ipsum non ante consectetur varius. Fusce dapibus posuere metus, nec interdum ante. Curabitur magna odio, interdum at est nec, vulputate faucibus quam. Aliquam est nisi, ultricies in mauris quis, venenatis tristique urna. Integer tristique, orci lobortis egestas feugiat, enim massa hendrerit turpis, quis dictum purus tortor ac augue.</p>
<p class="left">Sed pretium dapibus lorem. Morbi sed diam eu dolor fermentum pharetra. Aliquam quis erat maximus ligula tincidunt tincidunt vel sed dolor. Curabitur sed aliquet mi. Morbi quis ipsum non ante consectetur varius. Fusce dapibus posuere metus, nec interdum ante. Curabitur magna odio, interdum at est nec, vulputate faucibus quam. Aliquam est nisi, ultricies in mauris quis, venenatis tristique urna. Integer tristique, orci lobortis egestas feugiat, enim massa hendrerit turpis, quis dictum purus tortor ac augue.</p>
</div>
<div class="right-text">
<p class="right">Sed pretium dapibus lorem. Morbi sed diam eu dolor fermentum pharetra. Aliquam quis erat maximus ligula tincidunt tincidunt vel sed dolor. Curabitur sed aliquet mi. Morbi quis ipsum non ante consectetur varius. Fusce dapibus posuere metus, nec interdum ante. Curabitur magna odio, interdum at est nec, vulputate faucibus quam. Aliquam est nisi, ultricies in mauris quis, venenatis tristique urna. Integer tristique, orci lobortis egestas feugiat, enim massa hendrerit turpis, quis dictum purus tortor ac augue.</p>
<p class="right">Sed pretium dapibus lorem. Morbi sed diam eu dolor fermentum pharetra. Aliquam quis erat maximus ligula tincidunt tincidunt vel sed dolor. Curabitur sed aliquet mi. Morbi quis ipsum non ante consectetur varius. Fusce dapibus posuere metus, nec interdum ante. Curabitur magna odio, interdum at est nec, vulputate faucibus quam. Aliquam est nisi, ultricies in mauris quis, venenatis tristique urna. Integer tristique, orci lobortis egestas feugiat, enim massa hendrerit turpis, quis dictum purus tortor ac augue.</p>
</div>
</div>
http://jsfiddle.net/63p19cbc/2/
I believe this is what you are looking for ^^: JSFiddle. Do notice I changed the html in the JSFiddle a little bit.
HTML
<div class="main-content">
<div class="left">
<p> In a one horse open sleigh.</p>
</div>
<div class="right">
<p>Oh the weather outside is frightful</p>
</div>
<img class="christmas-tree" src="http://www.raidersleafs.com/images/christmas-tree.png" />
</div><!--main-content-->
CSS
.main-content {
position: relative;
width: 1000px;
margin: auto;
}
/*align image to center (horizontal) and place it by absolute positioning (so the
image is always appearing on the same spot) after placing it we will create an
empty spot so the text will appear to flow around the image*/
img.christmas-tree {
position: absolute;
left: calc(50% - 215px);
width: 430px;
}
/*Just some text assigned to the right div*/
.right{
width: 50%;
float: right;
}
/*We will create empty space where the christmas tree is by adding blank content
with ::before*/
.right::before{
content: "";
height: 550px;
shape-outside: polygon(50px 0, 50px 150px, 215px 550px, 0 550px);/*this cuts out
a part of the block so the text can freely move around. The values in here
are coördinates in this blank content that allow text to float around it.*/
width: 100%;
float: left;
}
.left{
width: 50%;
float: left;
clear: left;
text-align: right;
}
/*We will create empty space where the christmas tree is by adding blank content
with ::before*/
.left::before{
content: "";
shape-outside: polygon(450px 0px, 450px 150px, 270px 550px, 500px 550px); /*this
cuts out a part of the block so the text can freely move around*/
height: 550px;
width: 100%;
float: right;
}
A few final notes:
The polygon is kinda hard to explain, but you basically add some points (imagine lines between the points) to "cut" out some part of a block or image. The site Chris Hollenbeck recommended explains it better than I can.
A big part of my solution relies on knowing exact coordinates of the christmas-tree. To make it work with a flexible size tree will be a lot harder.
I expect many browsers do not support shape-outside:. If you know what browsers do and do not leave a comment ^^.
Related
So what my goal is, is to position this div background box "lightgrey", with the text which is in another div, but everytime i get the divs positioned the way I want, they seem to be offset, I was thinking of creating a #media_query but I felt like I would have to create way too many statements to have it adjust accordingly, if anyone has any suggestions that would be great.
<div style="width:200px; height:200px;right:0;margin-right:7%; border: 5px;
solid:grey; background-color:lightgrey;position:absolute;">
</div>
<div style="position:absolute;right:0;margin-right:10%;">
<h3>{{major_choice.0.Major}}</h3>
<h3>Overall Rating:</h3>
<h3>{{major_choice.0.ProfessorRating}}</h3>
</div>
The first image is of a map leaflet that does what I want to achieve and its essentially dynamically changing the size without losing its position, verses what I created which constantly moves out of position when i resize the screen.
Leaflet Map (my goal):
This first image is ideal with how I would want it positioned:
When I resize this happens:
I don't have a ton of experience with css, I'm in a web development class right now, but I wont be able to see my professor because of the holidays, if anyone could give me some suggestions I would really appreciate it!
Any suggestions?
html code: https://pastebin.com/iTmsyV5Z
I can't really get a full example working to test but something like:
<div style="width: 200px; height:200px; border: 5px;
solid:grey; background-color: lightgrey; float: left;">
</div>
<div style="margin-left:10%; float: left;">
<h3>{{major_choice.0.Major}}</h3>
<h3>Overall Rating:</h3>
<h3>{{major_choice.0.ProfessorRating}}</h3>
</div>
or
<div style="width: 200px; height:200px; border: 5px;
solid:grey; background-color: lightgrey; float: left;">
</div>
<div style="margin-right:10%; float: right;">
<h3>{{major_choice.0.Major}}</h3>
<h3>Overall Rating:</h3>
<h3>{{major_choice.0.ProfessorRating}}</h3>
</div>
Should work after some adjustments of the values. Not sure if you want the grey box all the way to the right or left.
I achieved this by using relative positioning. And floating both elements left so they stack horizontally. I believe this is what you wanted.
By adding the element within your main container, absolute positioning will work nicely. This will then scroll with the container. If you require it to stay where it is on the screen, you will need to use fixed positioning, it will then be relative to your viewport. So keep in mind when adjusting your top and right positioning to compensate.
.Menu,
.Content {
position: fixed;
background-color: #CCC;
left: 10%;
right: 10%;
}
.Menu {
top: 10px;
height: 50px;
}
.Content {
top: 70px;
bottom: 10px;
overflow: auto;
padding-right: 250px;
}
.Floating {
position: absolute;
background-color: #EDEDED;
right: 20px;
top: 20px;
width: 210px;
height: auto:
}
<div class="Menu">
This is the menu
</div>
<div class="Content">
<div class="Floating">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer euismod lectus eros, placerat euismod nisl pharetra eget. Fusce commodo ipsum non ipsum fringilla dignissim. Integer eu mi ligula. In hac habitasse platea dictumst. Cras aliquet luctus felis
nec rutrum. In in magna eros. Donec tellus ipsum, auctor et eleifend non, mollis quis mauris. Praesent cursus malesuada mattis.
</div>
<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer euismod lectus eros, placerat euismod nisl pharetra eget. Fusce commodo ipsum non ipsum fringilla dignissim. Integer eu mi ligula. In hac habitasse platea dictumst. Cras aliquet luctus
felis nec rutrum. In in magna eros. Donec tellus ipsum, auctor et eleifend non, mollis quis mauris. Praesent cursus malesuada mattis. Morbi id quam libero. Donec laoreet ullamcorper lobortis. Etiam quis est ac lacus varius malesuada. Nunc venenatis
rutrum dui, id euismod nunc porttitor id. Nulla id sapien imperdiet, ullamcorper felis et, rhoncus tortor. Quisque purus tellus, molestie a urna in, bibendum bibendum mauris. Nunc aliquet ornare tincidunt. Praesent leo diam, fermentum nec tempor in,
pellentesque eget velit. Aenean luctus mauris et turpis vehicula, at tristique ex gravida. Vivamus finibus, tellus vel volutpat facilisis, enim metus mattis mi, quis dictum tortor mi a mauris. Pellentesque malesuada tellus non consectetur feugiat.
Proin rutrum sem nec odio varius tincidunt. Quisque egestas enim et orci scelerisque, quis viverra lectus tristique. Donec consectetur, lacus sed vehicula lacinia, ipsum arcu consequat odio, sed porta erat neque eu lacus. Proin consequat quam vitae
nisl vulputate, ut imperdiet justo ultricies. Phasellus dictum vestibulum ullamcorper. Quisque lobortis eros sed ante porta ultricies. Suspendisse sit amet purus non enim fringilla pellentesque. Sed posuere, metus ut venenatis pretium, enim urna laoreet
sapien, accumsan condimentum mauris nisi sed elit. Nunc mollis sit amet enim ac placerat. Donec elementum consectetur ipsum in molestie. Fusce auctor sollicitudin lorem a pharetra. Vestibulum blandit consectetur sagittis. Nullam varius commodo dictum.
Sed tempus a nulla nec feugiat. Sed pharetra mattis velit sed sollicitudin. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aenean sit amet vehicula felis. Nullam faucibus interdum rhoncus. Proin eget velit non
nunc dignissim vestibulum sit amet id nulla. Nunc a lectus mauris. Sed sagittis orci ullamcorper nisi ullamcorper dictum. Etiam ut tellus tortor. In a molestie tortor. Quisque turpis tellus, fermentum euismod eros a, vulputate aliquam sapien. Integer
nunc dui, scelerisque nec interdum id, auctor ut ante. Curabitur pharetra dui vitae tellus tincidunt auctor. Etiam eget fringilla massa. Phasellus auctor lorem hendrerit massa porttitor, luctus consequat leo semper. Curabitur sollicitudin est sapien,
sed vulputate neque finibus ac. Aliquam pulvinar enim ac mi congue, eu dapibus velit imperdiet. Suspendisse pretium tellus eu urna auctor, quis sodales erat varius. Aenean eget felis mi. Suspendisse non tellus in mauris congue finibus et et risus.</div>
</div>
I am creating a self-help website for practice purposes only. I'm having trouble placing an 'aside' column (containing relevant quotes throughout history) on the right-side of my main content (excluding title & footer).
The 'float' property places the aside column to the right of all the content, but places it at the bottom. I have tried using 'flexbox' and this seems to solve the problem regarding the 'aside' element, but it places the footer vertically on-top of the content (& covering part of it) instead of horizontally at the bottom, along with moving the header to the left of the content (it should be at the top under the static nav-bar). This is what it does:
Can anybody help me? I'd really appreciate it.
body {
display: flex;
width: 800px;
height: auto;
margin-right: auto;
margin-left: auto;
text-align: center;
font-family: garamond, serif;
}
#navbar {
position: fixed;
right: 0;
left: 0;
}
.links {
margin: 8px;
padding: 16px;
background-color: orange;
-webkit-border-radius: 75%;
text-decoration: none;
color: black;
font-weight: 900;
transition: opacity 0.5s linear;
}
.links:hover {
opacity: 0.30;
width:
}
header {
font-size: 25px;
padding-top: 30px;
color: orange;
text-shadow: 8px 8px 16px grey;
}
#section1 {
padding-top: 8px;
}
#section2 {
padding-top: 16px;
padding-bottom: 16px;
}
section p {
text-align: justify;
}
#asideh2 {
text-align: center;
}
aside {
font-size: 12px;
width: 15%;
text-align: justify;
float: right;
}
footer {
justify-content: space-between;
background-color: #d3d3d3;
font-size: 12px;
padding: 8px;
}
<!DOCTYPE html>
<html lang="en-GB">
<head>
<meta charset="utf-8">
<title>Self-Help Emporium</title>
</head>
<body>
<nav id="navbar">
<a class="links" id="link1" href="#">Home</a>
<a class="links" id="link2" href="#">About</a>
<a class="links" id="link3" href="#">Blog</a>
<a class="links" id="link4" href="#">Contact</a>
<a class="links" id="link5" href="#">Disclaimer</a>
</nav>
<header>
<h1>Self-Help Emporium</h1>
<h2>Your Trusted Source for Self-help Material</h2>
</header>
<article>
<section id="section1">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In tempus, elit ut vestibulum maximus, orci felis pulvinar velit, malesuada faucibus est lacus et arcu. Cras commodo est nec venenatis blandit. Nullam pretium feugiat ultricies. Proin accumsan, mi et convallis ullamcorper, turpis leo pretium justo, non tincidunt mi est vitae purus. Aenean ultrices scelerisque lacus, eget sagittis justo consectetur ac. Vestibulum interdum consectetur nibh ut lacinia. Aliquam ac fringilla lacus, ut scelerisque purus. Nulla faucibus fringilla varius. Quisque enim ante, placerat eget semper vitae, pulvinar bibendum mi. Maecenas pulvinar tempus tellus, ut consectetur purus feugiat vel. Nulla eget viverra urna. Nulla eu ex eu nisi accumsan scelerisque. Nullam et nulla bibendum, condimentum odio eget, aliquet sem. Nunc ornare volutpat urna ut feugiat.</p>
<p>Maecenas scelerisque leo ipsum, id molestie dui auctor ac. Nunc feugiat laoreet tortor et convallis. Duis quis nisl et libero consectetur bibendum tempor at lectus. Praesent tristique, mi semper pharetra fermentum, metus orci porta ipsum, sit amet accumsan dolor tellus sit amet magna. Nam iaculis odio vel gravida egestas. Vestibulum venenatis est non orci pharetra ultricies. Fusce urna leo, commodo a ex vel, cursus semper sem. Etiam rutrum at est ut volutpat. Etiam vitae ullamcorper lectus. Duis tempus maximus nisi, eu aliquet felis congue ut. Donec erat arcu, malesuada eu ligula quis, consectetur suscipit mauris. Mauris commodo tortor ac elit euismod facilisis.</p>
<p>Vestibulum porttitor pulvinar erat finibus molestie. In at felis eu augue feugiat ullamcorper in ut sapien. Pellentesque gravida eros non sapien convallis ullamcorper. Vivamus magna odio, tristique sed sapien aliquet, dictum aliquet augue. Nunc lorem quam, rutrum quis nulla euismod, ornare aliquet urna. Nullam lobortis malesuada nisl, vitae mattis purus pharetra nec. Duis enim est, malesuada quis odio ac, rutrum luctus nisl. Morbi tortor risus, posuere quis orci ut, pulvinar luctus lectus. Mauris auctor risus ut dapibus mattis. Suspendisse euismod felis mauris, sit amet rhoncus lacus posuere et. In scelerisque lacus vel arcu pellentesque facilisis. Aliquam nisl tortor, cursus ac tincidunt luctus, malesuada quis lectus.</p>
</section>
<section id="section2">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In tempus, elit ut vestibulum maximus, orci felis pulvinar velit, malesuada faucibus est lacus et arcu. Cras commodo est nec venenatis blandit. Nullam pretium feugiat ultricies. Proin accumsan, mi et convallis ullamcorper, turpis leo pretium justo, non tincidunt mi est vitae purus. Aenean ultrices scelerisque lacus, eget sagittis justo consectetur ac. Vestibulum interdum consectetur nibh ut lacinia. Aliquam ac fringilla lacus, ut scelerisque purus. Nulla faucibus fringilla varius. Quisque enim ante, placerat eget semper vitae, pulvinar bibendum mi. Maecenas pulvinar tempus tellus, ut consectetur purus feugiat vel. Nulla eget viverra urna. Nulla eu ex eu nisi accumsan scelerisque. Nullam et nulla bibendum, condimentum odio eget, aliquet sem. Nunc ornare volutpat urna ut feugiat.</p>
<p>Maecenas scelerisque leo ipsum, id molestie dui auctor ac. Nunc feugiat laoreet tortor et convallis. Duis quis nisl et libero consectetur bibendum tempor at lectus. Praesent tristique, mi semper pharetra fermentum, metus orci porta ipsum, sit amet accumsan dolor tellus sit amet magna. Nam iaculis odio vel gravida egestas. Vestibulum venenatis est non orci pharetra ultricies. Fusce urna leo, commodo a ex vel, cursus semper sem. Etiam rutrum at est ut volutpat. Etiam vitae ullamcorper lectus. Duis tempus maximus nisi, eu aliquet felis congue ut. Donec erat arcu, malesuada eu ligula quis, consectetur suscipit mauris. Mauris commodo tortor ac elit euismod facilisis.</p>
<p>Vestibulum porttitor pulvinar erat finibus molestie. In at felis eu augue feugiat ullamcorper in ut sapien. Pellentesque gravida eros non sapien convallis ullamcorper. Vivamus magna odio, tristique sed sapien aliquet, dictum aliquet augue. Nunc lorem quam, rutrum quis nulla euismod, ornare aliquet urna. Nullam lobortis malesuada nisl, vitae mattis purus pharetra nec. Duis enim est, malesuada quis odio ac, rutrum luctus nisl. Morbi tortor risus, posuere quis orci ut, pulvinar luctus lectus. Mauris auctor risus ut dapibus mattis. Suspendisse euismod felis mauris, sit amet rhoncus lacus posuere et. In scelerisque lacus vel arcu pellentesque facilisis. Aliquam nisl tortor, cursus ac tincidunt luctus, malesuada quis lectus.</p>
</section>
</article>
<form>
</form>
</main>
<footer>
<span>Mathew J. M. | 2018 ™</span>
<span>Last updated: 11/09/2018</span>
</footer>
<aside>
<h2 id="asideh2">Self-Help Quotes:</h2>
<p>No matter where you are in life, you’ll save a lot of time by not worrying too much about what other people think about you. The earlier in your life that you can learn that, the easier the rest of it will be.</p>
<p>Our only limitations in life are those we set up in our own minds.</p>
<p>Focus on what you can control: your actions. How you react to negative feelings will be the key to your success.</p>
<p>Don’t Take Anything Personally. Nothing others do is because of you. What others say and do is a projection of their own reality, their own dream. When you are immune to the opinions of others, you won’t be the victim of needless suffering.</p>
</aside>
</body>
</html>
Edited: As you can see in the screenshot, the footer is vertical and is covering part of the main content. The header has been moved to the left of the main content. This has been caused by using 'flexbox'. If I don't use 'flexbox', the 'Self-Help Quotes' in the 'aside' element is placed under the content and not at the side.
I have solved this by adding a 'div' container with flexbox. I have kept the heading, nav-bar and footer outside of the flexbox container.
Note: In the picture below I have yet to add space and style for the 'aside' element.
You can use flexbox display: flex with fixed or sticky position position: fixed.
I've been trying to get a background picture to actually be in the back and not in the front.
I've tried with z-index, positioning en making divs in divs. But nothing really worked out.
The Screenshot of the issue.:
https://gyazo.com/4e9ae692ce1280ba8ea0ec37cb54930b
The above picture needs to be in the background so the box thing can go up in front.
The HTML code:
<div id="image">
<img src="DSC_0043.png" width="800" height="800">
<div id="content">
<div id="tabbox">-
<div class="tab">
Here follows like the actual content, which you of course don't need to know. it's just a bunch of text etc.
The CSS code:
#image{
position: relative;
z-index: 2;
}
#content{
width: 75%;
background-color: black;
position: absolute;
margin-left: 12.5%;
padding-bottom: 5.5%;
z-index: 1;
}
Using pure CSS, you can implement a background image even without a separate img tag.
Try using background-image:
#content {
/* Your CSS here... */
background-image: url("DSC_0043.png"),
}
EDIT:
If you want to repeat that image, you can specify background-repeat:
#content {
background-image: url("DSC_0043.png"),
background-repeat: repeat, /* Put no-repeat for non-repeating image */
}
if you want that image goes behind everything else, you should try with background-size: cover;
I didn't understand your problem very well, I hope that this will help you.
A slight rework of your code, you can accomplish this with css.
I used an image from google to show this but to explain I have two divs nested.
The parent div content sets the background image and adjusts the positioning of itself.
The child div box has the text and it's own width and height.
The css background-image: url ("path/to/image") and background-repeat: no-repeat make this possible. Feel free to manipulate the example I gave to add to your understanding.
#content {
width: 100%;
height: 100%;
background-image: url('https://images-na.ssl-images-amazon.com/images/I/61xo5qJF0nL._SY355_.jpg');
background-repeat: no-repeat;
position: absolute;
margin-left: 12.5%;
padding-bottom: 5.5%;
z-index: 1;
}
#box{
width: 350px;
height: 150px;
color: purple;
}
<div id="content">
<div id="box">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam accumsan turpis diam, non dictum dui mollis eu. Aliquam erat volutpat. Phasellus faucibus bibendum felis a posuere. Maecenas sit amet neque a sem mattis ornare sed vel mauris. Mauris vel semper nisl. Aliquam erat volutpat. Suspendisse potenti. Proin vulputate bibendum nulla, sit amet placerat arcu viverra in. Duis ultricies risus quis venenatis hendrerit. Sed elit lorem, suscipit at odio in, mollis dignissim dolor. Nulla a sem nec dolor consequat sodales. Nullam risus velit, venenatis nec quam in, tincidunt maximus velit. Cras lacus ex, pellentesque vel sapien quis, condimentum vulputate sapien. Maecenas at pellentesque lacus. Mauris ac ligula quam. Integer leo est, vulputate sed pulvinar ut, consequat vel risus.
Phasellus lectus neque, rutrum sit amet nisi eget, imperdiet scelerisque mauris. Nam elementum pretium sem ut sollicitudin. Cras in finibus eros. Aliquam sit amet metus vitae tellus vehicula pretium. Etiam vestibulum congue luctus. In quis auctor mi, sit amet tempor metus. Sed ex massa, porta a magna et, molestie vestibulum ipsum.
Sed congue, ligula non fringilla scelerisque, risus massa fermentum tortor, ornare feugiat justo massa molestie nisi. Ut id efficitur lacus. Duis ullamcorper mi nec tristique fermentum. Donec pellentesque vel massa et commodo. Integer semper gravida vulputate. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Mauris at urna hendrerit, blandit ligula nec, dapibus erat. Aliquam ullamcorper orci nec quam euismod, sed mollis purus volutpat.
Proin at velit ut nunc mattis sodales a id ante. Aliquam a lacinia odio. Vivamus vel vulputate magna. Duis iaculis scelerisque tincidunt. Sed cursus leo vitae libero efficitur venenatis. Fusce suscipit dui nibh, nec tristique sem sodales ut. Quisque ac blandit lorem, pretium ullamcorper orci. Vivamus posuere ligula neque, at laoreet nibh semper consectetur. Duis suscipit sollicitudin quam sed volutpat. Proin tellus neque, porta id rutrum nec, posuere at nibh. Fusce venenatis efficitur metus, quis feugiat metus imperdiet et.
Sed aliquam viverra finibus. Vestibulum gravida a tortor et tempus. Aliquam at tortor purus. Maecenas malesuada magna justo. Aenean elementum sagittis aliquam. Donec lobortis id orci id pharetra. In non purus vitae erat fermentum condimentum non nec metus.</div>
</div>
I'm trying to lay out my site in this way:
The image div will contain a variable-sized image, and the image should be vertically and horizontally aligned. The text div will contain a lot of text.
This could easily be done with a table, but I'm trying to make this responsive so that once the site is too small horizontally that the textDiv will no longer float next to imageDiv and will then fall underneath.
The problem I'm having is that the the divs will just take up the required space of their content. How do I ensure that these two will remain the same size when they are floated next to each other?
Once the divs no longer float next to each other them being the same size wouldn't make sense anymore so that functionality would no longer be required.
I found Flex as a possible solution but it isn't well supported. I should mention that their widths will be set to a percentage of the parentDivs width.
You can achieve this using:
Absolute positioning with padding
Flex layout
.parentDiv {border: 4px solid black;}
.imageDiv {border: 4px solid tomato;}
.textDiv {border: 4px solid skyblue;}
.imageDiv img { max-width: 100%; }
#media (min-width: 768px) {
#first .imageDiv { width: 50%; max-width: 50%; box-sizing: border-box; }
#first .parentDiv { position: relative; min-height: 150px; }
#first .parentDiv > div { padding-left: 50%; }
#first .imageDiv { position: absolute; top: 0; left: 0; }
#second .parentDiv { display: flex; }
#second .imageDiv, #second .textDiv { flex-basis: 50%; }
}
<h2>Using absolute positioning and padding</h2>
<div id="first">
<div class="parentDiv"><div>
<div class="imageDiv">
<img src="http://sstatic.net/stackexchange/img/logos/so/so-logo-med.png">
</div>
<div class="textDiv">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean quis cursus erat. In sit amet condimentum nulla, in elementum lorem. Duis iaculis, nibh nec iaculis semper, nisi neque fringilla metus, in faucibus urna urna non libero. Nullam aliquet ligula lorem, imperdiet lobortis ex malesuada ac. In sollicitudin eros eu dui iaculis, ac rutrum metus dapibus. Nam ac ex gravida, fringilla lectus nec, posuere sem. Nunc sit amet mi quis quam aliquet viverra. Duis congue gravida diam, eget ullamcorper leo faucibus vitae. Duis pretium lacus id nisl suscipit, lobortis rhoncus nisl blandit. Proin quis vestibulum purus, eu faucibus lectus. Vivamus enim turpis, suscipit nec cursus ac, sollicitudin at quam. Curabitur venenatis nisi tellus, a molestie ex mattis ac. Nulla nec dui ac tellus lacinia posuere at vel ante. Nulla iaculis eleifend dignissim.
Sed at lobortis neque. Nunc sapien ante, convallis at lobortis id, suscipit vitae augue. Interdum et malesuada fames ac ante ipsum primis in faucibus. Mauris commodo vehicula felis, in iaculis turpis eleifend vitae. Sed non iaculis turpis, a accumsan ipsum. Vestibulum nec pretium tortor, in bibendum nulla. Suspendisse id tincidunt felis. Sed eleifend, ipsum sit amet condimentum accumsan, metus mi euismod mi, at ullamcorper odio nunc ut leo. Donec pellentesque imperdiet enim, nec varius leo semper eu. Aenean dictum, justo pellentesque cursus consequat, nunc nulla aliquam augue, eget dignissim metus erat ac libero. Aliquam tristique orci sapien, at pretium leo molestie et. Ut quis auctor nisl.
Proin quis placerat urna. Aliquam non posuere elit, tincidunt sollicitudin libero. Nunc vel mauris sit amet nunc varius blandit vel vel felis. Sed dictum, lorem vitae commodo eleifend, purus libero sagittis mauris, et mattis mauris tortor et enim. Donec vel tincidunt mauris. Proin aliquam dui sed lorem auctor, id congue leo fermentum. Ut laoreet purus quis justo malesuada, sed gravida eros hendrerit. Quisque eleifend pulvinar leo ut volutpat. Curabitur nec lectus augue. Donec congue turpis sed lectus lobortis molestie. Aenean posuere in enim quis mattis. Morbi dui eros, tincidunt id hendrerit nec, tempor a mauris. Maecenas vel sem mi. Maecenas lacinia non augue at egestas.
Phasellus vestibulum elementum feugiat. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. In ullamcorper sapien elit, nec pretium sapien sollicitudin in. Donec placerat urna eget erat tincidunt imperdiet. Pellentesque sed nisi congue quam accumsan tristique sed ac diam. Nunc auctor non leo et ornare. Nam ornare pharetra lacus ut commodo. Sed sem nunc, porttitor a venenatis vel, cursus sed dui.
Morbi congue augue in tortor porta, vel condimentum orci feugiat. Donec lacinia nisl sed orci venenatis lobortis. Ut nulla eros, malesuada ut vestibulum cursus, laoreet et augue. Nullam varius dapibus lorem sit amet vestibulum. Pellentesque ultricies eu elit ac ullamcorper. Pellentesque viverra ultrices augue, ac vestibulum mi pretium ut. Vestibulum et ex eget tortor sodales convallis non a quam. Nam facilisis gravida lacinia. Quisque accumsan massa et accumsan interdum. Mauris vestibulum volutpat metus, vel pretium urna auctor eget. Vestibulum aliquet fringilla tristique. Nam ipsum quam, faucibus eget magna sed, facilisis molestie lacus.
</div>
</div></div>
</div>
<h2>Using flex layout</h2>
<p><b>Firefox specific problem:</b> the width of the image interfere with <code>flex-basis</code> of <code>imageDiv</code>.
<br>Give the width of the image in percentage.</p>
<div id="second">
<div class="parentDiv">
<div class="imageDiv">
<img src="http://sstatic.net/stackexchange/img/logos/so/so-logo-med.png">
</div>
<div class="textDiv">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean quis cursus erat. In sit amet condimentum nulla, in elementum lorem. Duis iaculis, nibh nec iaculis semper, nisi neque fringilla metus, in faucibus urna urna non libero. Nullam aliquet ligula lorem, imperdiet lobortis ex malesuada ac. In sollicitudin eros eu dui iaculis, ac rutrum metus dapibus. Nam ac ex gravida, fringilla lectus nec, posuere sem. Nunc sit amet mi quis quam aliquet viverra. Duis congue gravida diam, eget ullamcorper leo faucibus vitae. Duis pretium lacus id nisl suscipit, lobortis rhoncus nisl blandit. Proin quis vestibulum purus, eu faucibus lectus. Vivamus enim turpis, suscipit nec cursus ac, sollicitudin at quam. Curabitur venenatis nisi tellus, a molestie ex mattis ac. Nulla nec dui ac tellus lacinia posuere at vel ante. Nulla iaculis eleifend dignissim.
Sed at lobortis neque. Nunc sapien ante, convallis at lobortis id, suscipit vitae augue. Interdum et malesuada fames ac ante ipsum primis in faucibus. Mauris commodo vehicula felis, in iaculis turpis eleifend vitae. Sed non iaculis turpis, a accumsan ipsum. Vestibulum nec pretium tortor, in bibendum nulla. Suspendisse id tincidunt felis. Sed eleifend, ipsum sit amet condimentum accumsan, metus mi euismod mi, at ullamcorper odio nunc ut leo. Donec pellentesque imperdiet enim, nec varius leo semper eu. Aenean dictum, justo pellentesque cursus consequat, nunc nulla aliquam augue, eget dignissim metus erat ac libero. Aliquam tristique orci sapien, at pretium leo molestie et. Ut quis auctor nisl.
Proin quis placerat urna. Aliquam non posuere elit, tincidunt sollicitudin libero. Nunc vel mauris sit amet nunc varius blandit vel vel felis. Sed dictum, lorem vitae commodo eleifend, purus libero sagittis mauris, et mattis mauris tortor et enim. Donec vel tincidunt mauris. Proin aliquam dui sed lorem auctor, id congue leo fermentum. Ut laoreet purus quis justo malesuada, sed gravida eros hendrerit. Quisque eleifend pulvinar leo ut volutpat. Curabitur nec lectus augue. Donec congue turpis sed lectus lobortis molestie. Aenean posuere in enim quis mattis. Morbi dui eros, tincidunt id hendrerit nec, tempor a mauris. Maecenas vel sem mi. Maecenas lacinia non augue at egestas.
Phasellus vestibulum elementum feugiat. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. In ullamcorper sapien elit, nec pretium sapien sollicitudin in. Donec placerat urna eget erat tincidunt imperdiet. Pellentesque sed nisi congue quam accumsan tristique sed ac diam. Nunc auctor non leo et ornare. Nam ornare pharetra lacus ut commodo. Sed sem nunc, porttitor a venenatis vel, cursus sed dui.
Morbi congue augue in tortor porta, vel condimentum orci feugiat. Donec lacinia nisl sed orci venenatis lobortis. Ut nulla eros, malesuada ut vestibulum cursus, laoreet et augue. Nullam varius dapibus lorem sit amet vestibulum. Pellentesque ultricies eu elit ac ullamcorper. Pellentesque viverra ultrices augue, ac vestibulum mi pretium ut. Vestibulum et ex eget tortor sodales convallis non a quam. Nam facilisis gravida lacinia. Quisque accumsan massa et accumsan interdum. Mauris vestibulum volutpat metus, vel pretium urna auctor eget. Vestibulum aliquet fringilla tristique. Nam ipsum quam, faucibus eget magna sed, facilisis molestie lacus.
</div>
</div>
</div>
The image div will contain a variable-sized image, and the image
should be vertically and horizontally aligned. The text div will
contain a lot of text.
This could easily be done with a table, but I'm trying to make this
responsive so that once the site is too small horizontally that the
textDiv will no longer float next to imageDiv and will then fall
underneath.
If it is easily done with a table layout for you, then just use a table layout. Make it responsive by adding an appropriate media query and change the layout. By table layout I mean display: table (not the table element).
It will be as easy as:
#parent { display: table; }
#parent > div { display: table-cell; width: 50%; vertical-align: middle; }
Do take care to have a max-width specified on the image to keep it within bounds:
#imgWrap { text-align: center; }
#imgWrap > img { max-width: 100%; }
The vertical-align and text-align will help you control the alignment of the image.
The problem I'm having is that the the divs will just take up the
required space of their content. How do I ensure that these two will
remain the same size when they are floated next to each other?
Fixing the width with the display: table-cell will take care of that.
Once the divs no longer float next to each other them being the same
size wouldn't make sense anymore so that functionality would no longer
be required.
Just add a media query for the break point that you need and simply reset the display back to block:
#media screen and (max-width:480px) {
#parent { display: block; }
#parent > div { display: block; width: auto; }
}
Snippet:
* { box-sizing: border-box; padding: 0; margin: 0; }
#parent { border: 1px solid #00f; width: 75%; margin: 0 auto; display: table; }
#parent > div {
border: 1px solid #f00;
display: table-cell; width: 50%;
vertical-align: middle;
}
#imgWrap { text-align: center; }
#imgWrap > img { max-width: 100%; }
#media screen and (max-width:480px) {
#parent { display: block; }
#parent > div { display: block; width: auto; }
}
<div id="parent">
<div id="imgWrap">
<img src="//lorempixel.com/240/120" />
</div>
<div id="contentWrap">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean quis cursus erat. In sit amet condimentum nulla, in elementum lorem. Duis iaculis, nibh nec iaculis semper, nisi neque fringilla metus, in faucibus urna urna non libero. Nullam aliquet ligula lorem, imperdiet lobortis ex malesuada ac. In sollicitudin eros eu dui iaculis, ac rutrum metus dapibus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean quis cursus erat.
</p>
</div>
</div>
Fiddle: http://jsfiddle.net/abhitalks/29vLq11o/3/
I'm not sure I completely understand your question, but you can set the width of each to 50% and then float them left. They will retain their size side-by-side until the screen becomes to small:
.image {
float:left;
width:50%;
}
.image img {
display:block;
max-width:100%;
}
.text {
float:left;
width:50%;
}
http://jsfiddle.net/rhn76m5z/3/
I have a menu on the left side of my page and the content on the rest of the page. I have a dark, textured background so I want a semi-transparent background for the leftmenu div and a semi-transparent background for the content div. However, it seems like the body div is overlapping the menu div and stacking its transparency and also making the content of the menu div transparent.
I would rather have a space between the two sections. Could someone take a look at my code and offer a suggestion?
I have some code listed below but take a look at the jsfiddle to get the full picture.
http://jsfiddle.net/5xmze/ (Note, the links should be the same color as the header)
CSS:
#body{
padding-left:2px;
width: 85%;
position: relative;
background-color:rgba(0,0,0,0.6);
}
#leftside {
float: left;
width: 15%;
height: 100%;
}
HTML:
<div><span id="leftside">
<ul class="leftmenu">
<li class="leftmenu">Home</li>
<li class="leftmenu">Projects</li>
<li class="leftmenu">Resume</li>
<li class="leftmenu">Contact</li>
</ul></span>
</div>
<div id="body">
Content here...
</div>
Here's what I'm attempting to accomplish:
The best way would be to put the menu, and the body into the same parent div, then float:left; the body so it shows up beside the menu.
Don't forget to set a width to both elements, because if #body's width is bigger than space available on the page, it will show up under the menu.
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready( function(){
$(window).resize( function() {
var s = $("body").width();
$("body").css({ "min-width":s+"px" });
});
});
</script>
<style>
/* style.css */
body {
font-size: 1em;
background-image:url('http://i1358.photobucket.com/albums/q764/kenny_johnson5/blackorchid_zpsc8d78a87.png');
color:#FFF;
font-family:Arial;
width:85%;
margin-left:16%;
}
h1 {
font-family:Cambria,Serif;
color:#81E500;
text-align:center;
}
#top{
width: 85%;
position: relative;
}
#body{
padding-left:90px;
width: 85%;
position: relative;
background-color:rgba(0,0,0,0.6);
}
a {
color:#81E500;
font-family:Cambria,Serif;
font-size:1.5em;
}
#leftside {
float: left;
width: 15%;
height: 100%;
margin-left:-15%;
z-index:999;
}
ul.leftmenu {
list-style-type:none;
margin:0px;
padding:1px;
background-color:rgba(0,0,0,0.6);
border: 1px solid;
border-color:#000;
height:100%;
}
li.leftmenu {
padding:5px;
}
</style>
<html>
<div><div id="leftside">
<ul class="leftmenu">
<li class="leftmenu">Home</li>
<li class="leftmenu">Projects</li>
<li class="leftmenu">Resume</li>
<li class="leftmenu">Contact</li>
</ul></div>
</div>
<div id="body">
<div id="top">
<h1>Header</h1>
</div>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus tincidunt erat sit amet dolor imperdiet dignissim. Nunc eu enim erat. Suspendisse commodo faucibus risus at facilisis. Phasellus tortor urna, fringilla sed blandit non, porta vel enim. Vivamus placerat, risus et molestie elementum, risus elit dignissim elit, non porttitor nisl tortor sed lorem. Maecenas scelerisque mattis massa, vel blandit erat blandit sed. Vivamus erat augue, varius ac aliquet non, commodo id massa. Maecenas sit amet est posuere turpis ultrices aliquam. Nulla feugiat ultrices diam vitae egestas. Phasellus risus augue, dapibus nec condimentum non, tempus eu massa. Etiam sodales sodales dolor eu convallis.
</p>
<p>
Aenean in dignissim metus. Suspendisse placerat pharetra justo, et tristique neque vestibulum non. Quisque malesuada scelerisque diam eget suscipit. Donec non sollicitudin justo. Etiam sit amet massa felis. Maecenas aliquet cursus tristique. Etiam sollicitudin augue in risus venenatis rhoncus. Pellentesque tellus diam, porttitor in dapibus eu, rutrum eu lectus. Vestibulum luctus hendrerit augue vitae interdum. Donec in turpis malesuada arcu tempor placerat. Aliquam eget nisl ipsum. Cras blandit elementum vulputate. Ut vulputate ullamcorper urna, quis congue mauris laoreet nec. Morbi vitae dui eros.
</p>
<p>
Phasellus rhoncus ultrices sem et dictum. Ut ut nisl eget eros porttitor commodo auctor vitae leo. Quisque sed nulla augue, vel venenatis augue. Pellentesque bibendum sodales lectus, quis malesuada risus consectetur a. Aliquam lobortis aliquet vulputate. Duis sed velit est, in venenatis est. Vivamus viverra lacinia sapien non sodales. Aenean eleifend quam diam, id gravida tellus. Praesent dui sem, volutpat eu blandit in, volutpat ornare nulla. Nunc sed eros dolor.
</p>
<p>
Quisque sit amet diam nisl, volutpat interdum arcu. Proin et justo lorem. Mauris vitae egestas lacus. Nullam ut laoreet turpis. Donec eget metus enim, id porta orci. Nam condimentum feugiat tempor. Nunc ultricies pellentesque euismod. In hac habitasse platea dictumst. Etiam fringilla bibendum sapien, eu vestibulum nisi imperdiet tempus. Duis tincidunt magna id sapien porta vel aliquam massa tincidunt. Maecenas ut metus id augue congue scelerisque id nec enim. Ut ac nibh est, et laoreet orci. Nulla fermentum laoreet augue, in vulputate risus varius vel. Sed ac nunc quis tortor scelerisque rutrum.
</p>
<p>
Nullam adipiscing ultricies lacus ac pretium. In hac habitasse platea dictumst. Nullam convallis libero non augue sollicitudin mattis. Nunc commodo pharetra magna, tempor sagittis sem vehicula nec. Quisque massa ligula, gravida nec fringilla quis, tempus vel dolor. Nam et sem bibendum mi consectetur tincidunt. Nam placerat venenatis odio sit amet imperdiet. Integer luctus quam quis quam lobortis aliquam. Cras dignissim semper erat, ac laoreet leo volutpat quis. </p>
</div>
</body>
</html>