positioning elements in a certain place - html

I've been learning HTML and CSS for a little while now but I am pretty self taught so sorry if this seems to be a pretty basic question.
I have this container in the middle of my page (it's a carousel but I don't think that makes a difference) and I'm trying to position two things: a large word on top of it (inside a div) and navigation buttons below it. Currently, I've positioned them both there using position: fixed; and top and left elements. This isn't ideal of course because on mobile and devices of different widths these elements are in completely different positions.
Here's the HTML for the container and navigation buttons, the carousel controls are there too:
<div id="container">
<input hidden type="radio" name="carousel-control" id="button_a" checked/>
<input hidden type="radio" name="carousel-control" id="button_b"/>
<input hidden type="radio" name="carousel-control" id="button_c"/>
<input hidden type="radio" name="carousel-control" id="button_d"/>
<div id="title">explore</div> /*the text I want on top*/
<div id="carousel">
<div class="p-wrapper">
<section class="panel_a">
<h2>Panel a</h2>
<div class="headerdivider"></div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus ornare faucibus diam id maximus. Fusce at efficitur nunc. Curabitur sed ullamcorper orci. Nam nulla enim, ultricies nec lectus a, commodo volutpat nisi. Pellentesque facilisis lacinia ante, eu pulvinar ante varius a. Fusce tincidunt efficitur tempor. Praesent pretium felis consectetur posuere sagittis. Sed luctus nisl non vestibulum semper. Vivamus mi velit, porttitor ac malesuada at, vulputate venenatis augue.</p>
<p>Morbi faucibus, nisi ac vulputate mattis, turpis tortor maximus nibh, nec interdum lectus sem sit amet enim. Integer non nulla vitae ex gravida egestas. Fusce sodales neque ut erat tempor euismod. Quisque imperdiet rhoncus pellentesque. Fusce vitae efficitur dolor, nec laoreet lacus. Nulla orci purus, cursus sit amet posuere ac, ultrices sed dui. Ut bibendum, dui non euismod lobortis, mi neque pretium lacus, in pulvinar libero mauris eu sem. Morbi ut felis finibus, posuere risus sit amet, malesuada leo.</p>
<p>Nulla quis molestie mi. Cras quis magna dolor. Suspendisse a scelerisque ligula, ullamcorper imperdiet justo. Ut sit amet nisl malesuada, varius turpis quis, convallis urna. Vestibulum sed odio eget lorem porta dapibus. Mauris augue sapien, scelerisque vel neque vitae, vulputate iaculis tellus. Sed accumsan egestas sem congue vehicula. Fusce quis blandit nibh, non bibendum lorem. Integer maximus mi non eros tincidunt pretium. Curabitur tempor nisi a aliquet dictum. Sed pellentesque venenatis ex ac fermentum. Aliquam vitae tincidunt urna.</p>
<p>Nulla sagittis quis purus vitae consequat. Nullam pharetra dignissim tempus. Pellentesque egestas elit vel arcu condimentum euismod ut eu nisi. Fusce erat lectus, placerat quis egestas posuere, sollicitudin non ligula. Suspendisse potenti. Fusce vel leo ultrices, vehicula leo quis, semper quam. Cras mollis quis sem in tempor. Proin sed dui eu arcu efficitur pulvinar at sed leo. Donec rhoncus rhoncus est, eleifend posuere neque aliquet in.</p>
</section>
<section class="panel_b">
<h2>Panel b</h2>
<div class="headerdivider"></div>
{block:AskEnabled}
<p><iframe frameborder="0" scrolling="no" width="100%" height="190" src="http://www.tumblr.com/ask_form/spinningsilvers.tumblr.com" style="background-color:transparent; overflow:hidden;" id="ask_form"></iframe><!--[if IE]><script type="text/javascript">document.getElementById('ask_form').allowTransparency=true;</script><![endif]--></p>{/block:AskEnabled}
</section>
<section class="panel_c">
<h2>Panel c</h2>
<div class="headerdivider"></div>
<p>Fusce convallis arcu mauris, vitae semper ligula maximus vitae. Morbi a nibh id justo ullamcorper tincidunt. Aliquam et mollis mauris, eu varius metus. Praesent eget mi ac diam congue iaculis. Praesent accumsan euismod tempus. Aenean tempor libero et eros pellentesque molestie. Pellentesque malesuada ligula ut hendrerit laoreet. Ut turpis neque, tempor in ultrices sed, hendrerit ac leo. Nam placerat dolor sit amet ligula bibendum malesuada. Donec sagittis ultricies ex id mattis.</p>
<ul>
<li>Aliquam iaculis enim ut mi bibendum tincidunt.</li>
<li>Nulla quis elit in lorem vulputate laoreet.</li>
<li>Praesent non lacus euismod, ultricies lectus ac, vehicula arcu.</li>
<li>Integer lobortis ipsum vitae velit mollis, at commodo ligula suscipit.</li>
</ul>
<p>Sed ut leo et mi tristique feugiat. Nunc fermentum diam mauris, in ultricies neque tincidunt dictum. Quisque ac odio dignissim, ornare enim condimentum, faucibus erat. Sed tortor turpis, imperdiet dignissim lacus eget, dignissim vehicula lorem. Mauris semper mi lacus, sit amet rutrum lacus tincidunt sed. Curabitur vel nisl eu magna placerat pretium. Curabitur malesuada sagittis tortor, eget volutpat mi pellentesque quis.</p>
</section>
<section class="panel_d">
<h2>Panel d</h2>
<div class="headerdivider"></div>
<p>Aenean maximus accumsan mauris. Praesent rutrum vitae purus et mattis. Nunc at mi et diam pulvinar euismod. Curabitur interdum, leo quis tincidunt pharetra, risus nisl mollis velit, interdum consectetur justo orci in nisi. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Phasellus elit turpis, tincidunt non dui et, molestie maximus nisl. Duis pretium eros sed ultricies convallis. Pellentesque vitae tempor lorem, eu laoreet metus. Vivamus sit amet lorem libero. Vestibulum tristique ligula in gravida volutpat. Sed facilisis ipsum velit, et pharetra nisi ullamcorper ut. Maecenas purus dui, tincidunt non ipsum vel, bibendum aliquam elit. Cras rutrum velit diam, semper aliquet libero posuere nec.</p>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Donec ut eleifend lacus. Sed fringilla ullamcorper justo, porttitor cursus nisl. Sed et mi aliquet, rutrum erat at, porttitor felis. Mauris consequat mauris id posuere dictum. Proin nec congue purus, nec rhoncus justo. Cras sit amet neque eu ex feugiat auctor at dignissim augue. Sed commodo tellus id erat lobortis, sit amet elementum felis commodo. Ut massa diam, tristique vel lacinia sed, vulputate eget mauris. Fusce lacinia bibendum iaculis.</p>
</section>
</div> <!-- // .p-wrapper -->
</div> <!-- // #carousel -->
<div id="navigation"> /*the nav buttons that will go below*/
<label for="button_a" class="label_a"> <span>about</span> </label>
<label for="button_b" class="label_b"> <span>message</span> </label>
<label for="button_c" class="label_c"> <span>navigate</span> </label>
<label for="button_d" class="label_d"> <span>social</span> </label>
</div> <!-- // #navigation -->
Here's the CSS for the word I'm trying to put above:
#title {
font-family:'Abril Fatface', cursive;
font-size:40px;
position:fixed;
top:140px;
left:135px;
}
Here's the CSS for the navigation that I'm trying to put below:
#navigation {
position:fixed;
bottom:175px;
justify-content:center;
}
Here's a picture of
what I'm looking to get just with better code of course.
I've tried position: absolute; paired with top: 0px; and left: 0px and I tried putting the div for the words to go above in various spots but nothing's working. (Not sure this makes a difference but I'm working with Tumblr code here.) This is my first time posting here and as I mentioned I'm not too too advanced with coding. Thanks!

You could wrap everything that belongs together actually together, meaning inside a wrapper-element. That way, you can simply use display: flex with flex-flow: column on their parent to lay them out in a column.
Then, with the align-items-property, you can say how/where they should align.
For the navigation I have overridden it with align-self: stretch so that I can center its content.
However, one could have also given the parent align-items: stretch (which is default), and the title align-self: flex-start. Both will give the expected result as long as .carousel is the widest element of the three.
As you see, by using a wrapper-element, you don't need to fiddle around with numbers to position them, and as a bonus, you group them together making it actually semantically clear that they belong together.
body {
display: flex;
}
section {
display: flex;
flex-flow: column;
align-items: flex-start;
}
section > .carousel {
border: 1px solid black;
width: 400px;
height: 300px;
}
section > nav {
align-self: stretch;
display: flex;
justify-content: center;
gap: 0.8rem;
}
<section>
<h1>explore</h1>
<div class="carousel"></div>
<nav>
<a>Some link</a>
<a>Another link</a>
<a>A third link</a>
</nav>
</section>

Related

Pinning footer div to bottom of screen [duplicate]

This question already has answers here:
Fill remaining vertical space with CSS using display:flex
(6 answers)
Closed 1 year ago.
Say we have a div with two children divs:
<div id="parent" style=height:"100%">
<div id="mainbody"></div>
<div id="footer"></div>
</div>
I want the footer div to be pinned at the bottom of the screen, and mainbody top be on top. There may be a lot of vertical content in mainbody, so I want the scroll bar to only show in the mainbody div. Here is a crudely drawn example:
https://imgur.com/a/lNyOZme
How can I achieve this?
You can achieve this layout pretty easily with flexbox and a bit of height calculations.
body {
margin: 0;
}
main {
height: 100vh;
width: 100vw;
display: flex;
flex-direction: column;
}
section {
background: ivory;
padding: 2rem;
overflow-y: scroll;
height: calc(100% - 50px);
}
footer {
height: 50px;
background: royalblue;
color: white;
padding: 1rem;
}
footer p {
text-align: center;
}
<main>
<section>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut vitae mauris commodo velit cursus maximus. Vivamus congue, massa sit amet egestas tempus, nisl arcu vestibulum diam, auctor porta ligula ligula aliquam dolor. Aliquam tincidunt ligula id arcu eleifend, ut viverra neque faucibus. Sed a augue arcu. Sed mattis neque sit amet elit maximus, eget suscipit felis tristique. Sed in tincidunt ipsum. Nulla lectus magna, eleifend eget risus vel, blandit euismod leo. Vivamus egestas, libero sit amet vulputate volutpat, justo massa venenatis libero, quis consectetur ante erat vitae magna. Nullam dictum luctus purus non porta. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.</p>
<p>
Nullam vehicula ullamcorper convallis. Nunc non metus scelerisque, fringilla nisl nec, vulputate libero. Fusce mattis, enim in laoreet pretium, sapien nisi pellentesque felis, non pellentesque felis justo non est. Duis mollis euismod diam, vitae suscipit orci laoreet eu. Ut pulvinar iaculis massa ut mollis. Nunc a elementum velit. Nam porttitor turpis sit amet enim tempor cursus. Duis tempus lectus nibh, quis luctus neque euismod vel. Vivamus porta sem sed ante ultricies, a pretium mi fringilla. Sed interdum elit mi, a scelerisque quam accumsan eu. Phasellus non nulla fringilla, ultrices magna ut, accumsan orci. Curabitur bibendum nisi quis felis eleifend, ut feugiat mauris elementum. Pellentesque tempor eu sem vestibulum laoreet. Etiam ut vestibulum est, eu placerat tellus. Vivamus ac feugiat metus. In hac habitasse platea dictumst.
</p>
<p>
Suspendisse in urna ac erat vestibulum porttitor eget et massa. Integer faucibus ligula sem, eu consectetur leo pellentesque in. Phasellus faucibus turpis non turpis rhoncus ornare. Maecenas nec feugiat erat. Maecenas nec velit tempus, blandit tellus ac, ullamcorper nisi. Etiam ullamcorper nisi id hendrerit tristique. Nullam neque tellus, tincidunt sed congue quis, finibus non nunc. Aliquam vel mauris ante. Aliquam erat volutpat. Integer condimentum, odio in tincidunt sagittis, felis nulla auctor dolor, a malesuada magna nibh quis lectus.
</p>
<p>
Phasellus condimentum augue sit amet erat scelerisque cursus. Sed eget egestas leo, eu placerat eros. Suspendisse potenti. Maecenas varius vestibulum libero, a ullamcorper nisl convallis vel. Donec a ligula id nibh porttitor consequat. Quisque sodales, diam eget finibus dignissim, dui libero fermentum arcu, eget finibus felis orci eu erat. Nullam eleifend sem vitae nulla convallis varius. Suspendisse posuere neque pulvinar consequat faucibus. Mauris quis mauris eu turpis feugiat vestibulum. Etiam laoreet quam ipsum, mollis iaculis neque laoreet et. Quisque volutpat nisl ut sapien tempus, sed vestibulum mauris pharetra. Cras lacinia in arcu eget vestibulum. Maecenas non suscipit velit.
<p>
Praesent convallis fringilla mauris ut tincidunt. Vivamus aliquet ac magna at vehicula. Proin sapien lacus, malesuada id risus vitae, faucibus eleifend sem. Vestibulum nibh elit, dignissim nec augue a, finibus tempus mauris. Donec sed pharetra elit, a imperdiet ipsum. Nullam et est sed risus rutrum finibus. Suspendisse sit amet sem ut quam dignissim rutrum in in odio. Aliquam a lorem orci. Pellentesque varius faucibus ultricies. Cras et pulvinar diam. Praesent id pretium tellus. Donec nec turpis massa. Vivamus ac diam pharetra, accumsan elit vel, efficitur dui. Duis sollicitudin orci nisl, sed gravida urna sagittis vitae.</p>
</section>
<footer>
<p>
footer content
</p>
</footer>
</main>
Assigning a height to the bottom div won't always guarantee you that it'll be placed at the bottom. I'd recommend to simply make use of position property in css. The code below will work with any height you'll assign to your parent container -
#footer{
position: absolute;
bottom: 0px;
}
P.S. - In case the main body is not that big that it doesn't occupy the whole screen and you still want your footer to be at bottom, assign this height: 100vh to your parent container and use the same above code. It should look like this:
#parent{
height: 100vh;
}
#footer{
position: absolute;
bottom: 0px;
}

