Started a project involving a 3-column div at the top - 300px/dynamic/350px. The right div falls below the others: http://jsfiddle.net/tspencer103/b49mfno4/1/.
I have tries several suggestions here like http://jsfiddle.net/22YBU/. No luck. Any suggestions? Thanks.
div #div_1 {
float: left;
height: 50px;
background-color: red;
width: 300px;
}
div #div_2 {
height: 50px;
margin: 0px 350px 0px 300px;
background-color: green;
text-align: center;
}
div #div_3 {
float: right;
height: 50px;
background-color: blue;
width: 350px;
}
<div id="container">
<div id="div_1">LEFT STATIC 300px</div>
<div id="div_2">CENTER DYNAMIC</div>
<div id="div_3">RIGHT STATIC 350px</div>
</div>
If you're interested in a simple, more modern approach, drop the floats and use flexbox:
HTML (no changes)
<div id="container">
<div id="div_1">LEFT STATIC 300px</div>
<div id="div_2">CENTER DYNAMIC</div>
<div id="div_3">RIGHT STATIC 350px</div>
</div>
CSS
#container {
display: flex;
}
#div_1 {
background-color: red;
width: 300px;
height: 50px;
}
#div_2 {
background-color: green;
text-align: center;
height: 50px;
flex: 1; /* flexible width */
}
#div_3 {
background-color: blue;
width: 350px;
height: 50px;
}
DEMO
Flexbox benefits:
minimal code; very efficient
centering, both vertically and horizontally, is simple and easy
equal height columns are simple and easy
multiple options for aligning elements
it's responsive
unlike floats, which offer limited layout capacity because they were never intended for building layouts, flexbox is a modern (CSS3) technique with a broad range of options.
Note that flexbox is supported by all major browsers, except IE 8 & 9. Some recent browser versions, such as Safari 8 and IE10, require vendor prefixes. For a quick way to add all the prefixes you need, post your CSS in the left panel here: Autoprefixer.
Related
I'm trying to make this layout format as part of my intro level class to HTML/CSS. Can anyone help? Much appreciated.
See the attached link.[Probably can be created with mostly Divs. I tried to do divs with widths of 100% for the top and bottom sections. I'll probably do divs for the sidebar. How would I make the circles?
Answering the only question I see above…
You can make the “circles” by rounding elements (for example <div>s) with a CSS rule that applies border-radius on that element.
More info here: https://developer.mozilla.org/en-US/docs/Web/CSS/border-radius
#wazzzzzzup {
display: inline-block;
width: 100px;
height: 100px;
background: dodgerblue;
border-radius: 50%;
}
#wazzzzzzzzzzup {
display: inline-block;
width: 100px;
height: 100px;
background: gold;
border-radius: 10px;
}
#wazzup {
display: inline-block;
width: 100px;
height: 50px;
background: orangered;
border-radius: 100px / 50px;
}
<div id="wazzzzzzup"></div>
<div id="wazzzzzzzzzzup"></div>
<div id="wazzup"></div>
I'm a newbie in HTML and CSS. Today I want to make a checkout form like that:
I want height of checkout-option-header equal 50% checkout-option's, but It always bigger than I want. Like that:
As I understand the percentage will determine size of children by size of parents.
But why I can't use it right?
CSS file:
.checkout-container {
margin-left: 10%;
margin-right: 10%;
background: black;
overflow: hidden;
}
.checkout-container .checkout-option {
margin: 5%;
background: red;
min-height: 100px;
}
.review-container {
margin: 5%;
background: yellow;
min-height: 100px;
}
.information-container {
margin: 5%;
background: blue;
min-height: 100px;
}
.checkout-container .checkout-option .checkout-option-header {
background: yellow;
min-height: 50%;
}
.checkout-option-container {
background: green;
min-height: 50px;
}
HTML file:
<div class="checkout-container">
<div class="checkout-option">
<div class="checkout-option-header"></div>
<div class="checkout-option-container"></div>
</div>
<div class="review-container"></div>
<div class="information-container"></div>
</div>
I'm not sure if I actually understand what you are asking but your code seems to be working.
http://codepen.io/TheStonedTurtle/pen/NbNNxw
I copied your code added the below CSS.
.checkout-option {
border: 5px solid white;
}
If you're whole question is trying to understand how percentages work they are dependent on the parent element. I.E. if you have an element with 500px height and you give a child 50% height it will have 250px as that is 50% of 500. See these for more info:
https://developer.mozilla.org/en-US/docs/Web/CSS/percentage
You could also use flexbox to accomplish this with less CSS but it is a relatively new feature so it is not fully supported in I.E. yet.
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
Flexbox browser support: http://caniuse.com/#feat=flexbox
I copied and pasted your code but I didn't see such problem. The two boxes inside the .checkout-option are exactly 50% in height. Instead of min-height, use height because your .checkout-option is blocking the checkout-option-header.
I've been working independently on designing a website for a local company and I've been stuck on how to make my layout/design to work responsively. As of right now, my content looks similar to this:
However, as the browser screen decreases, or if the browser is already on a smaller resolution, Item 3 would shift below both Item 1 and Item 2 with a width of 100%. While both Item 1 and Item 2 would be inline with each other. Much like this:
Initially, I had both wrapping divs (1 and 2) set to display: inline-block. But I couldn't find any sort of research that said that (after changing inline-block div container 2 in a respective media query) a child element could be inline with a separate element while another child element in the same container would not. Recently, I've started debating the use of display: table , display: table-row , and display: table-cell to try and organize content in a table-like layout, but I couldn't find a way to assign Item 1 and Item 2 into their own row while excluding Item 3.
Honestly it's been a while since I've had to mess with anything HTML/CSS/JavaScript/etc., so I'm a little rusty. I'm hoping to see if anyone can point me in the right direction or give me some insight. Thanks.
I used fluid design with basic div's you can see here https://jsfiddle.net/74x5975j/6/
<div class="group">
<div class="box-1">BOX 1</div>
<div class="box-2">BOX 2</div>
<div class="box-3">BOX 3</div>
</div>
here is the CSS with media query:
.group {
width: 600px;
height: 300px;
}
.box-1 {
width: 50%;
height: 100%;
float: left;
background-color: gray;
text-align: center;
float: left;
}
.box-2 {
width: 50%;
height: 50%;
float: left;
background-color: blue;
text-align: center;
float: left;
}
.box-3 {
width: 50%;
height: 50%;
float: left;
background-color: red;
text-align: center;
float: left;
}
#media only screen and (max-width: 599px){
.group {
width: 100%;
height: 450px;
}
.box-1 {
height: 66.666%;
}
.box-2 {
height: 66.666%;
}
.box-3 {
width: 100%;
height: 33.333%;
}
}
https://jsfiddle.net/93hjyhs8/
I'm trying to vertically center the text on the right, but having great difficulty finding a pure CSS solution that works in all browsers.
The height of the .block element should be dynamic and expand to the size of the tallest child element (currently .thing1).
Note, that if possible I would prefer to avoid hacks such as using tables, but feel free to post those kind of solutions regardless.
Also, why is the element not only at the bottom but also slightly nudged down?
.block {
width: 500px;
background: yellow;
}
.thing1 {
height: 100px;
width: 40%;
background: blue;
display: inline-block;
}
.thing2 {
background: red;
width: 60%;
vertical-align: top;
display: inline-block;
}
<div class='block'>
<span class='thing1'></span><span class='thing2'>Hello world how are you today r u alrite m8 i think u r weak m8</span>
</div>
demo - https://jsfiddle.net/victor_007/93hjyhs8/1/
add vertical-align:middle for both the inline-block elements
You could use the new awesome css flexbox,
.block {
width: 500px;
background: yellow;
display: flex;
align-items: center;
justify-content: center;
}
Demo: https://jsfiddle.net/3y41ot0b/
I want to achieve the following effect: http://jsfiddle.net/3KJta/1/
However the solution I have uses a known width for the small div and the larger div. I need this to work with variable sized divs. The use case for this is a tooltip that appears above a smaller flexible sized element. The tooltip content isn't known and so the width could be anything.
So far I have:
<div class="small">
<div class="smaller"></div>
<div class="larger"></div>
</div>
and
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
div {
border: 2px solid black;
}
.small {
width: 50px;
height: 50px;
position: absolute;
left: 200px;
top: 50px;
text-align: center;
}
.smaller {
width: 20px;
height: 20px;
border-color: red;
display: inline-block;
}
.larger {
width: 200px;
height: 200px;
border-color: blue;
display: inline-block;
margin-left: -75px /* NOTE: in reality, .small has a variable width, and so does .larger, so i can't just take off this fixed margin */
}
If you are ok with using css3 and only support modern browsers you can use transform: translateX(-50%); to center the bigger box (currently supported browsers).
See this example: http://jsfiddle.net/2SQ4S/1/
If you use and extra element you can do it:
<div class="small">
<div class="smaller"></div>
<div class="larger">
<div>I'm extra</div>
</div>
</div>
CSS
.larger {
position:relative;
left:50%;
width:8000%;
margin-left:-4000%;
text-align:center;
border:none;
}
.larger div {
width: 200px;
height: 200px;
border-color: blue;
margin:auto;
}
http://jsfiddle.net/3KJta/4/
although that does cause some issues with content being wider than the page so you would need it all in a container with overflow:hidden:
http://jsfiddle.net/3KJta/7/
All a bit ugly though. Perhaps there's a solution where you can avoid doing this. Maybe a JS solution that measures the size of the content you're trying to show and offsets it.