Having 2 responsive Divs Side By side - html

So basically I am trying to make a page with 2 responsive columns, the same size side by side and instead of using px for measurement I'm sizing them using percentage. No matter what I do, setting both divs to have a margin of 5% and width of 40% they should sit side by side in a container with 'display: inline-block'. But for some reason it's not.
Here's the J-Fiddle demonstrating my issue. I have content above and below these divs on the page I'm working on... so they can't interfere with that, using, declaring float positions just seems to complicate things further.
http://jsfiddle.net/avh9s6pa/
If you guys could help I'd really appreciate it. It'll be something simple no doubt, but it's driving me nuts.
.post-reg-columns {
width: 100%;
display:block;
}
.firstcolumn {
display: inline-block;
max-width: 40%;
margin:5%;
padding:10px;
}
.firstcolumn button {
color: #fff;
background-color: #6496c8;
text-shadow: -1px 1px #417cb9;
border: none;
font-size: 1.4em;
font-family: 'Bree Serif', serif;
font-weight:bold;
width: 100%;
padding:15px;
}
.firstcolumn button:hover {
background-color: #416386;
}
.secondcolumn {
display: inline-block;
background:#fff7ca;
max-width: 40%;
margin:5%;
padding:10px;
}
<div class="post-reg-columns">
<div class="firstcolumn">
<div class="title2"> Basic Listing </div>
<button>Test Button</button>
ewfwefw efwefwefw fwefwef wefwefwef wefwefwe fwefwef wefefw efwe fefwefwefw eiofj erio jweriojgjphi owriog jerioj gerijg ejfwefwef wefj weijfwe jfjiw efjwej wef weijf hello this is a test blah blah blah! My name is Chris Mayberry and this is a test
</div>
<div class="secondcolumn">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed euismod sollicitudin magna, sed placerat dui pretium quis. Vivamus sit amet velit nisi. Etiam consectetur mauris ligula, id fermentum felis fermentum ac. Phasellus pharetra a lorem ac dictum. Nullam vitae tempor ex. Mauris in vehicula augue. Maecenas sit amet porttitor enim, eu vehicula orci. Aliquam id nisl non sem mattis varius in sed nulla. Nulla ultrices fringilla erat, vitae tincidunt turpis malesuada vitae. Cras vehicula ex at arcu eleifend cursus. Sed varius dignissim risus eu fringilla.
</div>
</div>

As per your code, both divs have 40% width which means total 80%. Further, 5% margin which mean 5*4 =20%. So total becomes 100% here. And in your second div it has also 5% margin which force it to break as (100%+20%) there is no more space. You need to remove margin:5%; from .firstcolumn.
Check this fiddel

Remove margin:5%; from .firstcolumn class.
Demo here
Update answer
.post-reg-columns {
width: 100%;
display:block;
margin:5%
}
Demo Here

Related

Centring text in CSS within a "V" shape