Create columns without rows (remove blank space below one section)

So I already tried Google for this problem, but couldn't find a solution. I'm currently trying to divide my page in to 50% columns. The left column should contain an image and a form, the right one a text description (with a variable size).
I want the sections of the first column, to not be affected by the ones in the second one, so the same logic as column-count would use. If I use grid-template-columns: 50% 50%; to create my columns and I adjust the browser window, the text in the right column gets longer and pushes down the form under the image, which creates a blank space.
Is there any way using grid-template-columns and not having the content of both related to each other, so there are only two columns and the spacing between each item just stays the same when resizing the browser window?
Forgot to mention that when the browser window gets resized, two columns should merge to one and the order of the sections should be image, text, form. Is there a way to adapt the order when resized?
CSS code used:
.grid-custom{
padding-left: $grid-gutter;
display: grid;
grid-template-columns: 50% 50%;
grid-gap: $grid-gutter;
#include media-query($small) {
padding-left: $grid-gutter-mobile;
grid-gap: $grid-gutter-mobile;
grid-template-columns: 100%;
}
}
HTML does not have to be large to display the concept.
Consider this:
* { box-sizing: border-box; }
.layout-wrap {
display: flex;
min-height: calc(1px + 40vw);
}
.div1 { margin-right: 0.5em; }
.div1, .div2 { width: 50%; border: 4px solid black; }
<div class="layout-wrap">
<div class="div1"> <h1>IMAGE & FORM</h1> </div>
<div class="div2"> <h1>TEXT</h1> </div>
</div>
Using flex you can achieve this. Please refer snippet below for css part.
.container{
display: flex;
}
.col1{
background: blue;
width: 100%;
}
.col2{
background: red;
width: 100%;
}
.form{
width: 100px;
}
<div class="container">
<div class="col1">
<img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxMSEhUTEhIVFhUVFRcXFxgXGBUVFRgWFRcWFxcVFxUYHSggGBolGxcVITEhJSkrLi4uGB8zODMsNygtLisBCgoKDg0OFxAQGC0dHR0rLS0rLS0rLS0tLSstLS0rLS0tLS0tLS0rLS0tLS0tLS0rLSstLS0tLS0tNy03LSs3N//AABEIANcA6wMBIgACEQEDEQH/xAAcAAAABwEBAAAAAAAAAAAAAAAAAQIDBAUGBwj/xAA8EAABAwIEAwYFAgQGAgMAAAABAAIRAyEEEjFBBVFhBhMicYGRMqGx0fBCwQdSYuEUIzNykvGCohYkwv/EABgBAAMBAQAAAAAAAAAAAAAAAAABAgME/8QAIREBAAMAAwEBAQADAQAAAAAAAAECEQMSITFBEzJRYSL/2gAMAwEAAhEDEQA/AOgoQj7soZCtnOTlQyJeVABAN5EMqdRoBomASdAFx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AKyfVZriPEi41Ycd266iGtJ84A8r81VHFukGbgAeggR7ABdNOCI+srcv+mowXGj3rS4yHUGk/wC4CT7g/IKDhOLkVPNtYe7fDf0ComVDIHK3pEEJum+DPKfmIWvSGf8AST78US4nmXH/AJa+5CYz3PUR7CB9AkttCNwVoJCGyMIEIAkSBQTIEESNABAIIwgAiRoID1zkKGUp8opWKjOUo8pTsopQDeQoFhTsokA1kKTBTyEI0Kni+F7ym5r3EUyIcBYuB2JF76QNeui4t2s4OadSocoZTaR4ZGYTpmg6mRaZ10grvVRg9duh5j7rnv8AEXAF7clNmZzPG53wsZI1cf1OImwny3TiThx5+IPi8gOkDpuOiPA4sNeXOe4HmBLosHQ6RlJb4QRoCU3iaUGN+XKFFy/3ViVo3il3OdqYtyDfhYOg+p3VZXxBc4vJvr5RoB0CST/ZIKIjCmRl37pBQGiJMgzI2ahEAnKTJN0AbmyjLPpKk4WjI+Xsm8UMrh7fnzS08RiLJJTtU2KZBThIFFCBQTAIIIIA0EEEAEIQQQHsEPCIwggsVm3AJCJBBDRoIKgAQhEgmQi1VvF8KH03NgwZk7k/nPkBpKCCZOddreCUcJRIbTBc/wATiTmcSHSG5nXyg+pjYWPK6zTJnXdBBC/ww3mgGWKCCCIeiKCCZHWM+acqeEnz+kf3QQSP8W1BrRf+YEj6qr4n8V+n0QQU1+qt8RHDmkwggrZiRoIJgRRwgggAUaJBAGgggkH/2Q==">
<div class="form">
Name: <input type="text"><br>
Class: <input type="text"><br>
Roll No: <input type="text">
</div>
</div>
<div class="col2">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. In vel odio non felis consectetur consectetur ut in felis. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris quis cursus metus. Nulla ligula purus, pellentesque eu dignissim fermentum, finibus nec mi. Curabitur sapien ex, dignissim eu accumsan sollicitudin, semper sed risus. Mauris pulvinar nisi quis semper interdum. Ut eu hendrerit felis, a gravida neque. Donec tincidunt quam et justo tincidunt tincidunt. Donec in quam tempus, tempus erat vel, fringilla lectus. Nullam iaculis non ipsum sodales varius. Etiam sagittis egestas orci non aliquet. Sed venenatis sodales sem, ut ultrices lacus dapibus quis. Curabitur volutpat libero eget volutpat ornare. Phasellus condimentum laoreet risus ultrices vulputate. Vestibulum dignissim ipsum et leo interdum varius. Maecenas vehicula enim id massa tincidunt scelerisque.
Sed diam nisi, aliquet eu massa non, tempor vehicula libero. Nam nec bibendum augue, nec eleifend orci. Quisque efficitur volutpat dui id semper. Duis ac mi leo. Donec eget suscipit ex, suscipit finibus nulla. Sed convallis enim vel lorem porttitor tincidunt. Etiam convallis facilisis urna. Nullam viverra tempor metus, ac pellentesque massa sodales sit amet. Maecenas sed consequat elit, ut volutpat arcu. Nam dui mi, vestibulum ut enim id, fermentum tempor lorem. Nunc eleifend, magna lobortis blandit pulvinar, justo tellus placerat lorem, in venenatis augue velit vel neque.
Donec fermentum cursus urna ut mattis. Fusce tincidunt augue volutpat, molestie dolor ac, vehicula dolor. Duis ante orci, pulvinar sit amet tincidunt volutpat, malesuada et urna. Suspendisse at hendrerit neque. Nullam vel varius tellus. Morbi sed sapien at nisl consequat interdum. Mauris quis odio id nulla suscipit feugiat sit amet et leo. Vivamus viverra pellentesque ligula at aliquam. Sed quis massa ullamcorper, ullamcorper turpis quis, tempus lorem. Sed quis nunc fermentum, commodo ante et, pulvinar tortor. Donec tincidunt sagittis nibh nec consectetur. Proin facilisis pretium mi, vitae pharetra neque sollicitudin at. Etiam condimentum odio id tortor finibus, eget porttitor mi aliquam. Vestibulum vulputate tincidunt tortor nec volutpat. Phasellus ut est risus. Sed convallis quis libero id congue.
Sed tempus, dui a sodales ullamcorper, lorem nunc varius lectus, nec sollicitudin mi leo eu mauris. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Mauris quis porttitor ante. Donec tincidunt molestie nunc posuere maximus. Praesent rhoncus cursus sem. Sed vitae vulputate urna. Morbi nec purus sit amet enim pharetra eleifend at eget nisi. Aliquam feugiat sodales massa, ut aliquet magna. Mauris justo metus, mollis ac porta ut, molestie hendrerit dolor. Mauris sed est interdum, feugiat eros eu, vehicula odio.
Vivamus lorem nibh, accumsan eget nibh efficitur, aliquam volutpat metus. Sed id dolor eget nisi ultricies tempor et blandit lectus. Fusce id ipsum at est congue ultrices. Sed id rutrum mi. Suspendisse semper justo ac metus finibus, vitae accumsan leo sagittis. Aliquam quis elit dolor. Morbi et tellus venenatis, imperdiet elit ac, semper augue. Interdum et malesuada fames ac ante ipsum primis in faucibus. Vestibulum ullamcorper porta lectus, in ullamcorper eros scelerisque ut. Sed id odio sit amet dolor vulputate finibus vel non dolor. Praesent orci lorem, porta sit amet turpis molestie, volutpat vestibulum felis. Phasellus non orci aliquet, vulputate risus in, tempor mi.
</div>
</div>
No need to use any CSS for 50%-50% screen or media query if u use this
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
</head>
<body>
<div class="container">
<div class="row">
<div class="border col-sm-6">
<div>
<img src="sample.jpg">
</div>
<div>
<h2>Contact us</h2>
<form >
First name:
<input type="text" name="firstname">
<br><br>
Last name:
<input type="text" name="lastname" >
<br><br>
Email ID:
<input type="email" name="email" >
<br><br>
<input type="submit" value="Submit">
</form>
</div>
</div>
<div class="border col-sm-6">
<h1>hello</h1>
<h2>hello</h2>
<h3>hello</h3>
<h4>hello</h4>
<h5>hello</h5>
<h6>hello</h6>
</div>
</div>
</div>
</body>
</html>

