I need 2 divs inside a big one:
the first will float left and second will float right
i gave the 1st div width of 75% and the 2nd 25%, it seems that the 2nd div is not finding its right place so it keeps coming under the left div on the right side
this is my code:
<div class="centerDiv2">
<span class="title2">LATEST BULLETIN</span>
<hr>
<div class="divLeft">
<img src="images/5891.jpg"/>
<span class="title">JUL 19</span>
<p class ="prog">"I Mathew</p>
</div>
<div class="divLeft">
<img src="images/42St.jpg"/>
<span class="title">JUL 19</span>
<p class ="prog">"I Mathew</p>
</div>
<div class="divRight">
<span class="title">RECENTLY</span>
<hr>
</div>
</div>
CSS:
.divLeft {
width:70%;
margin: 30 0;
}
.title2 {
font-size: 20px;
font-weight:bolder;
font-family: courier;
float: left;
width: 100%;
}
.centerDiv2 {
width: 1000px;
margin: 30 auto;
}
.divRight {
width:25%;
height:400px;
background-color: lightgray;
float:right;
margin: 30 0;
}
HTML:
<div class="centerDiv2">
<span class="title2">LATEST BULLETIN</span>
<hr>
<div class="leftDiv">
<div class="divLeft">
<img src="images/5891.jpg"/>
<span class="title">JUL 19</span>
<p class ="prog">"I Mathew</p>
</div>
<div class="divLeft">
<img src="images/42St.jpg"/>
<span class="title">JUL 19</span>
<p class ="prog">"I Mathew</p>
</div>
</div>
<div class="divRight">
<span class="title">RECENTLY</span>
<hr>
</div>
</div>
CSS:
.title2 {
font-size: 20px;
font-weight:bolder;
font-family: courier;
width: 100%;
}
.leftDiv{
width: 70%; display: inline-block;
}
.divRight {
display: inline-block; vertical-align: top; height: 400px; width: 25%;background-color: lightgray;
}
hi dude the issue is with width 75% and 25% using with the margin because you are giving margin though you have already 100% of you canvas means(body)
.wrapper{
margin: 30px 0;
}
.divLeft {
width:70%;
background-color:red;
}
.title2 {
font-size: 20px;
font-weight:bolder;
font-family: courier;
float: left;
width: 100%;
}
.centerDiv2 {
width: 1000px;
margin: 30px auto;
}
.divRight {
width:25%;
height:400px;
background-color: lightgray;
float:right;
margin: 30px 0;
background-color:black;
}
<div class="centerDiv2">
<span class="title2">LATEST BULLETIN</span>
<hr>
<div class="wrapper">
<div class="divLeft">
<img src="images/5891.jpg"/>
<span class="title">JUL 19</span>
<p class ="prog">"I Mathew</p>
</div>
<div class="divLeft">
<img src="images/42St.jpg"/>
<span class="title">JUL 19</span>
<p class ="prog">"I Mathew</p>
</div>
</div>
<div class="divRight">
<span class="title">RECENTLY</span>
<hr>
</div>
</div>
Related
I am making a web that's like a facebook where there is a image on the left and text on the right but if the text reach the bottom of the image it goes to the bottom of image. Its hard to explain so I will attached a screenshot
.comment {
width: 100%;
}
.comment img {
height: 40px;
width: 40px;
border-radius: 20px;
margin-right: 10px;
float: left;
}
.comment img:after {
content: "";
}
strong {
color: #365899;
font-weight: bold;
}
<div id="View_post-1" class="row">
<div>
<div class="comment">
<img src="../Image/Mark Anthony Fernandez.jpg">
<small>
<strong style="">Mark Anthony Fernandez</strong>
</small>
<br />
<div>
<span style="font-size:small;position:relative;word-wrap:break-word;">commentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcomment</span>
</div>
<br>
</div>
</div>
</div>
If I understand well you don't want the text to wrap around the image to the left.
You can use flexbox to achieve that and it will give you a responsive solution.
I have created a codepen for your case: https://codepen.io/frexos/pen/yPjqYm
<div id="View_post-1" class="row">
<div>
<div class="comment">
<img src="../Image/Mark Anthony Fernandez.jpg">
<div class="text">
<small>
<strong style="">Mark Anthony Fernandez</strong>
</small>
<br />
<div>
<span style="font-size:small;position:relative;word-wrap:break-word;">commentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcomment</span>
</div>
</div>
<br>
</div>
.comment {
width: 100%;
display: flex;
}
.comment img {
display: block;
height: 40px;
width: 40px;
border-radius: 20px;
margin-right: 10px;
float: left;
}
.comment img:after {
content: "";
}
strong {
color: #365899;
font-weight: bold;
}
.text {
min-width: 10%;
word-wrap: break-word;
}
It looks you are using bootstrap to set your layout, you can use media object for this, check updated snippet below... for detail reference click here
.comment{
width:100%;
}
.comment img{
border-radius: 50px;
}
.comment img:after{
content:"";
}
strong{
color:#365899;
font-weight:bold;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div id="View_post-1" class="row">
<div>
<div class="comment">
<div class="media">
<div class="media-left">
<img class="media-object" src="https://dummyimage.com/50x50/cccccc/ff0000.png&text=Sample-Text">
</div>
<div class="media-body"><small>
<strong style="">Mark Anthony Fernandez</strong>
</small>
<br />
<div>
<span style="font-size:small;position:relative;word-wrap:break-word;">commentcommentcommentcom mentcommentcommentcommentcommen tcommentcommentcommentcommentcommentc ommentcommentcommentcom mentcommentco mmentcommentcomme ntcommentcommentcommentcomme ntcomm entcommentcommentcomme ntcommentcommentcommentcommentcommen tcommentcommentcommentcommentcommentcommentcommentc ommentcommentcomm entcomment</span>
</div>
<br>
</div>
</div>
</div>
</div>
</div>
If you always know the width of the image you can just add a padding left to your div containing the text.
.comment > div{ padding-left: 50px;}
.comment {
width: 100%;
}
.comment img {
height: 40px;
width: 40px;
border-radius: 20px;
margin-right: 10px;
float: left;
}
.comment img:after {
content: "";
}
strong {
color: #365899;
font-weight: bold;
}
.comment > div{ padding-left: 50px;}
<div id="View_post-1" class="row">
<div>
<div class="comment">
<img src="../Image/Mark Anthony Fernandez.jpg">
<div>
<small>
<strong style="">Mark Anthony Fernandez</strong>
</small>
<br />
<div>
<span style="font-size:small;position:relative;word-wrap:break-word;">commentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcomment</span>
</div>
</div>
<br>
</div>
</div>
</div>
Try this:
.comment div{
display: flex;
word-break: break-all;
}
Please try this code:
.comment {
display: inline-block;
width: 100%;
}
.comment .image {
float: left;
width: 80px;
}
.comment img {
height: 40px;
width: 40px;
border-radius: 20px;
margin-right: 10px;
float: left;
}
.content {
float: left;
width: -webkit-calc(100% - 80px);
width: -moz-calc(100% - 80px);
width: -ms-calc(100% - 80px);
width: calc(100% - 80px);
}
.comment img:after {
content: "";
}
strong {
color: #365899;
font-weight: bold;
}
<div id="View_post-1" class="">
<div>
<div class="comment">
<div class="image">
<img src="../Image/Mark Anthony Fernandez.jpg">
</div>
<div class="content">
<small>
<strong style="">Mark Anthony Fernandez</strong>
</small>
<br />
<div>
<span style="font-size:small;position:relative;word-wrap:break-word;">commentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcommentcomment</span>
</div>
</div>
</div>
</div>
</div>
How to wrap div boxes into main div along with images with responsive.?
Am trying to achieve below layout.
When i use float:left the boxes are aligned perfect where as without it if i use display inline block the boxes are not aligned as shown below.
My jfiddle
.mywrapper {
margin: 0 auto;
min-width: 320px;
max-width: 905px;
background: yellow;
}
.firstblock {
margin-top: 60px;
margin-bottom: 60px;
background: red;
//background: #2b2b2b;
padding:30px;
width:auto;
height:auto;
}
.mainimage{
width: 190px;
height: 125px;
margin-left:2%;
float:left;
padding-right:30px;
}
.smallbox{
float: left;
width: 190px;
height: 110px;
background-color: green;
margin-right:10px;
}
.secondblock {
margin-bottom: 30px;
height: 215px;
background: aqua;
padding:30px;
}
<div class="mywrapper" id="myid">
Hello
<div class="firstblock">
<div >
<img class="mainimage" src="mainimg.JPG" border="0" />
</div>
<div>
<h2 class="title"><span>MY TEXT MY TEXT MY TEXT MY TEXT MY TEXT MY TEXT MY TEXT MY TEXT</span></h2>
<div class="smallbox"><img class="pcspecimg" src="box1.JPG" alt="box1.JPG" border="0" /><span>box1</span><div>MY TEXT</div></div>
<div class="smallbox"><img class="pcspecimg" src="box2.JPG" alt="box2.JPG" border="0" /><span>box2</span><div>MY TEXT MY TEXT</div></div>
<div class="smallbox"><img class="pcspecimg" src="box3.JPG" alt="box3.JPG" border="0" /><span>box3</span><div>MY TEXT MY TEXT</div></div>
</div>
</div>
<div class="secondblock">
secondblock
</div>
</div>
I think you would like this
.mywrapper {
margin: 0 auto;
min-width: 320px;
max-width: 905px;
background: yellow;
}
.firstblock {
margin-top: 60px;
margin-bottom: 60px;
background: red;
//background: #2b2b2b;
padding:30px;
width:auto;
height:auto;
}
.left-div{
float:left;
width: 27%;
height: 125px;
margin-right:2%;
border: 1px solid;
}
.right-div{
float:right;
width:70%;
}
h2{
margin-top:0;
}
.clear{
clear:both;
}
img{
height:auto;
width:auto;
max-width:100%;
max-height:100%;
}
.pcspecimg {
border: 1px solid #fff;
float: left;
height: 40px;
margin-right: 3%;
width: 27%;
}
.small-wrap {
margin-bottom: 5px;
}
.smallbox {
background-color: green;
float: left;
height: 110px;
margin-right: 1.5%;
width: 32.3%;
padding:5px;
box-sizing: border-box;
}
.smallbox:last-child{
margin-right:0;
}
.secondblock {
margin-bottom: 30px;
height: 215px;
background: aqua;
padding:30px;
}
<div class="mywrapper" id="myid">
Hello
<div class="firstblock">
<div class="left-div">
<img class="mainimage" src="mainimg.JPG" border="0" />
</div>
<div class="right-div">
<h2 class="title">
<span>MY TEXT MY TEXT</span>
</h2>
<div class="smallbox">
<div class="small-wrap">
<div class="pcspecimg">
<img src="box1.JPG" alt="box1" border="0" />
</div>
<span>box1</span>
<div class="clear"></div>
</div>
<div>MY TEXT</div>
</div>
<div class="smallbox">
<div class="small-wrap">
<div class="pcspecimg">
<img src="box1.JPG" alt="box1" border="0" />
</div>
<span>box1</span>
<div class="clear"></div>
</div>
<div>MY TEXT</div>
</div>
<div class="smallbox">
<div class="small-wrap">
<div class="pcspecimg">
<img src="box1.JPG" alt="box1" border="0" />
</div>
<span>box1</span>
<div class="clear"></div>
</div>
<div>MY TEXT</div>
</div>
</div>
<div class="clear"></div>
</div>
<div class="secondblock">
secondblock
</div>
</div>
.mywrapper {
margin: 0 auto;
min-width: 320px;
max-width: 905px;
background: yellow;
}
.firstblock {
display: flex;
flex-direction: row;
margin-top: 60px;
margin-bottom: 60px;
background: red;
//background: #2b2b2b;
padding:30px;
width:auto;
height:auto;
}
.mainimage{
width: 190px;
height: 125px;
margin-left:2%;
float:left;
padding-right:30px;
}
.smallbox{
float: left;
width: 190px;
height: 110px;
background-color: green;
margin-right:10px;
}
.secondblock {
margin-bottom: 30px;
height: 215px;
background: aqua;
padding:30px;
}
<div class="mywrapper" id="myid">
Hello
<div class="firstblock">
<div>
<img class="mainimage" src="mainimg.JPG" border="0" />
</div>
<div>
<h2 class="title"><span>MY TEXT MY TEXT MY TEXT MY TEXT MY TEXT MY TEXT MY TEXT MY TEXT</span></h2>
<div class="smallbox"><img class="pcspecimg" src="box1.JPG" alt="box1.JPG" border="0" /> <span>box1</span><div>MY TEXT</div>
</div>
<div class="smallbox"><img class="pcspecimg" src="box2.JPG" alt="box2.JPG" border="0" /> <span>box2</span><div>MY TEXT MY TEXT</div>
</div>
<div class="smallbox"><img class="pcspecimg" src="box3.JPG" alt="box3.JPG" border="0" /> <span>box3</span><div>MY TEXT MY TEXT</div>
</div>
</div>
</div>
<div class="secondblock">
secondblock
</div>
</div>
Is it you want?
Can You explain detail?
I have 2 columns of numbers that I want them to appear side by side. It works when I try using float: left but I want them to appear in the center. Without the float they appear one row then next row downwards.
body {
color: #fff;
text-align: center;
}
#roll, #roll2, #roll3, #roll4 {
width: 40px;
height: 360px;
background: #0077ee;
margin: 0 auto;
}
.roll-h {
width: 40px;
height: 120px;
margin: 0 auto;
overflow: hidden;
}
.shadow {
height: 40px;
margin: 0 auto;
transform: translateY(40px);
}
.black,
.his-h {
width: 40px;
height: 40px;
font-size: 20px;
line-height: 40px;
font-weight: 700;
text-align: center;
float: left;
}
.black {
background: black;
}
.floatleft {
float: left;
}
<div class="floatleft">
<div class="shadow"></div>
<div class="roll-h">
<div id="roll3">
<div class="black">9</div>
<div class="black">0</div>
<div class="black">1</div>
<div class="black">2</div>
<div class="black">3</div>
<div class="black">4</div>
<div class="black">5</div>
<div class="black">6</div>
<div class="black">7</div>
<div class="black">8</div>
<div class="black">9</div>
<div class="black">0</div>
</div>
</div>
</div>
<div class="floatleft">
<div class="shadow"></div>
<div class="roll-h">
<div id="roll4">
<div class="black">9</div>
<div class="black">0</div>
<div class="black">1</div>
<div class="black">2</div>
<div class="black">3</div>
<div class="black">4</div>
<div class="black">5</div>
<div class="black">6</div>
<div class="black">7</div>
<div class="black">8</div>
<div class="black">9</div>
<div class="black">0</div>
</div>
</div>
</div>
you have to add a parent (container) div around all your html with following styles:
<div style="margin:0 auto; display:inline-block">
see it here:
body {
color: #fff;
text-align: center;
}
#roll, #roll2, #roll3, #roll4 {
width: 40px;
height: 360px;
background: #0077ee;
margin: 0 auto;
}
.roll-h {
width: 40px;
height: 120px;
margin: 0 auto;
overflow: hidden;
}
.shadow {
height: 40px;
margin: 0 auto;
transform: translateY(40px);
}
.black,
.his-h {
width: 40px;
height: 40px;
font-size: 20px;
line-height: 40px;
font-weight: 700;
text-align: center;
float: left;
}
.black {
background: black;
}
.floatleft {
float: left;
}
.container {
display:inline-block;
margin:0 auto;
}
<div class="container">
<div class="floatleft">
<div class="shadow"></div>
<div class="roll-h">
<div id="roll3">
<div class="black">9</div>
<div class="black">0</div>
<div class="black">1</div>
<div class="black">2</div>
<div class="black">3</div>
<div class="black">4</div>
<div class="black">5</div>
<div class="black">6</div>
<div class="black">7</div>
<div class="black">8</div>
<div class="black">9</div>
<div class="black">0</div>
</div>
</div>
</div>
<div class="floatleft">
<div class="shadow"></div>
<div class="roll-h">
<div id="roll4">
<div class="black">9</div>
<div class="black">0</div>
<div class="black">1</div>
<div class="black">2</div>
<div class="black">3</div>
<div class="black">4</div>
<div class="black">5</div>
<div class="black">6</div>
<div class="black">7</div>
<div class="black">8</div>
<div class="black">9</div>
<div class="black">0</div>
</div>
</div>
</div>
</div>
you can center and keep items side by side using inline-block like this
.floatleft {
display: inline-block;
}
I am fairly new to CSS, but I want to know if there's an easier way to order these boxes, as I need something like a treemap, which links to a certain page, as you can see, have some animations. Currently I want to order this third box below the second one, and I don't know how, I'm trying with float and clear, but doesn't work for me. Excuse my beginner knowledge, but I'm learning. Also, if there's an easier way to do this, except manually like I'm doing, let me know please.
.cbox1 {
border:solid 2.5px white;
position:relative;
float:left;
z-index: 10;
}
.cboxtext {
text-align:center;
height:50%;
margin-top: 200px;
color:#fff;
}
.cboxpercentage {
text-align:center;
font-size:80px;
font-weight: bold;
color:#fff;
margin-top: -300px;
}
<a href="#">
<div class="cbox1 hvr-bounce-out" style="width:400px; height:400px;background-color:steelblue;">
<h2 class="cboxtext"> Company 1 </h2>
<h1 class="cboxpercentage"> 62,5% </h1>
</div></a>
<a href="#">
<div id="wrapper">
<div class="cbox1 hvr-sink" style="width:200px; height:200px; background-color:dodgerblue;">
<h2 class="cboxtext" style="font-size:24px; margin-top:90px;"> Company 2 </h2>
<h1 class="cboxpercentage"> 32,5% </h1>
</div></a>
<a href="#">
<div class="cbox1 hvr-float" style="width:200px; height:200px; background-color:blue;">
<h2 class="cboxtext"> Company 3 </h2>
<h1 class="cboxpercentage"> 5% </h1>
</div>
</a>
</div>
It's a new version of your code:
.cbox1,#wrapper {
position: relative;
}
.cbox1 a,#wrapper a {
text-decoration: none;
display: block;
width: 400px;
height: 400px;
}
.cbox1 a span,#wrapper a span {
display: block;
position: absolute;
width: 100%;
line-height: 400px;
}
.cbox1 a span.cboxtext,#wrapper a span.cboxtext {
line-height:30px;
}
.cbox1 {
width: 400px;
height: 400px;
float: left;
}
a .cboxtext {
top: 10px;
text-align:center;
color:#fff;
}
.cboxpercentage {
text-align:center;
font-size:80px;
font-weight: bold;
color:#fff;
}
#wrapper {
float: left;
width: 200px;
}
#wrapper a span {
line-height: 200px;
}
#wrapper .cbox1 {
width: 200px;
height: 200px;
}
#wrapper .cbox1 a {
width: 200px;
height: 200px;
}
#wrapper .cboxpercentage {
font-size:40px;
}
<div class="cbox1 hvr-bounce-out" style="background-color:steelblue;">
<a href="#">
<span class="cboxtext">Company 1</span>
<span class="cboxpercentage"> 62,5% </span>
</a>
</div>
<div id="wrapper">
<div class="cbox1 hvr-sink" style="background-color:dodgerblue;">
<a href="#">
<span class="cboxtext">Company 2</span>
<span class="cboxpercentage">32,5%</span>
</a>
</div>
<div class="cbox1 hvr-float" style="background-color:blue;">
<a href="#">
<span class="cboxtext">Company 3</span>
<span class="cboxpercentage">5%</span>
</a>
</div>
</div>
When i do my web design, meet a problem when i need to do
[LEFT LOGO] then [TITLE(CENTER)] then [RIGHT LOGO]
The problem appear at RIGHT LOGO there, it doesn't align with LEFT LOGO.
The right logo is under the line of TITLE(CENTER)
here is my code sample, thanks:
<div class="navigation">
<div id="left">
<a title="Multimedia" href="#">
<img src="images/logo.png"/>
</a>
</div>
<div id="title">Tutor Program</div>
<div id="right">
<a href="#" title="Inspire and Innovate">
<img src="images/tagline_alt.png"/>
</a>
</div>
css:
.navigation{
height:auto;
background-color:#666;
width:85%;
margin:auto;
min-width:800px;
}
#title{
text-align:center;
margin: auto;
font-family:‘Arial Black’, Gadget, sans-serif;
font-size: 20px;
color: #FFF;
}
#left {
float: left;text-align:left;
margin: auto;
}
#right {
float: right;text-align:right;
margin: auto;
}
a img { border: 0; }
simply move the right container above the left container check below
<div class="navigation">
<div id="right">
<a href="#" title="Inspire and Innovate">
<img src="images/tagline_alt.png"/>
</a>
</div>
<div id="left">
<a title="Multimedia" href="#">
<img src="images/logo.png"/>
</a>
</div>
<div id="title">Tutor Program</div>
</div>
I thing its work an another way i have some changes in style width depends of logo width. if it is not set in center then change the width %.
#title{
text-align:center;
margin: auto;
font-family:'Arial Black', Gadget, sans-serif;
font-size: 20px;
color: #FFF;
width:59%;
float:left;
}
.clear {
clear:both;
margin:0px;
font-size:0px;
}
and add a div after the last div with class clear.
<div id="right"> .... </div>
<div class="clear"> </div>
You could also display your divs as a table and table-cells, like this:
HTML
<div class="navigation">
<div id="left">
left
</div>
<div id="title">
title
</div>
<div id="right">
right
</div>
</div>
CSS
.navigation {
width: 100%;
display: table;
table-layout: fixed;
}
.navigation > div {
display: table-cell;
}
.navigation div:nth-child(1) {
background: lightgray;
}
.navigation div:nth-child(2) {
background: gray;
text-align: center;
}
.navigation div:nth-child(3) {
background: lightgray;
text-align: right;
}
Also check the JSFiddle Demo