I have this picture.
Is this possible in CSS?
Now I know you can use text-align: center and I could even make every line a span and incrementally increase the padding but is there a property I don't know about like centre from centre, or something similar?
This feels really obvious but I just can't think of a reasonable approach.
Update
The question was because in the picture the text tends to get shorter towards the bottom, much like the letter V, so t starts off wide and gets progressively narrower.
I had never seen a similar thing done so was very curious.
shape-outside can do it:
.wrapper {
display:flex; /* this is needed for the percentage height */
}
.box {
font-size: 25px;
text-align:justify;
}
.box > div,
.box::before{
height:150%; /* should be at least 100% but we consider bigger to avoid overflow */
width:100px; /* adjust this */
}
.box > div {
float:right;
shape-outside:linear-gradient(to bottom right,#0000 50%,#000 0);
}
.box::before {
content:"";
float:left;
shape-outside:linear-gradient(to bottom left,#0000 50%,#000 0);
}
/* the below is not need, it's only to illustrate the shape
uncomment it to see what is happening
.box > div {
background:linear-gradient(to bottom right,#0000 50%,red 0);
}
.box::before {
background:linear-gradient(to bottom left,#0000 50%,green 0);
}
*/
<div class="wrapper">
<div class="box">
<div></div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum pretium lacus ipsum, at placerat nunc sollicitudin scelerisque. Donec vulputate ex odio, et facilisis nisi tristique et. Maecenas tortor nisi, euismod et tellus sit amet, tincidunt congue
eros. Nam et viverra magna, id ultricies augue.
</div>
</div>
White-space: break-spaces.
With appropriate width you will get this:
#text {
font-family:sans-serif;
padding:10px;
text-align: center;
width: 600px;
white-space: break-spaces;
background-color:gray;
color: silver;
}
<div id="text">“Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam sodales ultrices nibh
at bibendum. Vivamus in volutpat diam. Vivamus ut mi non leo vehicula mattis.
Maecenas nec dolor id tellus consequat laoreet nec sit amet lacus.”
Jane from Cool Business Ltd</div>
Just apply text-align:center on the parent div.
Like this:
<div style='text-align:center'>
Your<br>
Multiline<br>
Text<br>
</div>

Horizontal Scrollbar for fixed right side bar layout in Chrome 45

I have this fixed right side bar layout working perfectly for me for a long time, it works in most of the browsers and devices too.
But the recent chrome update to 45 which happened few days ago, broke the layout by adding a horizontal scrollbar.
There are different ways to achieve the fixed right side bar layout, but this layout needs to extend the background color of main and side columns to the browser width extent with fixed max-width container(marked in red) and with shadow between columns.
And this below code was the best way I could achieve it.
Now all I need is no scrollbar in Chrome 45, I tried different ways to avoid it but none works. I know this wont be a easy fix, but any help on this would be appreciated.
http://jsfiddle.net/chetanjk/ptuxn2dq/
HTML
<div class="container" style="background:#000; color:#fff; text-align:center">
------page content max width for reference ----
</div>
<div class="page-cols">
<div class="container ">
<div class="cols-wrap">
<section class="main-col">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse ipsum sapien, tincidunt ac augue sodales, consequat sodales elit. Nunc pharetra eget velit sed pharetra.
</section>
<aside class="aside-col">
<div class="pack">
Sed luctus nisl ut ipsum scelerisque semper. Nullam euismod eros vitae odio viverra tristique. Nam pulvinar massa at diam congue, vitae fringilla neque varius. In molestie quis neque luctus facilisis.
Vestibulum sit amet mi ut odio condimentum dictum vel a metus. Morbi ultrices enim ut accumsan lacinia. Praesent augue purus, bibendum in odio in, pharetra consectetur mi. Vivamus ac arcu dignissim, placerat ipsum eu, tempor magna. Integer nec ipsum dui. Quisque at diam est. Aliquam ut placerat ligula, eu venenatis turpis. Sed nec eros vel ante ornare eleifend. Suspendisse aliquam nulla consectetur tellus molestie efficitur.
</div>
</aside>
</div>
</div>
</div>
CSS
body{
font-family: arial;
font-size: 14px;
color: #333;
line-height: 1.5;
overflow-y: scroll;
margin:0;
padding: 0;
}
*, *::before, *::after {
box-sizing: border-box;
}
.container:after,
.cols-wrap:after,
.page-cols:after{
clear: both;
content: "";
display:table;
}
.container{
margin: 0 auto;
max-width: 1200px;
min-width: 300px;
padding:0 10px;
position: relative;
}
.page-cols{
background-color: #999;
}
.cols-wrap{
width: 100%;
position: relative;
background-color: #ccc; /*this can be #fff too to match body bg*/
box-shadow: 10px 10px 10px -10px #000;
right: 320px;
}
.cols-wrap .main-col{
float: left;
left: 320px;
position: relative;
width: 100%;
padding-right: 340px;
}
.cols-wrap .aside-col{
float: right;
position: relative;
width: 320px;
margin-right: -320px;
padding-left: 20px
}

Expanding div height in CSS

So on my page, I have a two column layout - 75% (left - blue) and 25% (right - red). I can't get the red column to fill. In Chrome's inspector I see that the container classed <div> has expanded vertically to the size of #left, but I just cannot coax #right to expand appropriately. Here's the jfiddle link for my css and html (followed by the code itself in case you don't want to click to tinker):
Just one quick note: In my actual development code I don't use blue and red (left and right div background colours) - I use white and navy, respectively.
http://jsfiddle.net/EG3zb/
<div class="container">
<div id="left">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam id nunc bibendum ligula tempus interdum a ac urna. Fusce sed nunc molestie, consequat orci eu, vehicula orci. Suspendisse nec leo sit amet tellus varius feugiat. Maecenas lacinia neque euismod, tincidunt nisi et, fermentum ipsum. Vivamus ut gravida velit, vitae ultrices ante. Nullam varius mattis tellus, vitae consectetur tortor porttitor eu. Donec congue eros mauris. Ut consequat aliquam mattis. Aliquam non neque eros.</p>
</div>
<div id="right">
Blah.
</div>
</div>
And the accompanying CSS:
.container {
width: 100%;
min-height: 100%;
overflow: auto;
}
#left, #right {
padding-top: 2%;
}
#left {
float: left;
width: 75%;
color: #fff;
background-color: blue;;
}
#right {
float: right;
width: 25%;
background-color: red;
color: #fff;
}
this is working
.container {
width: 100%;
min-height: 100%;
overflow: auto;
display:flex;
}
.container #left,.container #right{
-webkit-flex: auto;
-ms-flex:auto;
flex:auto;
}
here is working demo
http://jsfiddle.net/mauryaashish945/EG3zb/5/
Instead of default display:block you can use display:table-cell so there is no need for float:left\right :
#left, #right {
display:table-cell;
}
Example

