I have an issue with the child divs not appearing side by side. There are two divs which appear at the bottom of the first div.
I have tried display:inline-block - but to no avail.
div.bodyClass {
background-color: D4BD6A;
height: 850px;
}
div.navClassItems {
text-align: center;
display: inline-block;
width: 250px:
}
div.secClass1 {
background-color: F9E18D;
display: inline-block;
}
div.secClass2 {
background-color: F9E18D;
display: inline-block;
}
<div id="mainbodyWithNav" class="bodyClass">
<div class="navClassItems">
<hr>Main Page
<br>
<hr>Metrics
<br>
<hr>Contact us
<br>
<hr>
</div>
<div class="secClass1">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
<div class="secClass2">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
</div>
you need to apply display:inline-block and set a (max)-width to all the children
.bodyClass {
background-color: #D4BD6A;
height: 850px;
font-size:0 /* inline-block gap fix */
}
.bodyClass > div{
text-align: center;
display: inline-block;
vertical-align:top;
max-width: 250px;
font-size:16px /* reset font-size */
}
[class*="sec"] {
background-color: #F9E18D;
}
<div id="mainbodyWithNav" class="bodyClass">
<div class="navClassItems">
<hr>Main Page
<br>
<hr>Metrics
<br>
<hr>Contact us
<br>
<hr>
</div>
<div class="secClass1">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
<div class="secClass2">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
</div>
Try this...
div.secClass1
{
background-color:F9E18D;
width:50%;
float:left;
}
div.secClass2
{
background-color:F9E18D;
width:50%;
float:left;
}
and put an <hr /> just before the secClass1 div so that it separates it from the menu above.
Use "Float:left" and set their width both to 50% (Or width of container divided by 2):
//below is container class
container{
width: 100%;
}
div.secClass1
{
float: left;
width: 50%;
background-color:F9E18D;
display:inline-block;
}
div.secClass2
{
float: left;
width: 50%;
background-color:F9E18D;
display:inline-block;
}
One option would be to set width to calc(50% - 125px) and float them left. See fiddle: https://jsfiddle.net/DIRTY_SMITH/7oe5kh9L/39/
div.secClass1
{
width: calc(50% - 125px);
float: left;
background-color:#F9E18D;
}
div.secClass2
{
width: calc(50% - 125px);
float: left;
background-color:#F9E18D;
}
try using "float: left;" instead
Related
Trying to align my website! But when the screen is half screen, both left and right elements get merged.
I want them to be one below the other with the left element first and the right element 2nd.
#media only screen and (max-width:400px) {
.about-right,
.about-left {
float:none;
width:100%;
padding-left: 25px;
padding-right: 25px;
}
Full screen
Half screen
The half screen is the default mobile view as well. Please help.
Code for my full screen:
`#media only screen and (max-width:1024px) {
.about-profile {
padding-right: 5rem;
}
.about-services {
padding-left: 5rem;
}
#media only screen and (max-width:900px) {
.about-profile {
padding-right: 4rem;
}
.about-services {
padding-left: 4rem;
}
After the 1st answer by #fevid
After edit
HTML Code:
<section id="about">
<div class="about-profile-bg"></div>
<div class="about-wrap">
<div class="about-profile">
<div class="about-profile-bg"></div>
<div class="about-services"> </div>
The profile = right and services = left.
I've used CSS in using and styling the left and right side.
.about-profile{
float: right;
width: 50%;
padding-left: 20px;
padding-right: 20px;
}
.about-services {
float:left;
width: 50%;
padding-left: 20px;
padding-right: 20px;
}
.about-services-bg {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image: url(../images/profile-bg.jpg);
background-color: #615e5e;
background-repeat: no-repeat;
background-position: center;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
opacity: 1;
.about-profile-bg {
position:absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background:#aaa7a3;
width: 50%;
background-image: url(../images/service-bg.jpeg);
background-repeat: no-repeat;
background-position: center;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
opacity: .80;
}
don't use float, use flex instead, in smaller screen change flex-direction to column.
presuming your parent container has .about class:
#media only screen and (min-width:401px) {
.about {
display: flex;
justify-content: space-between;
}
}
#media only screen and (max-width:400px) {
.about {
display: flex;
flex-direction: column:
}
}
It depends on what you want the page to look like if the text is longer than the image.
If you want it to wrap under the img if it is longer then it is correct to use float: left on the img (that's what float was designed for) but remove the div float: right on the text. Then as the viewport goes below your limit, setting width 100% will ensure the img is above the text. See this snippet:
body {
font-size: 30px; /* just to demo the wrapping round */
}
.about-right,
.about-left {
width: 45%;
}
.about-right {
float: right;
}
.about-left {
float: left;
margin-right: 10px;
}
#media (max-width:400px) {
.about-right,
.about-left {
rfloat:none;
rclear: both;
width:100%;
padding-left: 25px;
padding-right: 25px;
}
}
<img src="https://picsum.photos/id/1015/200/300" class="about-left">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
<br> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
<br> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
<br> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
<br> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</body>
If you want the text to remain on the right then you can use the structure you already have. Increasing the widths to 100% on narrower viewports will force the text div below the image. See this snippet:
body {
font-size: 30px; /* just to demo the wrapping round */
}
.about-right,
.about-left {
width: 45%;
}
.about-right {
float: right;
}
.about-left {
float: left;
margin-right: 10px;
}
#media (max-width:400px) {
.about-right,
.about-left {
width:100%;
padding-left: 25px;
padding-right: 25px;
}
}
<img src="https://picsum.photos/id/1015/200/300" class="about-left">
<div class="about-right">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
<br> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
<br> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
<br> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
<br> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
Make sure you have the closing bracket on the media statement.
However, you may like to investigate other methods, particularly grid and flex, as float is really just for the first example here, when you want the text to float around the img.
I have a CSS grid layout as follows here: https://codepen.io/anon/pen/KogEaq
body {
overflow: hidden;
padding: 0;
margin: 0;
background-color: #222525;
color: white;
}
#container {
display: grid;
grid-template-columns: 27fr 78fr;
max-height: 100vh;
}
#left {
grid-row: 1;
grid-column: 1;
}
#right {
grid-row: 1;
grid-column: 2;
max-height: 100%;
}
.box {
margin: 8px;
padding: 8px;
border-radius: 10px;
border: blue solid 2px;
overflow-y: auto;
max-height: 100%;
}
<div id="container">
<div id="left">
<div class="box">
Navigation sidebar stuff here
</div>
</div>
<div id="right">
<div class="box">
Page content
</div>
</div>
</div>
The page is intended to be a single page app and the body should not scroll. When the page content becomes large, I wish for the contents in the .box class to scroll.
The problem is, the .box and the parent #right column within the #container grid seem to exceed the max-height set by the container of 100vh, therefore the overflow property of the .box is not triggered and the content is cut short.
Edit:
If I wasn't clear before, the problem is that the .box and the #right elements do not respect the max-height attribute of the parent #container which is causing the scroll issues.
The problem isn't really the max-height. It's the top and bottom margins on your .box element (margin: 8px). When added to the max-height: 100vh, it results in an overflow of the wrong container. If you remove those margins, and add box-sizing: border-box (to factor in borders and padding), your page and the overflow work as intended.
body {
margin: 0;
background-color: #222525;
color: white;
}
#container {
display: grid;
grid-template-columns: 27fr 78fr;
}
#left {
grid-row: 1;
grid-column: 1
}
#right {
grid-row: 1;
grid-column: 2;
}
.box {
/* margin: 8px; */
padding: 8px;
border-radius: 10px;
border: aqua solid 5px;
max-height: 100vh;
overflow: auto;
}
li {
margin: 10px;
}
* { box-sizing: border-box; }
<div id="container">
<div id="left">
<div class="box">Navigation sidebar stuff here</div>
</div>
<div id="right">
<div class="box">
<ul>
<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</li>
<li>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</li>
<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</li>
<li>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</li>
<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</li>
<li>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</li>
</ul>
</div>
</div>
</div>
As a solution, try padding: 8px on the parent elements (#right and #left) instead.
I'm having some trouble trying to align a button with the right side of a responsive div (I'm trying to make all my html responsive).
What I am achieving right now is this current example:
.container1 {
background-color: yellowgreen;
position: relative;
width: 100%;
height: 400px;
}
.container1-text1 {
position: absolute;
top: 50%;
left: 50%;
width: 40%;
-webkit-transform: translate(-105%, -50%);
-ms-transform: translate(-105%, -50%);
transform: translate(-105%, -50%);
background-color: orange;
padding: 1.2em;
}
.container1-text2 {
position: absolute;
top: 50%;
left: 50%;
width: 40%;
-webkit-transform: translate(5%, -50%);
-ms-transform: translate(5%, -50%);
transform: translate(5%, -50%);
background-color: fuchsia;
padding: 1.2em;
}
.custom-button-style {
float: right;
color: white;
padding: 10px 32px;
background-color: #D0D763;
border-radius: 8px;
cursor: pointer;
}
<div class="container1">
<div class="container1-text1">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing
elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</p>
</div>
<div class="container1-text2">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing
elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</p>
</div>
<a href="" target="_blank">
<div class="custom-button-style">BUTTON TEXT</div>
</a>
</div>
Fiddle of current example: http://jsfiddle.net/6zstozwf/
But what I would like to achieve is this:
To keep it short, I thought on wrapping both the button and the second "pink/fuchsia" div on a wrapper-div, but I didn't have success on it.
The main problem is, that you have your elements positioned absolute. That will break your layout especially on small devices.
There are a few solutions out there. This one down below is made with display: flex mainly. See comments in code for explanation.
*, *::before, *::after {
/* changing calculation of box model for all elements */
box-sizing: border-box;
}
body {
/* I guess your whole page should be green anyway.
Otherwise you can put this back to .container1 */
background-color: yellowgreen;
}
.container1 {
/* making the container kind of "flexible" */
display: flex;
/* spread elements from across width but leave a gap between them */
justify-content: space-between;
/* vertically align elements to the top */
align-items: flex-start;
/* when elements reach over a 100% wrap them to the next line */
flex-wrap: wrap;
/* vw means viewport width - similar to % */
padding: 5vw;
}
/* combine styles for both text elements */
.container1-text1, .container1-text2 {
width: 40vw;
padding: 1.2em;
}
.container1-text1 {
background-color: orange;
}
.container1-text2 {
background-color: fuchsia;
}
.button-container {
/* just an element spread to 100% width
all inline elements should be aligned to the right */
width: 100%;
text-align: right;
padding-top: 5vw;
}
.custom-button-style {
display: inline-block;
color: white;
padding: 10px 32px;
background-color: #D0D763;
border-radius: 8px;
}
<div class="container1">
<div class="container1-text1">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing
elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</p>
</div>
<div class="container1-text2">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing
elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</p>
</div>
<div class="button-container">
<a href="" target="_blank" class="custom-button-style">
BUTTON TEXT
</a>
</div>
</div>
You're having trouble because of your absolute positioning and your float. Both cause more trouble than they're worth. Look at inline-block and leave positioning static, then your anchor can flow below them as normal and be aligned right with text-align.
* {
box-sizing: border-box;
}
.container {
background-color: yellowgreen;
margin-bottom: 20px;
text-align: center;
}
.container > div {
display: inline-block;
width: 40%;
margin: 4.5%;
background-color: orange;
padding: 1.2em;
}
* {
box-sizing: border-box;
}
.container {
background-color: yellowgreen;
margin-bottom: 20px;
text-align: center;
}
.container > div {
display: inline-block;
width: 40%;
margin: 4.5%;
background-color: orange;
padding: 1.2em;
}
.container > div.text2 {
background-color: fuchsia;
}
.custom-button-style {
color: white;
padding: 10px 32px;
background-color: #D0D763;
border-radius: 8px;
cursor: pointer;
}
.text-right {
text-align: right;
}
.custom-button-style {
color: white;
padding: 10px 32px;
background-color: #D0D763;
border-radius: 8px;
cursor: pointer;
}
.text-right {
text-align: right;
}
<div class="container">
<div class="text1">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing
elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</p>
</div>
<div class="text2">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing
elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</p>
</div>
</div>
<div class="text-right">
<a href="" target="_blank">
<span class="custom-button-style">BUTTON TEXT</span>
</a>
</div>
Fiddle
When flex-basis:auto is set on a div, the div expands vertically to fit contents.
Example
Html:
<div class="parent">
<div class="image">
<img src="http://placebacon.net/400/103">
</div>
<div class="text">
-- Removed for readability --
</div>
</div>
scss:
.parent {
position:absolute;
top:0px;
left:0px;
right:0px;
bottom:0px;
display:flex;
flex-direction:column;
.image {
flex-basis:auto;
flex-grow:0;
flex-shrink:0;
img {
width:100%;
height:auto;
}
}
.text {
flex-basis:0px;
flex-grow:1;
flex-shrink:1;
overflow-y:scroll;
}
}
However this does not work horizontally :
Example 2
.parent {
position:absolute;
top:0px;
left:0px;
right:0px;
bottom:0px;
display:flex;
flex-direction:row;
.image {
flex-basis:auto;
flex-grow:0;
flex-shrink:0;
img {
height:100%;
width:auto;
}
}
.text {
flex-basis:0px;
flex-grow:1;
flex-shrink:1;
overflow-y:scroll;
}
}
If you resize the height of the parent, the image will change size to preserve aspect ratio. However the flex box retains the size of the image before the transformation.
Is there a CSS property I need to set to get the expected behavior?
Seems like you need to set an height in .parent, .image and finally to img to trigger the calculation for each elements : https://jsfiddle.net/knjesznx/4/
You should not mind the flex value unless you have really litlle content aside and a background to show , then just add flex:1 to the container that is suppose to fill all space left demo
.parent {
position: absolute;
top: 0px;
left: 0px;
right: 0px;
bottom: 0px;
height: 100vh;/* here */
display: flex;
flex-direction: row;
}
.parent .image {
height: 100%;/* here */
}
.parent .image img {
height: 100%;/* here */
width: auto;
}
.parent .text {
overflow-y: scroll;
/* eventually use flex:1; to fill all space left*/
}
<div class="parent">
<div class="image">
<img src="http://placebacon.net/103/400">
</div>
<div class="text">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
</div>
I would remove the and set the image as the background of the image container. The css would look like:
.image {
flex-basis:auto;
flex-grow:0;
flex-shrink:0;
height: 100%;
width: 150px;
background-image: url('http://placebacon.net/103/400');
background-size: cover;
}
Hi i currently have two colums one left and one right with the left column having two rows in it
however i want the centre point of the column offset to the right so the left column would be about 60% and the right would be 40%
Here is the html and css i am using
#import url(http://fonts.googleapis.com/css?family=Lora:700);
.container {
width: 75%;
margin: auto;
}
.titleheader {
text-align: center;
margin-top: 5px;
font-size: 70px;
font-family: 'Lora', serif;
border-bottom: 3px solid #000;
width: 56%;
margin: auto;
}
.midcontainer {
-webkit-column-count: 2;
-moz-column-count: 2;
column-count: 2;
margin-top: 20px;
}
.top {
margin-bottom: 15px;
}
.bottom {} .rightsection {} .leftsection {
display: inline-block;
}
.memo {}
<div class="container">
<div class="titleheader">
<?php echo $this->Accountname; ?></div>
<div class="midcontainer">
<div class="leftsection">
<div class="top">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
<div class="bottom">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
</div>
<div class="rightsection">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
</div>
<div class="memo"></div>
</div>
As much as I love them, you cannot set the widths of CSS columns independently. However, you can get the layout you're looking for by using CSS tables:
.midcontainer {
display:table;
border-spacing: 50px;
border-collapse: separate;
}
.leftsection, .rightsection{
display:table-cell;
}
.rightsection {
width:40%
}
#import url(http://fonts.googleapis.com/css?family=Lora:700);
.container{
width: 75%;
margin: auto;
border:1px dotted #ccc;
}
.titleheader{
text-align: center;
margin-top: 5px;
font-size: 70px;
font-family: 'Lora', serif;
border-bottom: 3px solid #000;
width: 56%;
margin: auto;
}
.midcontainer {
display:table;
border-spacing: 50px;
border-collapse: separate;
}
.leftsection, .rightsection{
display:table-cell;
}
.rightsection {
width:40%
}
.top{
margin-bottom: 15px;
}
.bottom{
}
.memo{
}
<div class="container">
<div class="titleheader">Invalid Account Number</div>
<div class="midcontainer">
<div class="leftsection">
<div class="top">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
<div class="bottom">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
</div>
<div class="rightsection">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
</div>
<div class="memo"></div>