How to size divs so they don't appear too small on mobile devices?

I am designing a page for a blog. The page has a fixed position sidebar, and a centered div for content. You can see it here. Here's my CSS:
.container {
width: 100%;
height: 100%;
text-align: center;
}
.sidebar {
position: fixed;
left: 0px;
top: 10%;
height: 80vh;
width: 10%;
background-color: red;
}
.content {
width: 40%;
display: inline-block;
text-align: justify;
}
<body>
<div class="container">
<div class="sidebar">
THis is the sidebar.
</div>
<div class="content">
<h1>Fourth</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec in sapien vel augue auctor tempor. Duis orci velit, congue at ornare non, tincidunt quis sapien. Nam at fringilla tortor. Fusce non pharetra quam. Vestibulum fermentum facilisis urna
sed consequat. Nam rutrum sapien at facilisis porttitor. Fusce vehicula dignissim nisl, vel cursus lorem mattis ut. Sed eros libero, euismod et ligula sed, rutrum varius libero. Nulla eget sem sit amet velit pretium porttitor. Morbi tempus ultrices
urna, in egestas erat cursus ut. In hac habitasse platea dictumst.</p>
<p>Donec efficitur gravida pellentesque. Curabitur dignissim odio at tempus fermentum. Aenean pharetra sed sem sed convallis. Praesent pretium urna sit amet leo porttitor, eu auctor purus consequat. Donec id velit eleifend, fringilla enim vitae, blandit
lacus. Nulla tincidunt sed lacus ac euismod. Nam non blandit diam.</p>
<p>Vivamus hendrerit ex a orci dapibus convallis. Vivamus dictum maximus purus, in condimentum massa molestie ut. Donec aliquet, augue ut consequat consectetur, velit turpis finibus elit, sed porta dui felis sed massa. Nulla aliquam interdum est eget
ornare. Suspendisse cursus nec lorem eu rhoncus. Curabitur vehicula pellentesque egestas. Proin et commodo purus. Nulla malesuada consequat tortor, interdum volutpat est congue sed. Curabitur vitae placerat lacus, vestibulum lacinia mi. Duis auctor
malesuada lacus id consectetur. Etiam venenatis nisi eget tellus accumsan, vel ornare mi porttitor. Curabitur dictum non tortor et laoreet.</p>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Praesent egestas quam orci, et eleifend lectus lobortis vel. Nullam pulvinar porttitor egestas. Phasellus consectetur felis eget erat iaculis pulvinar
in sit amet sapien. Nulla sollicitudin maximus nulla, nec ullamcorper arcu tempor at. Aliquam at nisl massa. Sed eleifend urna sit amet erat semper, ac aliquam quam imperdiet. Ut nec cursus nisl. Quisque feugiat imperdiet tellus sed aliquam. Nulla
magna velit, interdum nec auctor vitae, congue at augue. Phasellus placerat risus et vehicula efficitur. Etiam hendrerit egestas interdum. Nulla placerat fringilla mi et rhoncus. Fusce porttitor, arcu consectetur finibus porta, mi ante ultrices
tellus, nec vulputate diam leo quis tellus. Fusce aliquam nulla vel sem tempus, non elementum est condimentum. Nunc accumsan libero diam, ut varius nibh dapibus luctus.</p>
<p>Integer vitae tempor velit. Sed convallis sed dolor id pulvinar. Donec nisi nisl, accumsan quis ante in, tempor dapibus metus. Mauris sed libero consequat, pellentesque sapien ac, tristique felis. Nullam et justo varius, fringilla tellus non, egestas
justo. Morbi sodales libero orci, id viverra nulla lobortis iaculis. In hac habitasse platea dictumst. Pellentesque rutrum sollicitudin augue, nec laoreet dolor mattis non. Mauris non urna ligula. Donec vel velit libero. Sed elit arcu, bibendum
non consectetur eu, varius ut lacus. Fusce commodo nunc ut molestie blandit. In scelerisque suscipit metus, at suscipit felis porta in. Morbi porttitor dapibus malesuada. Fusce vel elit aliquet, convallis nulla eget, ultricies metus.</p>
</div>
</div>
<br/>
<p><em>This is the footer</em>
</p>
</body>
Currently all widths are as percentages. I do not want the content to span the whole width of the page (for easier reading). However on mobile devices (or when the screen width is small enough) I want the content to span the page. However with % widths, the content width constantly changes with the page width. It is ok on a computer screen but for smaller widths the content div becomes too narrow.
An example would be the website medium. You can see (as you resize the window) that for larger widths, the content width remains the same, but for smaller widths the content starts to span the whole page.
Any idea how to achieve that?
you can set a min-width in your .content with any value you may like, just remember you have a fixed sidebar
.container {
width: 100%;
height: 100%;
text-align: center;
}
.sidebar {
position: fixed;
left: 0px;
top: 10%;
height: 80vh;
width: 10%;
background-color: red;
}
.content {
width: 40%;
display: inline-block;
text-align: justify;
min-width: 260px
}
<div class="container">
<div class="sidebar">
THis is the sidebar.
</div>
<div class="content">
<h1>Fourth</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec in sapien vel augue auctor tempor. Duis orci velit, congue at ornare non, tincidunt quis sapien. Nam at fringilla tortor. Fusce non pharetra quam. Vestibulum fermentum facilisis urna sed
consequat. Nam rutrum sapien at facilisis porttitor. Fusce vehicula dignissim nisl, vel cursus lorem mattis ut. Sed eros libero, euismod et ligula sed, rutrum varius libero. Nulla eget sem sit amet velit pretium porttitor. Morbi tempus ultrices
urna, in egestas erat cursus ut. In hac habitasse platea dictumst.</p>
<p>Donec efficitur gravida pellentesque. Curabitur dignissim odio at tempus fermentum. Aenean pharetra sed sem sed convallis. Praesent pretium urna sit amet leo porttitor, eu auctor purus consequat. Donec id velit eleifend, fringilla enim vitae, blandit
lacus. Nulla tincidunt sed lacus ac euismod. Nam non blandit diam.</p>
<p>Vivamus hendrerit ex a orci dapibus convallis. Vivamus dictum maximus purus, in condimentum massa molestie ut. Donec aliquet, augue ut consequat consectetur, velit turpis finibus elit, sed porta dui felis sed massa. Nulla aliquam interdum est eget
ornare. Suspendisse cursus nec lorem eu rhoncus. Curabitur vehicula pellentesque egestas. Proin et commodo purus. Nulla malesuada consequat tortor, interdum volutpat est congue sed. Curabitur vitae placerat lacus, vestibulum lacinia mi. Duis auctor
malesuada lacus id consectetur. Etiam venenatis nisi eget tellus accumsan, vel ornare mi porttitor. Curabitur dictum non tortor et laoreet.</p>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Praesent egestas quam orci, et eleifend lectus lobortis vel. Nullam pulvinar porttitor egestas. Phasellus consectetur felis eget erat iaculis pulvinar in
sit amet sapien. Nulla sollicitudin maximus nulla, nec ullamcorper arcu tempor at. Aliquam at nisl massa. Sed eleifend urna sit amet erat semper, ac aliquam quam imperdiet. Ut nec cursus nisl. Quisque feugiat imperdiet tellus sed aliquam. Nulla
magna velit, interdum nec auctor vitae, congue at augue. Phasellus placerat risus et vehicula efficitur. Etiam hendrerit egestas interdum. Nulla placerat fringilla mi et rhoncus. Fusce porttitor, arcu consectetur finibus porta, mi ante ultrices
tellus, nec vulputate diam leo quis tellus. Fusce aliquam nulla vel sem tempus, non elementum est condimentum. Nunc accumsan libero diam, ut varius nibh dapibus luctus.</p>
<p>Integer vitae tempor velit. Sed convallis sed dolor id pulvinar. Donec nisi nisl, accumsan quis ante in, tempor dapibus metus. Mauris sed libero consequat, pellentesque sapien ac, tristique felis. Nullam et justo varius, fringilla tellus non, egestas
justo. Morbi sodales libero orci, id viverra nulla lobortis iaculis. In hac habitasse platea dictumst. Pellentesque rutrum sollicitudin augue, nec laoreet dolor mattis non. Mauris non urna ligula. Donec vel velit libero. Sed elit arcu, bibendum
non consectetur eu, varius ut lacus. Fusce commodo nunc ut molestie blandit. In scelerisque suscipit metus, at suscipit felis porta in. Morbi porttitor dapibus malesuada. Fusce vel elit aliquet, convallis nulla eget, ultricies metus.</p>
</div>
</div>
<br/>
<p><em>This is the footer</em>
</p>
You can use CSS special selectors: example:
#media screen and (max-width: 480px) {
.content {
width: 80%;
}
}
So that the .content will be set to 80% width on small screens.
You may also want to change the sidebar behavior for small resolutions, like setting up his position to initial and expanding his width to the same width as your content, so the design stay coherent.
Here's a fiddle (You need to resize the render frame by click and drag to see it in action )
https://jsfiddle.net/9c3ztska/1/
Now i will introduce to you something very usefull when designing responsive website:
It's a framework called Skel.
Long story short, it uses a grid system, wich let you specify specific size for a div for specific resolutions.
The grid system works with 12 units in width, so 12u represent 100% of the container width.
Here's a code example:
<div class="row">
<div class="6u 12u(small)"> YOUR CONTENT </div>
</div>
What it means:
Your content will be 50% of the container width on large screen, but will expand to 100% on small screens.
If you want to try it out and get fast in it, i recommend you to try baseline wich is a boilerplate using Skel framework.
You can download it and put it on your server (no db needed) and start coding.
baseline comes with pre-configured Skel and "breakpoints" (breakpoints are screen resolutions for wich Skel will swicth between CSS rules)

