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.
Related
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>
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've been searching online for an answer and can't really find a solution. I'm trying to display an image and then directly below have a colored block (that is attached to the bottom of the image) for a caption on the image.
Below are my CSS code and HTML for the page.
I have this css code:
/* SECTIONS */
.section {
clear: both;
padding: 0px;
margin: 0px;
}
/* COLUMN SETUP */
.col {
display: block;
float:left;
margin: 1% 0 1% 5.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 FOUR */
.span_4_of_4 {
width: 100%;
}
.span_3_of_4 {
width: 73.75%;
}
.span_2_of_4 {
width: 47.5%;
}
.span_1_of_4 {
width: 21.25%;
}
/* GO FULL WIDTH BELOW 480 PIXELS */
#media only screen and (max-width: 480px) {
.col { margin: 1% 0 1% 0%; }
.span_1_of_4, .span_2_of_4, .span_3_of_4, .span_4_of_4 { width: 100%; }
}
/***** HTML CODE: *****/
<div class="section group">
<div class="col span_1_of_4">
<img src="XXX" style="border-width: 1px; border-style: solid; width: 190px; height: 255px;" /></a>
<br />
TEXT HERE
</div>
</div>
.img-wrapper {
background: #888;
border-width: 1px;
border-style: solid;
}
.img-wrapper img {
width: 100%;
padding-bottom: 50px;
}
<div class="section group">
<div class="col span_1_of_4">
<div class="img-wrapper">
<img src="xxx">
<br>
TEXT HERE
</div>
</div>
</div>
Wrap the image and the caption in the same div, and give that div a background color.
Here's a simple example:
<div id="wrapper">
<img src="XXX" style="width: 190px; height: 255px;" />
Text
</div>
#wrapper {
background: #ccc;
display: inline-block;
}
#wrapper a {
text-align: center;
display: block;
padding: 10px;
}
http://jsfiddle.net/eo9wfx5c/1/
I need little help for my CSS.
I am trying to make a comment system but it has something went wrong.
This is my DEMO page from codepen.io
You can see there is a user avatar and textarea. The container max-width:650px; when you reduced width the browser the it is automatically changing.
anyone can help me in this regard?
HTML
<div class="container">
<div class="comment">
<div class="commenter">
<img src="https://igcdn-photos-c-a.akamaihd.net/hphotos-ak-xta1/t51.2885-19/11084950_1591056347778266_1536322251_a.jpg">
</div>
<div class="comment-text-area">
<textarea class="textinput" placeholder="Comment"></textarea>
</div>
</div>
</div>
CSS
body {
background-color: #dddddd;
}
.container {
position: relative;
max-width: 650px;
margin: 0px auto;
margin-top: 50px;
}
.comment {
background-color: blue;
float: left;
width: 100%;
height: auto;
}
.commenter {
float: left;
}
.commenter img {
width: 35px;
height: 35px;
}
.comment-text-area {
float: left;
width:100%;
height: auto;
background-color: red;
}
.textinput {
float:left;
width: 100%;
min-height: 35px;
outline: none;
resize: none;
border: 1px solid #f0f0f0;
}
I want to make it like this:
You could try using calc(); to perform the calculation for you... baring in mind you would need to add the vendor prefixes to this.
body {
background-color: #dddddd;
}
.container {
position: relative;
max-width: 650px;
margin: 0px auto;
margin-top: 50px;
}
.comment {
background-color: blue;
float: left;
width: 100%;
height: auto;
}
.commenter {
float: left;
}
.commenter img {
width: 35px;
height: 35px;
}
.comment-text-area {
float: right;
width: calc(100% - 45px);
height: auto;
background-color: red;
}
.textinput {
float:left;
width: 100%;
min-height: 35px;
outline: none;
resize: none;
border: 1px solid #f0f0f0;
}
<div class="container">
<div class="comment">
<div class="commenter">
<img src="https://igcdn-photos-c-a.akamaihd.net/hphotos-ak-xta1/t51.2885-19/11084950_1591056347778266_1536322251_a.jpg">
</div>
<div class="comment-text-area">
<textarea class="textinput" placeholder="Comment"></textarea>
</div>
</div>
</div>
as an option instead of float use display: table
*{
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
background-color: #dddddd;
}
.container {
position: relative;
max-width: 650px;
margin: 0px auto;
margin-top: 50px;
}
.comment {
background-color: #00f;
height: auto;
display: table;
width: 100%;
padding: 5px;
}
.commenter,
.comment-text-area{
display: table-cell;
vertical-align: top;
}
.commenter{
width: 35px;
padding-right: 5px;
}
.commenter img {
width: 35px;
height: 35px;
}
.comment-text-area {
width:100%;
height: 100%;
/*background-color: red;*/
}
.textinput {
width: 100%;
min-height: 35px;
outline: none;
resize: none;
border: 1px solid #f0f0f0;
}
<div class="container">
<div class="comment">
<div class="commenter">
<img src="https://igcdn-photos-c-a.akamaihd.net/hphotos-ak-xta1/t51.2885-19/11084950_1591056347778266_1536322251_a.jpg">
</div>
<div class="comment-text-area">
<textarea class="textinput" placeholder="Comment"></textarea>
</div>
</div>
</div>
For scenarios like this I combine float:left;and float:none; The avatar wrapper div gets the float:left; and the comment wrapper div gets the float:none;.
The trick here is to put padding-left on the float:none; div equal to the width of the float:left; div.
.comment {
background-color: blue;
float: left;
width: 100%;
height: auto;
}
.commenter {
float: left;
width:35px;
}
.commenter img {
width: 35px;
height: 35px;
}
.comment-text-area {
float: none;
height: auto;
background-color: red;
padding-left:35px;
}
Here is a working demo
See this fiddle
I have changed your CSS a little bit. See the changes below. The problem with your CSS was that you used no width for .commenter. Thus it took default 100% width.
CSS
.commenter {
float: left;
width: 6%;
}
.comment-text-area {
float: left;
width: 94%;
height: auto;
background-color: red;
}
EDIT
use width for .commenter as width: 35px;..I chose 35px because it is the width of the avatar image.
only change .comment-text-area height:94%
body {
background-color: #dddddd;
}
.container {
position: relative;
max-width: 650px;
margin: 0px auto;
margin-top: 50px;
}
.comment {
background-color: blue;
float: left;
width: 100%;
height: auto;
}
.commenter {
float: left;
}
.commenter img {
width: 35px;
height: 35px;
}
.comment-text-area {
float: left;
width: 94%;
height: auto;
background-color: red;
}
.textinput {
float:left;
width: 100%;
min-height: 35px;
outline: none;
resize: none;
border: 1px solid #f0f0f0;
}
<div class="container">
<div class="comment">
<div class="commenter">
<img src="https://igcdn-photos-c-a.akamaihd.net/hphotos-ak-xta1/t51.2885-19/11084950_1591056347778266_1536322251_a.jpg">
</div>
<div class="comment-text-area">
<textarea class="textinput" placeholder="Comment"></textarea>
</div>
</div>
</div>
you can give the class name form-control to the <textarea> like this:
<textarea class="form-control" rows="3" cols="90" ></textarea>
Reference: https://www.w3schools.com/bootstrap/bootstrap_forms_inputs.asp
<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;
}
.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%;
}
.test2n
{
text-align: left;
height: 95%;
width: 95%;
padding: 2%;
overflow: hidden;
}
.articleTeaserBoxColor
{
box-shadow: inset 0 -1px 1px rgba(0,0,0,0.5), inset 0 1px 1px rgba(238,146,85,1);
}
/* COLUMN SETUP */
.col {
display: block;
/*float:left;*/
display: inline-block;
margin: 1% 0 1% 0;
}
.col:first-child {
margin-left: 0;
}
.span_1_of_3 {
width: 32.2%;
}
/* GROUPING */
.group:before, .group:after {
content: "";
display: table;
}
.group:after {
clear: both;
}
.group {
zoom: 1; /* For IE 6/7 */
}
/* SECTIONS */
.section {
clear: both;
padding: 0px;
margin: 0px;
height: auto;
overflow: auto;
text-align: center;
width: 100%;
}
displays this:
How can I modify my CSS to ensure the three boxes (the one with the box shadow) height matches that of the box with the most text (The middle box should be the same height, but because of content it is shorter).
Any content within a box, which is less than the box with the most text, will have blank space, which is fine.
This is what I would like it to be:
There are several ways and methods, but here's a quick one:
.col {
display: table-cell;
vertical-align: top:
}
Demo http://jsfiddle.net/Lg9y9s93/1
Are Flexbox or jQuery possibilities? As others have mentioned the only pure CSS way (at the moment) is via table-cell which I'm not a huge fan of.
If jQuery is possible there's a fairly simple script I use to make heights match:
CSS:
.item{
float: left;
width: 280px;
}
jQuery:
// Set 'x' number of items to the tallest height
var tallestBox = 0;
$(".item").each(function() {
var divHeight = $(this).height();
if (divHeight > tallestBox){
tallestBox = divHeight;
}
});
// Apply height & add total vertical padding
$(".item").css("height", tallestBox + 30);
Or if Flexbox is possible (modern browsers) this is crazy easy now:
CSS:
.contain{
display: flex;
flex-direction: row;
}
You can use pseudo table layout: http://jsfiddle.net/8rvdkyke/
.content {
display: table;
width: 400px;
}
.content > div {
display: table-cell;
height: 100%;
vertical-align: top;
}
This listing of code is emulating behavior of table layout causing all children div's to be the same height. You can tweak the sizes and other styles for your needs.
UPD: For responsive layout out, you can switch between table-cell and table-row to make them arranged horizontally (table-cell) and vertically (table-row): http://jsfiddle.net/8rvdkyke/1/
This is how I do this (as of this date)
http://jsfiddle.net/sheriffderek/ae2sawnn/
HTML
<section class="your-section">
<ul class="block-list">
<li class="block">
<a href="#">
<div class="image-w">
<img src="http://placehold.it/1600x900" alt="your-image" />
</div>
<div class="text-w">
<p><strong>Might as well have the whole thing a link</strong> and not just that little bitty part of a sentence... etc... etc...</p>
</div>
</a>
</li>
<li class="block">
{{ ... }}
</li>
<li class="block">
{{ ... }}
</li>
</ul>
</section> <!-- .your-section -->
CSS
* {
box-sizing: border-box;
}
body {
margin: 0;
}
a {
text-decoration: none;
color: inherit;
}
.your-section {
width: 100%;
float: left;
}
.block-list {
width: 100%;
float: left;
list-style: none;
margin: 0; padding: 0;
}
.block {
width: 100%;
float: left;
padding: .5rem;
margin-bottom: 1rem;
border: 1px solid red;
}
.block a {
display: block;
}
.image-w {
width: 100%;
float: left;
}
.image-w img {
display: block;
width: 100%;
height: auto;
}
.text-w {
width: 100%;
float: left;
}
#media (min-width: 600px) {
.block {
width: 33%;
margin-bottom: 0;
}
} /* end break-point 1 */
JS
// resources
// http://stackoverflow.com/questions/14167277/equal-height-rows-for-fluid-width-elements
// #popnoodles 's answer on S.O.
$.fn.extend({
equalHeights: function(){
var top = 0;
var row = [];
var classname = ('equalHeights'+Math.random()).replace('.','');
$(this).each(function(){
var thisTop = $(this).offset().top;
if ( thisTop > top ) {
$('.'+classname).removeClass(classname);
top = thisTop;
}
$(this).addClass(classname);
$(this).outerHeight('auto');
var h = (Math.max.apply(null, $('.'+classname).map(function(){ return $(this).outerHeight(); }).get()));
$('.'+classname).outerHeight(h);
}).removeClass(classname);
}
});
$(function(){ // call the function
$(window).resize(function() {
// on resize... but also... trigger that once by default right off the bat
$('.block').equalHeights();
}).trigger('resize');
});