screenshot
Image size is 100% width.
Trying to make two columns and three columns below.
Fourth and fifth column height does not match the column height.
padding-right 5px must also apply.
a,b,c = image size (224x224)
d = image size (448x224)
e = image size (224x224)
How can I do this?
<div id="box-wrapper">
<div class="box-banner">
<div class="box-button"><img src="/224/random/ffffff"></div>
<div class="box-button"><img src="/224/random/ffffff"></div>
<div class="box-button"><img src="/224/random/ffffff"></div>
</div>
<div class="box-banner-two">
<div class="box-button-two"><img src="/448x224/random/ffffff"></div>
<div class="box-button-two"><img src="/224/random/ffffff"></div>
</div>
</div>
#box-wrapper {
padding-top: 10px !important;
padding-left: 5px !important;
padding-right: 5px !important;
height: 100%;
position: relative;
float: left;
}
.box-banner,
.box-banner-two {
width: 100%;
height: 100%;
position: relative;
float: left;
}
.box-button {
float: left;
width: 32.444%;
margin: 0 5px 5px 0;
}
.box-button img,
.box-button-two img {
width: 100%;
}
.box-banner .box-button:nth-child(3) {
margin-right: 0px;
float: right !important;
}
.box-banner-two .box-button-two:nth-child(1) {
float: left;
width: 64.888%;
margin: 0 5px 5px 0;
}
.box-banner-two .box-button-two:nth-child(2) {
float: right;
width:32.444%;
margin: 0 5px 5px 0;
margin: 0;
}
I modified the html and css posted by you to achieve the same effect. I hope this helps.
Try to avoid important as much as possible.
*, *:after {
box-sizing: border-box;
}
a {
display: block;
text-decoration: none;
background-color: burlywood;
height: 224px;
text-align: center;
line-height: 224px;
}
#box-wrapper {
padding: 10px 5px 0 5px;
height: 100%;
position: relative;
}
.clearfix:after {
display: table;
clear: both;
content: '';
}
.box-button {
float: left;
width: 33.333%;
padding: 0 5px 5px 0;
}
.col-2 {
width: 66.666%;
}
<div id="box-wrapper">
<div class="box-banner clearfix">
<div class="box-button">
A Link
</div>
<div class="box-button">
A Link
</div>
<div class="box-button">
A Link
</div>
</div>
<div class="box-banner clearfix">
<div class="box-button col-2">
A Link
</div>
<div class="box-button">
A Link
</div>
</div>
</div>
Your are over complicating stuff with margin and paddings. The secret here is using box-sizing: border-box. Understand it better here
Apply the box-sizing to the .banner and its childrens
.banner {
box-sizing: border-box;
}
.banner * {
box-sizing: inherit;
}
Also apply to the img the width and padding you need
.banner img {
width: 100%;
}
.banner > * {
padding: 5px;
}
To better help you on layout add col- classes to each img parent
.col1-3 {
width: 33.333%;
}
.col2-3 {
width: 66.666%;
}
The html:
<div class="banner cf">
<div class="col1-3"><img src="http://www.okcourtsidehoops.com/okcourtsidehoops/wp-content/uploads/2013/04/images-21.jpg" /></div>
<div class="col1-3"><img src="http://www.okcourtsidehoops.com/okcourtsidehoops/wp-content/uploads/2013/04/images-21.jpg" /></div>
<div class="col1-3"><img src="http://www.okcourtsidehoops.com/okcourtsidehoops/wp-content/uploads/2013/04/images-21.jpg" /></div>
</div>
<div class="banner cf">
<div class="col2-3"><img src="http://www.amnh.org/var/ezflow_site/storage/images/media/amnh/images/learn-teach/program-images/teacher-programs-images-folder/data-viz-images-folder/data-viz-webinar-image-3/655567-3-eng-US/data-viz-webinar-image-3_imagelarge.jpg" /></div>
<div class="col1-3"><img src="http://www.okcourtsidehoops.com/okcourtsidehoops/wp-content/uploads/2013/04/images-21.jpg" /></div>
</div>
A working example:
http://codepen.io/sandrina-p/pen/PGQKrQ
try this..
#box-wrapper {
padding-top: 10px !important;
padding-left: 5px !important;
padding-right: 5px !important;
height: 100%;
position: relative;
}
.box-banner,
.box-banner-two {
width: 100%;
height: 100%;
position: relative;
float: left;
}
.box-button {
float: left;
width: 32.444%;
margin: 0 5px 5px 0;
}
.box-button img,
.box-button-two img {
width: 100%;
}
.box-banner .box-button:nth-child(3) {
float: right !important;
}
.box-banner-two .box-button-two:nth-child(1) {
float: left;
width: 64.888%;
margin: 0 5px 5px 0;
}
.box-banner-two .box-button-two:nth-child(2) {
float: right;
width:32.444%;
margin: 0 5px 5px 0;
margin: 0;
}
<div id="box-wrapper">
<div class="box-banner">
<div class="box-button"><img src="/224/random/ffffff"></div>
<div class="box-button"><img src="/224/random/ffffff"></div>
<div class="box-button"><img src="/224/random/ffffff"></div>
</div>
<div class="box-banner-two">
<div class="box-button-two"><img src="/448x224/random/ffffff"></div>
<div class="box-button-two"><img src="/224/random/ffffff"></div>
</div>
<div style="clear:both;"></div>
</div>
<div style="clear:both;"></div>
Related
How can I synchronize the height of an image with the height of a text area, depending on the screen size? I do not want to use the left border of the text area because I want a visual separation between the left bar and the text. I do not want the width of the bar to be adjusted simultaneously, because it is only a visual separator in the page; the bar should be just as long as the text on its right side.
NB: the bar is not restricted to an image; it can be anything as long as the result is a colored vertical bar with the correct height.
html {
height: 100%;
margin: 0;
padding: 0;
}
body {
background-color: #fff8dc;
color: grey;
font-family: Arial;
font-size: 1em;
position: relative;
min-height: 100%;
}
.common {
background-color: #fff8dc;
float: left;
width: 25%;
height: 100vh;
text-align: center;
padding: 0 40px 10px 40px;
}
.detail {
background-color: #fff8dc;
float: left;
margin: 0 20px 0 0;
overflow: auto;
height: 100%
}
.text {
margin: 0px 40px 0px 40px;
background-color: #ffffff;
padding: 10px 20px 10px 20px;
}
<div class="common">
<p>blabla</p>
</div>
<div>
<div class="detail">
<img src="widgets/spacer.gif" alt="vertical bar" width="30px" height="400px" style="background-color: #E3B90A;">
</div>
<div class="text">
<h1>BLABLA</h1>
<p>blablabla</p>
<p>blablabla</p>
<p>blablabla</p>
</div>
</div>
You can do it this way:
HTML:
<div class="common">
<p>blabla</p>
</div>
<div class="container">
<div class="detail">
<img src="widgets/spacer.gif" alt="vertical bar">
</div>
<div class="text">
<h1>BLABLA</h1>
<p>blablabla</p>
<p>blablabla</p>
<p>blablabla</p>
</div>
</div>
CSS:
html {
height: 100%;
margin: 0;
padding: 0;
}
body {
background-color: #fff8dc;
color: grey;
font-family: Arial;
font-size: 1em;
position: relative;
min-height: 100%;
}
.container{
display: flex;
flex-direction: row;
}
.common {
background-color: #fff8dc;
float: left;
width: 25%;
height: 100vh;
text-align: center;
padding: 0 40px 10px 40px;
}
.detail {
background-color: #E3B90A;
width: 30px;
height: auto;
}
.detail img{
width: 100%;
height: auto;
}
.text {
width: 100%;
background-color: #ffffff;
padding: 10px 20px 10px 20px;
}
Fiddle: https://jsfiddle.net/debraj/s84yxh8L/
So I have a silly question, how do I get my divs on the right side? I have main content but I need to set up four divs on the right side. It looks like this and I need to add div1 - 4. Am I supposed to add width:100%; float: left in .main_container?
Question #2 - I would like to group main_info1 - 3 under one div like main so that I could use .main in css with max-width: 900px; overflow: hidden; margin-left: 20px; attributes for all divs without the need for repeating but when I do that main_info2 jumps up and ignores main_info1 lists. Thanks.
HTML:
<div class="main_container">
<div class="title_container">
<h1>Title</h1>
</div>
<aside>
<div class="small_blocks">
<div class="block1">
<span>Text</span>
</div>
<div class="block2">
<span>Text</span>
</div>
</div>
</aside>
<div class="content clearfix">
<div class="image1">
<img src="img/img1.jpg">
</div>
<div class="image2">
<img src="img/img2.jpg">
</div>
</div>
<div class="main_info">
<h2>Title</h2>
<p>Text</p>
</div>
<div class="main_info2 clearfix">
<h2>Title</h2>
<ul>
<li>
<p>Text</p>
</li>
</ul>
</div>
<div class="main_info3 clearfix">
<h2>Title</h2>
<p>Text</p>
</div>
</div>
CSS:
.main_container {
width: 1360px;
margin: 0 auto;
background: url("../img/bg.jpg") left top no-repeat;
background-color: #0c0334;
}
.title_container {
display: table;
}
.title_container h1 {
float: left;
display: table-cell;
vertical-align: top;
margin-top: 50px;
margin-left: 20px;
line-height: 66px;
}
.small_blocks {
min-width: 900px;
overflow: hidden;
}
.small_blocks div {
height: 55px;
margin-top: 30px;
}
.small_blocks .block1 {
float: left;
margin-left: 20px;
background: #390b5d;
width: 595px;
line-height: 52px;
}
.small_blocks .block1 span {
font-size: 30px;
padding-left: 20px;
font-weight: 100;
}
.small_blocks .block2 {
float: left;
width: 285px;
background: #e26c34;
padding-left: 20px;
line-height: 52px;
vertical-align: middle;
}
.small_blocks .block2 span {
font-size: 30px;
padding-left: 10px;
font-weight: 100;
vertical-align: middle;
display: inline-block;
}
.clearfix:after {
content: "";
visibility: hidden;
display: block;
height: 0;
clear: both;
}
.content {
width: 900px;
height: 377px;
overflow: hidden;
margin: 20px 0 0 20px;
}
.content .image1 {
float: left;
width: 268px;
}
.content .image2 {
float: left;
margin-left: 10px;
width:100%;
max-width: 622px;
}
.main_info {
max-width: 900px;
overflow: hidden;
margin-top: 60px;
margin-left: 20px;
}
.main_info h2 {
height: 34px;
border-bottom: 1px solid #390b5d;
}
.main_info2 {
max-width: 900px;
overflow: hidden;
margin: 60px 0px 0px 20px;
background: #110321;
}
.main_info2 h2 {
background: #390b5d;
min-height: 55px;
width: 880px;
padding-left: 20px;
height: 34px;
color: #fff;
line-height: 52px;
}
.main_info3 {
max-width: 900px;
overflow: hidden;
margin: 60px 0px 0px 20px;
background: #390b5d;
}
.main_info3 h2 {
min-height: 55px;
width: 880px;
padding-left: 20px;
height: 34px;
color: #fff;
line-height: 52px;
}
I think you are a newbie. You should work hard to master in HTML and CSS. :)
However, here is a solution. Please inspect them closely. Hopefully you will get your answers.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
img {
display: block;
}
.clearfix:after {
content: "";
visibility: hidden;
display: block;
height: 0;
clear: both;
}
.wrapper {
min-width: 1000px;
max-width: 1360px;
margin: 0 auto;
padding: 0 20px;
}
.title_container {
padding-top: 50px 0 30px;
}
.title_container h1 {
line-height: 66px;
}
.small_blocks {
height: 55px;
overflow: hidden;
margin-bottom: 20px;
font-size: 30px;
font-weight: 100;
line-height: 52px;
color: #fff;
}
.small_blocks > div {
height: inherit;
float: left;
padding-left: 20px;
}
.small_blocks .block1 {
background: #390b5d;
width: 66.111111%;
}
.small_blocks .block2 {
width: 33.888889%;
background: #e26c34;
}
.content {
/*height: 377px;*/
overflow: hidden;
margin-bottom: 60px;
}
.content > div img {
width: 100%;
height: auto;
}
.content .image1 {
float: left;
width: 29.777778%;
}
.content .image2 {
float: left;
width: 70.222222%;
padding-left: 10px;
}
.main_container {
width: 68.181818%;
float: left;
}
.main_info {
margin-bottom: 60px;
background: #d7d7d7;
}
.main_info .head {
padding-left: 20px;
background: #000;
color: #fff;
}
.main_info h2 {
height: 34px;
line-height: 34px;
}
.main_info .body {
padding: 20px;
}
.sidebar {
width: 31.818182%;
padding-left: 20px;
float: right;
}
.sidebar_block {
min-height: 150px;
margin-bottom: 20px;
padding: 20px;
background: #000;
color: #fff;
}
<div class="wrapper">
<header class="title_container">
<h1>Title</h1>
</header>
<main class="main_container">
<div class="small_blocks">
<div class="block1">
<span>Block 1</span>
</div>
<div class="block2">
<span>Block 2</span>
</div>
</div>
<div class="content clearfix">
<div class="image1">
<img src="http://dummyimage.com/268x377/000/fff.jpg&text=image1">
</div>
<div class="image2">
<img src="http://dummyimage.com/622x377/000/fff.jpg&text=image2">
</div>
</div>
<section class="main_info">
<div class="head">
<h2>Main Info-1 h2</h2>
</div>
<div class="body">
Main info 1
</div>
</section>
<section class="main_info">
<div class="head">
<h2>Main Info-2 h2</h2>
</div>
<div class="body">
Main info 2
</div>
</section>
<section class="main_info">
<div class="head">
<h2>Main Info-3 h2</h2>
</div>
<div class="body">
Main info 3
</div>
</section>
</main>
<aside class="sidebar">
<section class="sidebar_block">Div 1</section>
<section class="sidebar_block">Div 2</section>
<section class="sidebar_block">Div 3</section>
<section class="sidebar_block">Div 4</section>
</aside>
</div>
Regarding the questions in your comment:
Actually float works. As you use a fixed width width: 420px;, probably there has no enough space for the second ul to accommodate it in a single row. Use width: 50%; or below and see the changes. Or, you can check it in a wider screen, like, 1360px resolution.
Yes, for smaller devices.
This is a basic example. I used percentage values for the column width. So columns may become very narrower in smaller devices. To prevent that, I used min-width: 1000px for .wrapper. This will prevent narrower column width, but cause a horizontal scroll-bar in smaller devices.
I often do the width hack 49% and border 1px to do seperator for 2 column. It worked, just like the below demo. But is there any better way of doing it? I want to avoid this 49% hack, because when the viewport shrink to a larger or smaller size, it's obvious and the design will break.
body{
margin:0;
}
.left {
background: #eee;
float: left;
width: 49%;
border-right:1px solid #333;
}
.right {
background: #eee;
float: right;
width: 50%;
}
img {
margin: 0 auto;
display: block;
width: 44px;
padding: 5px 0;
}
<div class="navigate" style="width: 170px;">
<div class="left">
<img src="https://cdn0.iconfinder.com/data/icons/arrow-set/512/previous_arrow_point_flat-128.png">
</div>
<div class="right">
<img src="https://cdn0.iconfinder.com/data/icons/arrow-set/512/next_arrow_point_flat-128.png">
</div>
</div>
You can use box-sizing
CSS
body {
margin:0;
}
.left {
background: #eee;
float: left;
width: 50%;
border-right:1px solid #333;
box-sizing:border-box;
}
.right {
background: #eee;
float: right;
width: 50%;
}
img {
margin: 0 auto;
display: block;
width: 44px;
padding: 5px 0;
}
HTML
<div class="navigate" style="width: 170px;">
<div class="left">
<img src="https://cdn0.iconfinder.com/data/icons/arrow-set/512/previous_arrow_point_flat-128.png">
</div>
<div class="right">
<img src="https://cdn0.iconfinder.com/data/icons/arrow-set/512/next_arrow_point_flat-128.png">
</div>
</div>
DEMO HERE
I cannot get this red div wrap to stretch down past the other divs. I've tried using the clear:both; attribute, and a few other combinations, but to no avail. Can anyone tell me what I'm doing wrong? Thanks
#footer-wrap{
width:100%;
height:auto;
margin: 0 auto;
background:#dc0000;
}
#footer{
width:960px;
height:auto;
margin: 0 auto;
background:#dc0000;
padding: 30px 0 30px 0;
}
.footer-class{
width:126px;
height:200px;
float:left;
background:#093;
margin:0 30px 0 0;
}
.footer-class-end{
width:180px;
float:right;
background:#FF0;
}
<div id="footer-wrap">
<div id="footer">
<div class="footer-class"><h5>products</h5></div>
<div class="footer-class"><h5>support</h5></div>
<div class="footer-class"><h5>information</h5></div>
<div class="footer-class"><h5>legal</h5></div>
<div class="footer-class"><h5>interactive</h5></div>
<div class="footer-class-end"><h5>twitter</h5></div>
</div></div>
You have to clear left float with clear: left.
#footer-wrap {
width: 100%;
height: auto;
margin: 0 auto;
background: #dc0000;
}
#footer {
width: 960px;
height: auto;
margin: 0 auto;
background: #dc0000;
padding: 30px 0 30px 0;
}
.footer-class {
width: 126px;
height: 200px;
float: left;
background: #093;
margin: 0 30px 0 0;
}
.footer-class-end {
width: 180px;
float: right;
background: #FF0;
}
.clear {
clear: left;
}
<div id="footer-wrap">
<div id="footer">
<div class="footer-class">
<h5>products</h5>
</div>
<div class="footer-class">
<h5>support</h5>
</div>
<div class="footer-class">
<h5>information</h5>
</div>
<div class="footer-class">
<h5>legal</h5>
</div>
<div class="footer-class">
<h5>interactive</h5>
</div>
<div class="footer-class-end">
<h5>twitter</h5>
</div>
<div class="clear"></div>
</div>
</div>
Reference: w3.org - Floats and clearing - CSS-Tricks - What is "Float"?
A new way clearing floats without extra markup is by putting clear at :after pseudo-element (but has less browser compatibility).
#footer:after {
content: "";
clear: both;
display: block;
}
#footer-wrap {
width: 100%;
height: auto;
margin: 0 auto;
background: #dc0000;
}
#footer {
width: 960px;
height: auto;
margin: 0 auto;
background: #dc0000;
padding: 30px 0 30px 0;
}
#footer:after {
content: "";
clear: both;
display: block;
}
.footer-class {
width: 126px;
height: 200px;
float: left;
background: #093;
margin: 0 30px 0 0;
}
.footer-class-end {
width: 180px;
float: right;
background: #FF0;
}
<div id="footer-wrap">
<div id="footer">
<div class="footer-class">
<h5>products</h5>
</div>
<div class="footer-class">
<h5>support</h5>
</div>
<div class="footer-class">
<h5>information</h5>
</div>
<div class="footer-class">
<h5>legal</h5>
</div>
<div class="footer-class">
<h5>interactive</h5>
</div>
<div class="footer-class-end">
<h5>twitter</h5>
</div>
</div>
</div>
Reference: MDN - Clear
Or add just overflow:hidden to wrapper. http://jsfiddle.net/5a8vmr4r/1/
This is well known issue with floated elements...
You didn't add clearfix, thats why it doesn't work.
http://jsfiddle.net/5a8vmr4r/3/
I have the following HTML:
<div class="section group">
<div class="col span_1_of_3 articleTeaserBoxColor">
<div class="test2n">
<div class="imgHolder"><img id="NewsArticle_2790_image" class="imgArtThumb" title="" alt="" src="artOne.png" /></div>
<div class="textHolder">
<div class="textHolderTop">Care on the Fast Track</div>
<div class="textHolderBottom">The National Cancer Institute</div>
</div>
</div>
</div>
<div class="col span_1_of_3 articleTeaserBoxColor">
<div class="test2n">
<div class="imgHolder"><img id="NewsArticle_2792_image" class="imgArtThumb" title=" alt="" src="artThree.png" /></div>
<div class="textHolder">
<div class="textHolderTop">Stay Connected</div>
<div class="textHolderBottom">tool for interacting with your provider and following your healthcare</div>
</div>
</div>
</div>
<div class="col span_1_of_3 articleTeaserBoxColor">
<div class="test2n">
<div class="imgHolder"><img id="NewsArticle_2791_image" class="imgArtThumb" title="" alt="" src="artTwo.png" /></div>
<div class="textHolder">
<div class="textHolderTop">Know When Antibiotics Work and When They Don't</div>
<div class="textHolderBottom">If you or your child has a virus, antibiotics will not help you or him/her</div>
</div>
</div>
</div>
</div>
CSS:
.imgArtThumb
{
max-width: 100%;
height: auto;
}
.aTitle
{
font-size: 16px !important;
font-weight: bold;
color: #F67D24;
margin-top: 15px;
margin-bottom: 15px;
}
.test2
{
padding: 8px;
text-align: left;
box-shadow: inset 0 -1px 1px rgba(0,0,0,0.5), inset 0 1px 1px rgba(238,146,85,1);
}
.test2n
{
text-align: left;
height: 95%;
width: 95%;
padding: 2%;
overflow: hidden;
}
.articleTeaserBoxColor
{
vertical-align: top;
box-shadow: inset 0 -1px 1px rgba(0,0,0,0.5), inset 0 1px 1px rgba(238,146,85,1);
}
.test2 p, .test2n p
{
text-align: left;
}
.setP p
{
text-align: left;
padding: 10px 10px 0 0;
}
.setP article
{
text-align: left;
padding: 10px 0 0 0;
}
/* SECTIONS */
.section {
clear: both;
padding: 0px;
margin: 0px;
height: auto;
overflow: auto;
text-align: center;
width: 100%;
}
/* COLUMN SETUP */
.col {
display: block;
/*float:left;*/
display: inline-block;
margin: 1% 0 1% 0;
}
.col:first-child {
margin-left: 0;
}
/* GROUPING */
.group:before, .group:after {
content: "";
display: table;
}
.group:after {
clear: both;
}
.group {
zoom: 1; /* For IE 6/7 */
}
/* GRID OF THREE */
.span_3_of_3 {
width: 100%;
}
.span_2_of_3 {
width: 66.1%;
}
.span_1_of_3 {
width: 32.2%;
}
/* GO FULL WIDTH AT LESS THAN 480 PIXELS */
#media only screen and (max-width: 820px) {
.col {
margin: 1% 0 1% 0%;
padding-bottom: 10px;
}
}
#media only screen and (max-width: 820px) {
.span_3_of_3 {
width: 100%;
}
.span_2_of_3 {
width: 100%;
}
.span_1_of_3 {
width: 98%;
}
.imgArtThumb {
width: 100%;
height: 110px;
}
.setTableCell
{
display: block;
}
}
.imgHolder
{
float: left;
display: inline-block;
width: 43%;
padding-right: 2%;
height: 100%;
}
.textHolder
{
float: left;
display: inline-block;
width: 55%;
height: 100%;
}
.textHolderTop
{
width: 100%;
height: 48%;
text-align: left;
padding-bottom: 2%;
overflow: hidden;
}
.textHolderBottom
{
width: 100%;
height: 48%;
overflow: hidden;
text-align: left;
padding-bottom: 2%;
}
.setTableCell
{
display: table-cell;
}
At full desktop width page this is what I see:
At smaller screen (mobile) this is what I see:
If I remove the text or unchecked table-cell from the developer tool from the image below, it works fine. But I am not sure why the display: block is cancelled out if the screensize matches the condition.
How can I resolve it
In your css, .setTableCell is assigned display:table-cell below the media query part. Move it higher or give the media query a narrower selector; just being inside a media query block does not give it higher priority.