Forcing one column in layout to take precedence

I have a section of a page layout which has the option of anywhere from 1 to 3 buttons in the right column, and the left column will have a title which may be a few words or even a paragraph.
The right column has the buttons and must take precedence and stay aligned to the right of the page width. The buttons must stay inline without wrapping. You can remove one or two buttons and it forces the text to the left, which is correct.
The left column needs to flow as close to the right column as it needs to in the case of wrapping text.
I've hit upon the idea of using CSS table display which works great in the case of long text, but for short text, the button column comes away from the right side.
Try removing all but 3 or 4 words of text and the buttons snap to the left. Am I taking the wrong approach here?
Here is the HTML, and here's a fiddle http://jsfiddle.net/MaureenDunlap/tvFbN/16/
<div id="wrapper">
<div id="container">
<div id="header_wrapper">
<div class="player_header_info">In vel purus ipsum. quam tempor auctor. Praesent ac leo magna, at condimentum felis. Nullam vel tortor semper metus bibendum iaculis. In consequat arcu aliquam nibh posuere non cursus eros dictum. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nulla venenatis gravida mi eget vestibulum.
<div class="player_header_secondary">February 28, 2013</div>
</div>
<div id="buttons">
<div class="button_container">
<img src="http://www.likno.com/Images/lwbm/Single_Mesh_11.jpg" />
<img src="http://www.likno.com/Images/lwbm/Single_Mesh_11.jpg" />
<img src="http://www.likno.com/Images/lwbm/Single_Mesh_11.jpg" />
</div>
</div>
</div>
</div>
<div id="normal">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sit amet tortor at diam aliquet ornare eu nec leo. Phasellus ut blandit leo. Vivamus viverra velit eget quam tempor auctor. Praesent ac leo magna, at condimentum felis. Nullam vel tortor semper metus bibendum iaculis. In consequat arcu aliquam nibh posuere non cursus eros dictum. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nulla venenatis gravida mi eget vestibulum. Phasellus elit ipsum, convallis a porttitor eu, blandit non justo. Pellentesque gravida, dui vel vulputate cursus, diam nisl eleifend massa, ullamcorper cursus nisl diam at erat. Nulla urna odio, vehicula et commodo sit amet, commodo at diam. Phasellus molestie tincidunt lacus, varius semper ligula tincidunt non. Nullam fermentum, enim ut dictum gravida, libero mauris pretium lacus, ac vehicula neque massa at mi.</p>
<p>Nam dignissim vehicula eros non viverra. Vestibulum non tellus sed ante placerat pharetra in vitae velit. Vestibulum eu lacinia urna. Nullam libero mauris, venenatis in condimentum auctor, porta tempor massa. In faucibus sapien sit amet tellus faucibus quis dictum eros pellentesque. Fusce id odio nec orci pellentesque bibendum. Curabitur viverra, nisl nec sodales elementum, lectus nisi vulputate leo, non cursus est libero eget odio. Curabitur a libero arcu. Etiam pellentesque mauris ut mi pellentesque euismod. Aenean sit amet consectetur diam. Curabitur nec velit leo. Sed feugiat lacinia sagittis.</p>
<p>Nam quis nulla quis lorem ornare semper nec eget orci. Proin justo lectus, suscipit rhoncus sollicitudin nec, dignissim eu mauris. Curabitur sit amet tortor in nisl vulputate placerat in nec lectus. Praesent euismod pellentesque augue, eu condimentum quam pellentesque et. Aliquam erat volutpat. Nam vitae leo et augue placerat lobortis et id magna. Curabitur sit amet ante id felis luctus iaculis. Quisque ac orci eu purus tempor consectetur vitae et dui. Mauris vehicula tincidunt ligula a cursus. Nunc imperdiet semper pulvinar. Phasellus iaculis laoreet quam, ac adipiscing mi pellentesque eu.</p>
<p>Nulla adipiscing fermentum leo, eget convallis nulla facilisis vel. Phasellus mollis ultrices risus vel volutpat. Nullam in enim mi. Duis eget ligula lectus, eget feugiat mauris. Duis at tortor enim, sit amet euismod turpis. Cras mattis tincidunt dolor nec feugiat. Mauris hendrerit lacus eu augue ultrices eu porttitor tellus semper. Ut mattis augue vitae velit tincidunt tristique.</p>
</div>
Here's my CSS:
#header_wrapper {
display: table;
border-collapse: collapse;
width:100%;
border:1px dotted #ccc;
}
.player_header_info {
display: table-cell;
vertical-align:top;
background-color: #e7dbcd;
padding-left:5px;
}
#buttons {
display: table-cell;
padding-left: 10px;
vertical-align:top;
}
.button_container {
position:relative;
display:inline;
white-space:nowrap;
}
if you are just wanting your buttons to stay on the right you can add text-align:right to #buttons
http://jsfiddle.net/tvFbN/20/
Otherwise you will need to add a min-width to .player_header_info
as you are using table-cells without giving them a width, they will always re-size to the content inside them without breaking the width of the top level table element