Div refuses to center

The problem should be able to be seen live at this link (on every page, as the main content of the page is contained by my "content" div): http://tucsonbagley.com/index.html
The "content" class (a container div) has a much larger margin on the left than on the right and, after going over my CSS ad nauseum, I just cannot figure out why. I've broken something for sure (it was working not long ago!), but I just can't figure out what.
If I remove my id Navbar or id Header divs, the Content div will default back to the left... yeah, at this point I'm lost.
The CSS in question:
.content{
display:inline-block;
margin:0 auto;
width: 68%;
overflow:hidden;
text-align: center;
padding: 10px;
background-color: #FFFFFF;
font-size: 12px;
border-radius: 10px 10px 10px 10px;
}
Example HTML:
<body>
<div class="header">
<p>Tucson Bagley</p>
</div>
<div id="socialmedia">
<img src="images/Twitter_logo_blue.png"/>
<img src="images/linkedin.png"/>
<img src="images/facebook.png"/>
</div>
<div id="header">
<small>BagelHero#gmail.com</small>
</div>
<div id="navbar">
<ul>
<li><span>Gallery</span></li>
<li><span>Resume/CV</span></li>
<li><span>Contact me</span></li>
</ul>
</div>
<div class="content">
<div class="thumbleft"><h2>This is some content.</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin non varius metus. Pellentesque eu nunc tortor. Aliquam id lectus orci. Sed id consectetur eros. Curabitur semper nisl nibh, rhoncus lacinia nibh volutpat at. Pellentesque sollicitudin vitae ipsum ut dictum. Proin ac risus ac nisi interdum hendrerit. Pellentesque sodales mauris ac eleifend vehicula. Nulla convallis aliquet urna varius auctor. Donec eget ipsum ut mauris consequat auctor eget sit amet odio. Nullam sed lorem erat. Praesent consequat porttitor magna, sit amet feugiat odio tincidunt ut. Fusce congue eros vel quam condimentum, vel consectetur quam imperdiet. </p>
</div>
</br>
<div id="copyright">
<p>Copyright 2012-2014 | Tucson Bagley</p>
</div>
</body>
Some help would be appreciated. Thanks in advance!
Add a <div style="clear:both"></div> before .content div and apply display:block to .content instead of display:inline-block and that's it
change the css of your .content to look like this
.content{
position: absolute;
left:0px;
right:0px;
display:inline-block;
margin:10px auto;
width: 68%;
overflow:hidden;
text-align: center;
padding: 10px;
background-color: #FFFFFF;
font-size: 12px;
border-radius: 10px 10px 10px 10px;
}
the magic is the left:0px combined with right:0px and margin:10px auto which will only work in absolute mode.
Edit - updated css as per comments.

