Is it possible to have a two column layout whereby one of the columns has a min-width value? Please see the code below:
#container {
width: 100%;
max-width: 1200px;
min-width: 960px;
height: 600px;
margin: 0 auto;
}
#sidebar {
float: left;
width: 20%;
min-width: 300px;
height: 100%;
}
#content {
float: left;
width: 80%;
height: 100%;
}
The problem is that when the window is resized and #sidebar gets the min-width value applied, #content will drop off the page.
Ideally I would like to do this without having to use display: table and ideally a CSS only solution would be preferred.
EDIT: Here is a jsfiddle to demonstrate the issue: http://jsfiddle.net/2DwB3/
You can do this: http://codepen.io/anon/pen/GmwIo
#container {
width: 960px;
height: 600px;
margin: 0 auto;
overflow: hidden;
}
#sidebar {
float: left;
min-width: 300px;
height: 100%;
}
#content {
}
The #content column is collapsing (even in full screen size) because min-width value of the left column (#sidebar) exceeds its width value, Hence the remaining space for the right column (#content) is less than 80% of the width of the #container.
In this case the width of the #content should be changed base on the width of the #sidebar. But as you have used min-width property for the sidebar, if you set a lower value than the width value (something like 150px), It'll be impossible to calculate the width of the #content even by using CSS3 calc() function.
Alternatively, you can stop floating the right column and hide the extra horizontal overflow by overflow-x: hidden; to achieve the desired goal:
#sidebar {
float: left;
width: 20%;
min-width: 300px;
height: 80%; /* Changed for the demo */
}
#content {
height: 100%;
overflow-x: hidden;
}
WORKING DEMO.
Related
So, I am working on something and I am trying to create an image tag that is inside another div. The problem is, I write
.container {
padding: 0;
margin: 0;
}
.container img {
padding: 0px;
margin: 0px;
width: 100%;
height: 100%;
}
<div class='container'>
<img src='https://www.clarkson.edu/_site_support/background_image_banks/images/tor_images/studcnt_4128800003.jpg' alt='A problem occured'>
</div>
But there is still some room before the edge. I also tried to put padding to 0 and margins to 0 but still, nothing.
Give body margin as 0px;
body {
margin: 0px;
}
Use a reset file or structure in css to set the values to a defined default and not let browsers get that. One of the reset files I've used is from here http://meyerweb.com/eric/tools/css/reset/ . The body in this case has a margin of 8px and since there is not box-sizing defined it affects the widths. Try that.
Try this code
body,html{
margin:0px;
padding:0px;
}
Set the float attribute to get rid of the extra room:
div img { float: left }
But about the size of the image you need to have in mind that if the div's width/height is set as percentage, the inner element's width/height can not be set in percentage.
If you'd like to set the image width/height in percentage, you need to specify the dimensions of the div in pixels.
E.g.
This works:
div {
width: 600px;
height: 400px;
}
div img {
width: 100%;
height: 100%;
}
But this does not work:
div {
width: 100%;
height: 100%;
}
div img {
width: 100%;
height: 100%;
}
Totally, what you need to handle both parts of your question is something like this:
div {
width: 100%;
height: 100%;
}
img {
float: left; /* or right, whatever you'd rather */
display: block;
}
Though, for a better suggestion, information about the container of the div's needed.
I'm creating a menu bar on my website. My issue is that there is a small margin at the side of one of my menu items. (I have highlighted this by adding background-color: black; to the container.) I am using safari.
The CSS:
.testMenuOption{
width: calc(100% /3);
height: 100%;
float: left;
margin:auto;
background-color: white;
display: table;
}
Can somebody tell me what my issue is? I have tried removing the text and it is not the issue.
Since you calculate the width by using 100/3, there will be rounding errors, where as a result the widths wont add up 100% again. What you can do to fix it is to set the width of two of the .menuOptionsWraps to 33% and one to 34%.
For example by doing so:
.menuOptionSelectedWrap {
float: left;
width: 33%;
height: 100%;
margin: auto;
margin-right: -4px;
background-color: #d6eef2;
display: table;
}
.menuOptionSelectedWrap:last-of-type {
width: 34%;
}
I'm not sure what you say,that black line change when window resize.check your css, width: calc(100% /3);
change the value 3,you will get idea.
I have the typical 3 column layout and I need it to be fluid (ish). The specs of the projects are: we need the container to go from 1024px to 1440px max (that's easy). And the center column needs to go from 514 (at 1024) to 626 (at 1440), the sidebars on both sides containing the rest of the space.
I don't see an easy way around this, I've played with max-width and min-width but since the proportions are not the same at the 2 breakpoints, I can't use percentage width to make the columns fill the space on higher resolutions.
Here is my code:
<div id="container">
<nav id="sidebar-left">Left</nav>
<section id="page">Center</section>
<div id="sidebar-right">Right</div>
</div>
#container{
min-width:1024px;
max-width: 1440px;
width: 100%;
margin: 0 auto;
overflow: hidden;
position: relative;
min-height: 100%;
}
#sidebar-left{
min-width: 230px;
max-width: 387px;
float: left;
background: red;
height: 300px;
}
#sidebar-right{
min-width: 230px;
max-width: 387px;
float: right;
background: blue;
height: 300px;
}
#page{
min-width: 514px;
margin: 0 20px;
max-width: 626px;
float: left;
background: purple;
height: 300px;
}
And I also made a fiddle:
https://jsfiddle.net/1y59nuxz/
I'd rather have a css only solution, I'm pretty sure is more or less easy to solve using jquery but I'd want to know if this is approachable with using it.
EDIT: I need this to be compatible with IE9+
Ok. You have several solutions to accomplish this task.
One solution is to change order of elements in your html (if possible):
<div id="container">
<nav id="sidebar-left">Left</nav>
<div id="sidebar-right">Right</div>
<section id="page">
<div class="page-inner">Center</div>
</section>
</div>
For "#page" use next css code:
#page {
overflow: hidden;
height: 300px;
}
.page-inner {
height: 100%;
margin: 0 20px;
background: purple;
}
Example code:
#page {
overflow: hidden;
height: 300px;
}
.page-inner {
height: 100%;
margin: 0 20px;
background: purple;
}
#container{
min-width:1024px;
max-width: 1440px;
width: 100%;
margin: 0 auto;
overflow: hidden;
position: relative;
min-height: 100%;
}
#sidebar-left{
min-width: 230px;
max-width: 387px;
float: left;
background: red;
height: 300px;
}
#sidebar-right{
min-width: 230px;
max-width: 387px;
float: right;
background: blue;
height: 300px;
}
<div id="container">
<nav id="sidebar-left">Left</nav>
<div id="sidebar-right">Right</div>
<section id="page">
<div class="page-inner">Center</div>
</section>
</div>
You can also check the fiddle.
Another solution is to apply flexbox. It's an elegant and easy way.
I think this layout can be achieved using some table & table-cell css like so:
basically set the .container to display: table
then set all direct children of the .container to display: table-cell
now these children will shrink/grow accordingly to their parent, however some tweaks have to be made for the #page to stay put at 626px widh and shrink down accordingly
max-width/min-width combo won't work on the #page div, however we can specify a fixed width, according to the max-width desired, in this case 626px, so that this div won't go past 626px width, but will shrink down if the window is resized
finally since we're using display: table-cell on these children divs, any margin prop. will be ignored, however we can mimic a margin using some border-left & right props. OR add another div inside the #page div that will hold the content and have some margin applied to it and the background accordingly.
Check out the demos bellow:
fake margins to the #page here
OR another div that holds the content for #page here
I have modified your code on fiddle
or else check the code below.
Html
<div class="content">
<div class="content__left">left</div>
<div class="content__right">Right</div>
<div class="content__middle">Center</div>
</div>
CSS
html, body, .container {
width: 100%;
height:100%;
min-width:1024px;
max-width: 1440px;
}
.content__left {
width: 20%;
max-width:200px;
float: left;
background: red;
margin-right:20px;
height:300px;
}
.content__middle {
min-width: 514px;
background: purple;
overflow: auto;
height:300px;
}
.content__right {
width: 20%;
max-width:200px;
float: right;
background: blue;
margin-left:20px;
height:300px;
}
This question already has answers here:
CSS - Equal Height Columns?
(11 answers)
Closed 8 years ago.
I have a wrapper, main and aside elements inside.
I want to have:
wrapper - no fixed height, stretching to the content's height - the longer column of the 2.
aside - left column, width 30%, min-width:340px(with padding), height 100% of wrapper.
main - right column, width auto.
When I set the wrapper to position:relative and aside to position:absolute the 100% height is working, however that breaks the main element's width. Is there any other way to achieve what I need with CSS/SASS only and without being "hackish" with hidden divs and such?
.wrapper{
border:$contentborder;
background: $contentgradient;
border-radius:3px;
text-align: center;
margin: auto;
}
main{
text-align: left;
overflow-x: hidden;
}
aside{
float: left;
-moz-box-sizing: border-box;
box-sizing: border-box;
width: 30%;
min-width: 340px;
padding: 20px;
padding-left: 0;
height: 100%;
text-align: left;
}
http://jsfiddle.net/2m503b8e/
Assign some height for your parent div for instance height:209px; to your .wrapper
DEMO
You can also use min-height: value to your main and aside
You need to add a margin-left to main, that equals the width of aside:
main {
margin-left: 340px;
}
You might be interested in creating breakpoints for the min-width/width values though. For screens with viewport size of greater than 1033px, the width of aside will become 30%, so your margin-left needs to be 30%.
#media screen and (min-width: 1033px) {
main {
margin-left:30%;
}
}
Fiddle:
http://jsfiddle.net/2m503b8e/5/
There are several ways of achieving this. Probably the easiest is to make the elements display like a table:
.wrapper{
border:$contentborder;
background: $contentgradient;
border-radius:3px;
text-align: center;
margin: auto;
background:gray;
display:table; /* make this act as a table */
}
main{
text-align: left;
overflow-x: hidden;
background: red;
padding:2em;
display:table-cell; /* make this act as a table cell */
}
aside{
/*float: left; */
-moz-box-sizing: border-box;
box-sizing: border-box;
width: 30%;
min-width: 340px;
padding: 20px;
padding-left: 0;
/* height: 100%; */
text-align: left;
background:orange;
display:table-cell; /* make this act as a table cell */
}
http://jsfiddle.net/2m503b8e/3/
i am kind of new to designing stuff which is why i want to learn a bit about it..
I am having an issue with my website, what css can I use to make a Div acting as a wraper grow in terms of height as the content grows? My content is being hidden underneath the footer... as it grows
Thank you
css
.wrapper
{
width :1200px;
height: 1000px;
margin-left: auto;
margin-right: auto;
overflow :hidden;
background-color: white;
}
Change this:
.wrapper
{
width :1200px;
height: 1000px;
margin-left: auto;
margin-right: auto;
overflow :hidden;
background-color: white;
}
to this:
Change this:
.wrapper
{
width :1200px;
margin-left: auto;
margin-right: auto;
background-color: white;
}
Your request is not entirely clear, but you could use min-height to make an element have a minimum height:
.wrapper {
width: 1200px;
min-height: 100px;
margin-left: auto;
margin-right: auto;
background-color: blue;
}
http://jsfiddle.net/uQjEn/3/
And:
http://jsfiddle.net/uQjEn/2/
Never, ever use overflow: hidden with an explicit height. I know all the cool kids are using that to contain floats but you can't combine that with a height set.
Remove the overflow property or the height property.