Div inside div not auto expanding (screenshot)

I need the red box to expand with the blue box content, so they are always both the same size.
The red box is defined as:
.leftMenu{
float:left;
width:20%;
background-image:url(../images/leftMenuBG.jpg);
background-position:bottom;
background-color:#BFDAE3;
background-repeat:repeat-x;
}
Can't seem to get it to work, whatever I try! Any ideas? Thanks!
Simple solution: Use tables.
Semantic solution: Use faux columns.
You will need to wrap the red div around the blue div, so have the blue divs inside, floated right, and then have a clearing div after the blue divs.
<div style="border:solid red 2px;">
<div style="border:solid blue 2px;float:right;width:200px;">
<p>Content here</p>
</div>
<div style="clear:both;"></div>
</div>
Excuse the use of inline styles, these should be in a style sheet.
If you need each div to sit independently of each other and don't mind using JavaScript (as this is only a presentational layer) try this method.
You can use a jQuery plugin for that too. (for example, http://www.cssnewbie.com/equal-height-columns-with-jquery/)
But the Semantic solution: Use faux columns. from Magnar is nice too and doesn't require Javascript.
An additional 'faux column'-method is to (ab)use positioning.
Place both boxes inside a container that's floated (which makes it expand to accomodate floated children) and positioned relatively (which allows us to position child elements inside it).
Then, position the shortest column absolutely, and float the longest column. The container will take on the height of the floated child, and the div with position:absolute will take that height again.
A short example:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head><title>Columns</title>
<style type="text/css">
html, body {
width: 100%;
}
#container {
width: 100%;
float: left;
position: relative;
border: 2px solid black;
}
#left-box {
position: absolute;
width: 40%;
border: 2px solid red;
background-color: #5555ee;
height: 100%;
}
#right-box {
float: right;
margin-right: 15%;
width: 40%;
border: 2px solid blue;
background-color: #3e3e3e;
}
</style>
</head>
<body>
<div id="container">
<div id="left-box">
- E - x - P - a - N - d - I - n - G -
</div>
<div id="right-box">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed mattis eros ut sem sollicitudin ultricies. Vivamus pharetra, urna sit amet auctor mollis, risus sem ultrices quam, non condimentum enim leo sit amet tellus. Pellentesque id vehicula nisl. Nulla ut commodo ligula. Sed sit amet ligula purus, at suscipit leo. Nulla quis nulla id est aliquet vehicula. Suspendisse consectetur, nunc in hendrerit dignissim, nisl massa viverra quam, et faucibus augue lorem eu mi. Vestibulum commodo luctus ante, vel placerat metus ullamcorper vel. Sed id imperdiet orci. In hac habitasse platea dictumst. Praesent ac dui orci, vitae pharetra dolor.
</p>
<p>
Aenean enim metus, placerat at hendrerit in, hendrerit in velit. Cras tincidunt blandit sapien, a aliquet elit sollicitudin vitae. Quisque at ligula sem. In hac habitasse platea dictumst. Ut eu magna ipsum, id fringilla massa. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Vivamus consequat metus sed lectus dignissim posuere quis a felis. Mauris in consectetur arcu. Nullam fermentum adipiscing dignissim. Sed quis orci in magna viverra sollicitudin. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Maecenas condimentum lectus pretium tortor porta a hendrerit dui pharetra. Etiam est justo, bibendum vehicula vestibulum ac, mattis ut risus. Praesent dapibus nibh id enim vestibulum porta. Donec aliquam urna a diam varius blandit. Nulla interdum ante at arcu vehicula sagittis. Curabitur quam sapien, luctus ac sagittis vitae, tristique a odio. Nulla consequat gravida urna, at bibendum nisl ultricies ac.
</p>
<p>
Vivamus quis metus porta purus aliquet aliquet. Morbi sollicitudin orci ut ligula vehicula sollicitudin. Etiam sed lacus eget leo molestie ullamcorper sit amet ac urna. Cras vitae turpis in sapien dignissim molestie. Curabitur tellus purus, dignissim at adipiscing in, faucibus ac tortor. Duis vitae metus ac urna cursus consequat eget vel quam. Integer bibendum mauris enim, sit amet blandit sapien. Nam in lectus ante. Curabitur lacinia erat sit amet lectus malesuada facilisis. Phasellus et pellentesque enim. Fusce eget tristique est. Suspendisse id dui eu lorem congue tincidunt. Cras libero lectus, placerat eget tristique a, gravida vitae lorem. Sed nec venenatis sapien. Suspendisse tempus orci ut odio venenatis et cursus sem faucibus. Mauris commodo ultricies dictum. Curabitur iaculis, ligula sit amet lobortis hendrerit, eros orci elementum nisi, cursus lacinia nunc felis vitae erat. Donec id elementum ipsum.
</p>
<p>
Mauris id mi sed augue egestas vestibulum non a ipsum. Ut arcu purus, consequat in tincidunt in, pretium a dui. Cras in quam tellus, non ultricies nisi. Sed leo orci, gravida et luctus sed, eleifend quis odio. Praesent cursus feugiat neque, tincidunt malesuada libero egestas sit amet. Etiam nisi nisi, faucibus vitae accumsan sed, gravida ut lacus. Suspendisse hendrerit fringilla interdum. Cras fermentum nibh non eros gravida pretium et a sem. Sed non nisl dui, non commodo arcu. Donec nec massa mi, vel auctor odio. Curabitur sagittis velit id felis egestas iaculis. Nunc pharetra magna eu metus malesuada ut porta mi suscipit. Aenean vitae elit sit amet neque pellentesque malesuada. Aliquam eu nulla consectetur est adipiscing vulputate non a odio. Sed consectetur neque eros. Nulla fermentum vehicula vestibulum. Aenean eleifend, nisi eget porta accumsan, tellus orci tincidunt metus, volutpat lobortis quam augue commodo tellus. Aenean consectetur pretium vestibulum. Pellentesque a scelerisque sem. Cras pellentesque tortor euismod magna viverra mollis.
</p>
<p>
Mauris dignissim sodales placerat. Sed id interdum erat. Nunc sagittis, nunc in auctor ullamcorper, nisi dolor commodo sem, sit amet aliquam diam dolor posuere est. Ut vestibulum elit ut urna imperdiet non tincidunt sapien euismod. Fusce ut sem erat, aliquam accumsan metus. Proin sed velit nec velit laoreet dignissim at sit amet ante. Pellentesque ac dolor non nulla dapibus lacinia. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Suspendisse non nisl diam. Sed et ligula sed libero porttitor semper eget eu elit. Phasellus quis massa dolor. Phasellus ac justo ac diam ultrices iaculis quis at odio. Fusce eget nisi nunc. Cras cursus, dui eget mattis rutrum, arcu dolor sollicitudin nibh, eu congue augue quam ut leo. Praesent in est nulla, eu ullamcorper enim. Nullam in adipiscing ligula.
</p>
</div>
</div>
</body>