Text extends out of <div> once in <p> tag?

I am trying to do something very simple. I want my text to stay contained within my <div>. I was having this problem earlier with two floating divs. I tried clearing them, and using word-wrap however that did not solve the problem. So I put that on hold then moved on to something new.
While creating another div that was not floating, I noticed once I placed the text inside the <p></p> tag, the text extended outside the div again. I know this because initially I forgot to place the text in the <p> tag, and the text stayed in the box. Once I corrected it, the text extended out again. Please help. I am pulling my hair out for what I know should be something simple.
Side Note: I do not want to use overflow:scroll;. I don't have enough text for that.
#topNews {
width: 625px;
height: 220px;
position: relative;
font-family: Arial Arial, Helvetica, sans-serif;
font-size: 14px;
border-bottom: solid #7e7d7d thin;
float: left;
margin-left: -30px;
margin-top: -15px;
}
#about {
width: 320px;
height: 180px;
position: relative;
margin-right: 3px;
margin-left: 3px;
margin-top: 7px;
border: dashed red thin;
}
<div id="topNews">
<div id="about">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse et turpis sed metus fermentum pellentesque. Vestibulum auctor neque ac nunc elementum malesuada. Praesent non est sed libero vestibulum consectetuer. Sed vehicula. Vivamus quis tellus sit amet erat ultrices luctus. Fusce a ligula. Fusce viverra libero vitae velit.
</p>
</div>
</div>
Its Gone out of div because
#topNews {
width: 625px;
height: 220px;
position: relative;
font-family: Arial Arial, Helvetica, sans-serif;
font-size: 14px;
border-bottom: solid #7e7d7d thin;
float: left;
margin-left: -30px;
margin-top: -15px;
}
In your code you specifies margin with -ve value. So its starting position may be in -ve x-axis.
Use +ve x-axis values...
like
margin-left: 0px;
margin-top: 0px;
Fiddle link
Text IS inside a div, its just the div is positioned out of you view because you used:
margin-left: -30px;
margin-top: -15px;
check out this image: click (i edited -30 and -15 to 0 and 0)
to make your job easier in future, use developer tools (f12 by default)
I just tried out your sample code and the text is contained in the DIV properly ..
I think this will helpful for you.
HTML
<div id="topNews">
<div id="about">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse et turpis sed metus fermentum pellentesque. Vestibulum auctor neque ac nunc elementum malesuada. Praesent non est sed libero vestibulum consectetuer. Sed vehicula. Vivamus quis tellus sit amet erat ultrices luctus. Fusce a ligula. Fusce viverra libero vitae velit.
</p>
</div>
<div id="about">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse et turpis sed metus fermentum pellentesque. Vestibulum auctor neque ac nunc elementum malesuada. Praesent non est sed libero vestibulum consectetuer. Sed vehicula. Vivamus quis tellus sit amet erat ultrices luctus. Fusce a ligula. Fusce viverra libero vitae velit.
</p>
</div>
</div>
CSS
#topNews{
width:625px;
height:220px;
position:relative;
font-family:Arial Arial, Helvetica, sans-serif;
font-size: 14px;
border-bottom:solid #7e7d7d thin;
}
#about{
width:200px;
float:left;
margin-right:3px;
margin-left:3px;
margin-top:7px;
padding:5px;
border: dashed red thin;
}
Perhaps you have css somewhere after that changes the size of your p tag. Also if you have anything with a width of 100% (ie: width: 100%;), it's always 100% plus the size of your margins/padding which would make elements stick out.