Aligning multiple divs with “align-items” but one fail [duplicate] - css

This question already has answers here:
In CSS Flexbox, why are there no "justify-items" and "justify-self" properties?
(6 answers)
What's the difference between align-content and align-items?
(15 answers)
Closed 1 year ago.
I am desperate to know why the div that works under the flex container doesn't follow "align-items:flex-end"? (Altho the result now is what I want, but I just want to understand the logic behind it)
The below picture shows the result. which <h2> section doesn't go to the cross end, but <div2> does.
enter image description here
following the HTML and CSS code
body,html{
padding: 0;
margin: 0;
height: 100%;
}
body{
background-color: #3F5D45;
display:flex;
align-items:center;
justify-content:center;
}
.all{
width: 90%;
}
.top{
height: 60px;
background-color: #EAF0ED;
padding: 0 30px;
border-radius: 5px 5px 0 0;
color: #3F5D45;
font-weight: bold;
display:flex;
justify-content:space-between;
}
.div1{
background-color: #fff;
padding: 30px 50px;
display:flex;
flex:1;
}
.div1 .con{
padding-left:50px;
display:flex;
flex-direction:column;
justify-content:space-between;
align-items:flex-end;
flex:1 1 66.6%;
}
.div2 i{
font-size: 20px;
color: #3F5D45;
padding: 0 3px;
}
.div1 .pic{
height: 350px;
width: 350px;
background-image: url('https://images.unsplash.com/photo-1462745294598-b3f9a2d7b858?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=334&q=80');
background-size: cover;
flex:1 1 33.3%;
}
<div class="all">
<div class="top">
<img src="https://pei-qun.github.io/Sweetaste/img/flex-ex-img3.svg" height="55" alt="">
<p>more</p>
</div>
<div class="div1">
<div class="pic"></div>
<div class="con">
<article>
<h2>Lorem ipsum dolor sit amet</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque imperdiet eu odio et vestibulum. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Mauris sollicitudin sem justo, non pulvinar nunc vehicula in. Nullam non mollis dolor, in luctus est. Phasellus dictum erat ut fermentum consequat.</p></article>
<div class="div2">
<i class="fa fa-share-square-o"></i>
<i class="fa fa-heart-o"></i>
<i class="fa fa-facebook-square" ></i>
</div>
</div>
</div>
If anyone knows why is the reason this happened, please let me know!
It will be much appreciated! Thank you!

Related

Two divs side by side, without container

I have to inline two divs side by side. The thing is, I can't edit HTML and they don't have a container. To make things even more complicated, the first div needs to be wider than the second one. And I have no idea how to do this and make it responsive.
This is what I have so far. But it's not responsive. To make it so, I'd have to edit it with #media and I'm really trying to avoid that. Is there a way I could make this cleaner? A way I could use flex maybe, without a container? And make it responsive too, without having it meshed together on smaller devices?
.one,
.two {
float: left;
}
.one {
width: 66.66%;
}
.two {
width: 33.33%;
}
<div class="one">content goes here</div>
<div class="two">content goes here</div>
EDIT: This is what the outline of my code looks like, with a container. Just to get you guys more information about the issue. Div with a class section-one has 5 items inside, and they need to stay inlined and responsive when the window is resized, so I don't want to mess up the code I currently have because it behaves well on smaller screens.
.container {}
.heading {
text-align: center;
margin-bottom: 35px;
}
.section-one {
text-transform: uppercase;
display: flex;
flex-wrap: wrap;
text-align: center;
justify-content: space-between;
}
.item {
position: relative;
flex-shrink: 0;
margin: 0 auto;
margin-bottom: 15px;
}
.section-left {
float: left;
text-transform: uppercase;
width: 66.66%;
margin-top: 80px;
padding-right: 80px;
}
.section-right {
float: left;
width: 33.33%;
}
<div class="container">
<div class="heading">
<h2>Lorem ipsum dolor</h2>
<p>Morbi posuere mi condimentum dui suscipit vulputate. Donec lectus diam.</p>
</div>
<!--- /.heading -->
<div class="section-one">
<div class="item">Praesent eu elementum.</div>
<div class="item">Praesent eu elementum.</div>
<div class="item">Praesent eu elementum.</div>
<div class="item">Praesent eu elementum.</div>
<div class="item">Praesent eu elementum.</div>
</div>
<!--- /.section-one -->
<div class="section-left">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum eu sodales est. Nullam cursus id nibh mattis porta. Cras aliquet eros urna, quis imperdiet tortor placerat sed.
</div>
<!--- /.section-left -->
<div class="section-right">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum eu sodales est. Nullam cursus id nibh mattis porta. Cras aliquet eros urna, quis imperdiet tortor placerat sed.
</div>
<!--- /.section-right -->
</div>
You could use CSS calc() function along-with display:inline-block instead of float to align both divs responsively without making use of media query.
But as both divs are display as inline-block and when using inline-block it adds white-space around it's block, to remove that I have used font-size:0 in body tag, so on remaining block in your design you have to assign font-size manually or else text won't be visible.
body{
font-size:0;
margin:0;
}
.one{
display:inline-block;
background:pink;
width:calc(100vw - 40vw);
font-size:16px;
}
.two{
display:inline-block;
background:pink;
width:calc(100vw - 60vw);
font-size:16px;
}
<div class="cont">
<div class="one">content goes here</div>
<div class="two">content goes here</div>
</div>
Given the fact you already use Flexbox, I suggest you do it for this too, like this.
If you don't want the container, just drop its markup and move its CSS properties to the body
Fiddle demo
Stack snippet
.container {
display: flex; /* added */
flex-wrap: wrap; /* added */
}
.heading {
flex: 0 0 100%; /* added, behaves like a block */
text-align: center;
margin-bottom: 35px;
}
.section-one {
flex: 0 0 100%; /* added, behaves like a block */
text-transform: uppercase;
display: flex;
flex-wrap: wrap;
text-align: center;
justify-content: space-between;
}
.item {
position: relative;
flex-shrink: 0;
margin: 0 auto;
margin-bottom: 15px;
}
.section-left {
flex: 1 0 66.666%; /* added, behaves like an inline-block but fill when on single line */
min-width: 400px;
text-transform: uppercase;
margin-top: 80px;
padding-right: 80px;
box-sizing: border-box; /* added, make padding be included in set width */
border: 1px dotted gray; /* demo purpose */
}
.section-right {
flex: 1 0 33.333%; /* added, behaves like an inline-block but fill when on single line */
min-width: 200px;
box-sizing: border-box; /* added, make border be included in set width */
border: 1px dotted gray; /* demo purpose */
}
<div class="container">
<div class="heading">
<h2>Lorem ipsum dolor</h2>
<p>Morbi posuere mi condimentum dui suscipit vulputate. Donec lectus diam.</p>
</div>
<!--- /.heading -->
<div class="section-one">
<div class="item">Praesent eu elementum.</div>
<div class="item">Praesent eu elementum.</div>
<div class="item">Praesent eu elementum.</div>
<div class="item">Praesent eu elementum.</div>
<div class="item">Praesent eu elementum.</div>
</div>
<!--- /.section-one -->
<div class="section-left">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum eu sodales est. Nullam cursus id nibh mattis porta. Cras aliquet eros urna, quis imperdiet tortor placerat sed.
</div>
<!--- /.section-left -->
<div class="section-right">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum eu sodales est. Nullam cursus id nibh mattis porta. Cras aliquet eros urna, quis imperdiet tortor placerat sed.
</div>
<!--- /.section-right -->
</div>
I suggest you to use a media query anyway to make your divs on top of each other on small devices, especially if you have text content. The max-width I'm giving to you is just an example
#media screen and (max-width: 480px) {
.one,
.two {
float: none;
width: 100%;
}
}
I would gladly suggest you the flex-box property, but if you don't got a container and can't modify the HTML, this will be complicated.
Here's the link anyway : https://css-tricks.com/snippets/css/a-guide-to-flexbox/
With flexbox, you just have to give the property to your container :
.container {
display: flex;
}
Then you can choose the way you want to sort your elements :
.container {
flex-direction: row;
}
Again this is an example, check the link i gave you for further informations.
You need to reset box-sizing to include padding and border into width calculation.
The CSS box-sizing property is used to alter the default CSS box model used to calculate width and height of the elements.
A media query will help to pile them when boxes become too small.
Media queries are useful when you want to apply CSS styles depending on a device's general type (such as print vs. screen), specific characteristics (such as the width of the browser viewport), or environment (such as ambient light conditions). With the huge variety of internet-connected devices available today, media queries are a vital tool for building websites and apps that are robust enough to work on whatever hardware your users have.
example
.container {}
.heading {
text-align: center;
margin-bottom: 35px;
}
.section-one {
text-transform: uppercase;
display: flex;
flex-wrap: wrap;
text-align: center;
justify-content: space-between;
}
.item {
position: relative;
flex-shrink: 0;
margin: 0 auto;
margin-bottom: 15px;
}
.section-left {
float: left;
text-transform: uppercase;
width: 66.66%;
/*margin-top: 80px; remove */
padding-right: 80px;
}
.section-right {
float: left;
width: 33.33%;
}
/* updates */
.section-left,
.section-right {
box-sizing:border-box;
}
#media all and (max-width : 599px) {
.section-left,
.section-right {
width:100%;
padding:1em;
}
}
/* let's see them */
div {
box-shadow:0 0 0 2px green;
}
<div class="container">
<div class="heading">
<h2>Lorem ipsum dolor</h2>
<p>Morbi posuere mi condimentum dui suscipit vulputate. Donec lectus diam.</p>
</div>
<!--- /.heading -->
<div class="section-one">
<div class="item">Praesent eu elementum.</div>
<div class="item">Praesent eu elementum.</div>
<div class="item">Praesent eu elementum.</div>
<div class="item">Praesent eu elementum.</div>
<div class="item">Praesent eu elementum.</div>
</div>
<!--- /.section-one -->
<div class="section-left">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum eu sodales est. Nullam cursus id nibh mattis porta. Cras aliquet eros urna, quis imperdiet tortor placerat sed.
</div>
<!--- /.section-left -->
<div class="section-right">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum eu sodales est. Nullam cursus id nibh mattis porta. Cras aliquet eros urna, quis imperdiet tortor placerat sed.
</div>
<!--- /.section-right -->
</div>

CSS print page-break-after not working with CSS Grid layout

I'm using the new CSS3 layout technique defined by gridbyexample.com.
It's works very well except when I try to print the layout. Chrome and Firefox seem to be ignoring any page breaks and the landscape view mode I have defined in the CSS. I have a code pen for my project but it seems to change how it looks in print preview mode so it's only good for looking at HTML and CSS but not how the print will look.
https://codepen.io/JeffreySpring/pen/rzjeKm
I have created a .zip file with all the files and images that can be downloaded from https://drive.google.com/open?id=0B0LdH-fKpAKeY0NRa290M25uTGc
Here is the HTML
<!DOCTYPE html>
<html>
<head>
<title>Steam Controller Bindings Template</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body cz-shortcut-listen="true" style="">
<ul class="wrapper">
<li class="device">
<div id="steamDeviceContainer">
<div><h1>Couch Gamer's Witcher 3 Bindings</h1></div>
<img src="img/steam_controller.png" alt="Steam Controller">
</div>
<div class="mappingGyroShift1">
<h3 class="mappingHeader gyroShift1">Gyro<span class="boundTo gyroShift1">(Mouse Joystick)</span></h3>
<div class="actionBind gyroShift1">Precision Crossbow/Bomb Aim</div>
</div>
</li>
<li>
<div class="mapping">
<h3 class="mappingHeader">Left Trigger</h3>
<div class="actionBind">Use Witcher Senses</div>
<div class="actionBind">Block or Counterattack</div>
</div>
<div class="mapping">
<h3 class="mappingHeader">Left Bumper</h3>
<div class="actionBind">Quick choice menu</div>
</div>
<div class="mapping">
<h3 class="mappingHeader">Select Button</h3>
<div class="actionBind">Pause Game/Game Options</div>
<div class="actionBind">HOLD: Inventory Screen</div>
</div>
<div class="mapping">
<h3 class="mappingHeader">Left Grip</h3>
<div class="actionBind">Use Item</div>
<div class="actionBind gyroShift1">HOLD: (GYRO ON) Aim Crossbow/Bomb</div>
</div>
</li>
<li>
<div class="mapping">
<h3 class="mappingHeader">Right Trigger</h3>
<div class="actionBind">Use Sign</div>
</div>
<div class="mapping">
<h3 class="mappingHeader">Right Bumper</h3>
<div class="actionBind">Quick Save</div>
</div>
<div class="mapping">
<h3 class="mappingHeader">Start Button</h3>
<div class="actionBind">In Game Menu</div>
<div class="actionBind">HOLD: Map</div>
</div>
<div class="mapping">
<h3 class="mappingHeader">Right Grip</h3>
<div class="actionBind modeShift1">Mode Shift Left TouchPad</div>
<div class="actionBind modeShift1">Mode Shift A Button</div>
</div>
</li>
<li class="wide">
<div class="mapping pageBreakAfter">
<h3 class="mappingHeader">Left Joystick<span class="boundTo">(Joystick Move)</span></h3>
<div class="actionBind">ROTATE: Move Character</div>
<div class="actionBind">DOUBLE PRESS: Call your mount</div>
</div>
</li>
<li class="wide">
<div class="mapping pageBreakAfter">
<h3 class="mappingHeader">Face Buttons<span class="boundTo">(Button Pad)</span></h3>
<div class="actionBind aBtn">A BUTTON: Interact/Roll</div>
<div class="actionBind aBtn">A BUTTON HOLD: Run/Quick Swim/Gallop/Accelerate Boat</div>
<div class="actionBind aBtn">A BUTTON QUICK DOUBLE PRESS THEN HOLD: Full Gallop</div>
<div class="actionBind bBtn">B BUTTON: Jump/Dodge/Let helm go</div>
<div class="actionBind bBtn">B BUTTON HOLD: Resurfacing</div>
<div class="actionBind yBtn">Y BUTTON: Strong attack</div>
<div class="actionBind xBtn">X BUTTON: Fast Attack</div>
<div class="actionBind xBtn">X BUTTON HOLD: Submerging/Stop the Boat</div>
<div class="actionBind modeShift1">A BUTTON: Autoloot</div>
</div>
</li>
<li class="wide">
<div class="mapping">
<h3 class="mappingHeader">Left TouchPad<span class="boundTo">(4 way D-Pad)</span></h3>
<div class="actionBind">D-PAD UP: Consumable 1/3</div>
<div class="actionBind">D-PAD UP HOLD: Switch to Consumable 1/3</div>
<div class="actionBind">D-PAD DOWN: Consumable 2/4</div>
<div class="actionBind">D-PAD UP HOLD: Switch to Consumable 2/4</div>
<div class="actionBind">D-PAD LEFT: Drawing or hiding steel sword</div>
<div class="actionBind">D-PAD LEFT: Drawing or hiding silver sword</div>
<div class="actionBind modeShift1">MODE SHIFT RIGHT GRIP: Radial Menu 1</div>
</div>
</li>
<li class="wide">
<div class="mapping">
<h3 class="mappingHeader">Right TouchPad<span class="boundTo">(4 way D-Pad)</span></h3>
<div class="actionBind">D-PAD UP: Consumable 1/3</div>
<div class="actionBind">D-PAD UP HOLD: Switch to Consumable 1/3</div>
<div class="actionBind">D-PAD DOWN: Consumable 2/4</div>
<div class="actionBind">D-PAD UP HOLD: Switch to Consumable 2/4</div>
<div class="actionBind">D-PAD LEFT: Drawing or hiding steel sword</div>
<div class="actionBind">D-PAD LEFT: Drawing or hiding silver sword</div>
</div>
</li>
<li class="full">
<div class="mappingModeShift1">
<h3 class="mappingHeader modeShift1">Radial Menu 1<span
class="boundTo modeShift1">(6 button touch menu)</span></h3>
<div class="actionBind modeShift1">BUTTON 1: Aard</div>
<div class="actionBind modeShift1">BUTTON 2: Yrden</div>
<div class="actionBind modeShift1">BUTTON 3: Igni</div>
<div class="actionBind modeShift1">BUTTON 4: Quen</div>
<div class="actionBind modeShift1">BUTTON 5: Axii</div>
<div class="actionBind modeShift1">BUTTON 6: Swap Crossbow/Bomb</div>
</div>
</li>
<li class="full">
<div class="mapping">
<h3 class="mappingHeader">Details</h3>
<div class="notes">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis efficitur arcu ut sapien ullamcorper,
vel ornare tellus venenatis. Pellentesque non sapien magna. Suspendisse potenti. Duis et turpis
sapien.
Donec turpis odio, posuere dignissim ornare semper, commodo a nunc. Nunc lacinia felis id elementum
vehicula.
Curabitur vel risus luctus, ornare nulla ac, tincidunt tellus. Nam tortor lorem, aliquet ut
efficitur vel,
</p>
<p>
ullamcorper vel metus. Orci varius natoque penatibus et magnis dis parturient montes, nascetur
ridiculus mus.
Nam v
itae odio arcu. Phasellus fermentum nisi ipsum, a viverra urna placerat dignissim. Ut tempus finibus
mauris
faucibus consequat. Proin eu risus interdum, malesuada lectus id, egestas tortor. In imperdiet eget
augue et semper.
Sed risus justo, pulvinar id velit et, ullamcorper posuere ex. Nulla vel laoreet purus. Vivamus sed
venenatis erat,
in aliquam lectus. Mauris et lectus id eros feugiat viverra eu eu massa.
</p>
<p>
Nam egestas malesuada ligula quis cursus. Duis quis lorem in nunc maximus malesuada. Cras ante enim,
tincidunt ac
risus vel, elementum tincidunt erat. Ut auctor dolor a metus ornare auctor. Pellentesque at tellus
mi. Morbi e
fficitur metus vel enim ullamcorper, quis sagittis eros condimentum. Phasellus laoreet consectetur
lectus et dapibus.
Morbi tincidunt id mi nec ullamcorper. Integer dictum, justo vitae ullamcorper tristique, lorem nunc
rutrum augue, ut
pellentesque diam purus at ex. Proin sollicitudin iaculis eros.
</p>
</div>
</div>
</li>
<li class="full noPrint">
<div class="mapping">
<h3 class="mappingHeader">Screenshots</h3>
<div class="notes">
<div>
<img src="img/customRadialMenu.png" alt="Custom Menu Screenshot">
</div>
</div>
</div>
</li>
<li class="full noPrint">
<div id="videoWrapper">
<div class="video-container">
<iframe width="560" height="315" src="https://www.youtube.com/embed/4lcm4bdtkZs" frameborder="0"
allowfullscreen></iframe>
</div>
</div>
</li>
</ul>
</body>
</html>
Here is the CSS
/*noinspection CssUnknownTarget*/
#import url('https://fonts.googleapis.com/css?family=Oswald');
html {
box-sizing: border-box;
font-family: 'Oswald', sans-serif;
}
*, *:before, *:after {
box-sizing: inherit;
background-color: #00335B;
color: #F9F3F4;
}
img {
max-width: 100%;
}
.wrapper {
list-style: none;
margin: 0 auto 0 auto;
padding: 0;
display: grid;
grid-template-columns: 1fr;
grid-template-rows: auto;
grid-auto-flow: dense;
}
#media print {
.noPrint {
display: none !important;
}
#page {
size: landscape; /* auto is the initial value */
/* this affects the margin in the printer settings */
margin: 25px 25px 25px 25px;
}
div.pageBreakAfter {
page-break-after: always;
page-break-inside: avoid;
}
div.pageBreakBefore {
page-break-before: always;
page-break-inside: avoid;
}
}
#media (min-width: 460px) {
.wrapper {
grid-template-columns: 1fr 1fr;
}
.device {
grid-column: 1 / 3;
}
.full {
grid-column: auto / span 2;
}
}
#media (min-width: 660px) {
.wrapper {
grid-template-columns: 1fr 1fr 1fr 1fr;
}
.device {
grid-column: 2 / 4;
grid-row: 1 / 3;
}
.wide {
grid-column: auto / span 2;
}
.full {
grid-column: auto / span 4;
}
}
.wrapper li {
margin: 10px;
padding: 10px;
}
h1 {
font-family: 'Oswald', sans-serif;
color: #F9F3F4;
text-shadow: 0 0 300px #000;
font-size: 150%;
text-align: center;
}
.mapping {
border: solid #F9F3F4 3px;
border-radius: 9px;
font-family: 'Oswald', sans-serif;
color: #F9F3F4;
margin: 20px;
}
.mappingModeShift1 {
border: solid #FF8C00 3px;
border-radius: 9px;
font-family: 'Oswald', sans-serif;
color: #FF8C00;
margin: 20px;
}
.mappingGyroShift1 {
border: solid #00FFFF 3px;
border-radius: 9px;
font-family: 'Oswald', sans-serif;
color: #00FFFF;
margin: 20px;
}
.mappingHeader {
padding-left: 3px;
padding-right: 3px;
font-family: 'Oswald', sans-serif;
font-style: normal;
position: relative;
left: 30px;
top: -10px;
text-transform: uppercase;
display: inline;
}
#steamDeviceContainer {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
#videoWrapper {
margin-left: 15px;
margin-right: 15px;
}
.video-container {
position: relative;
padding-bottom: 56.25%;
padding-top: 30px;
height: 0;
overflow: hidden;
}
.video-container iframe, .video-container object, .video-container embed {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.actionBind {
margin-left: 30px;
margin-right: 10px;
padding-bottom: 10px;
}
.notes {
margin-left: 30px;
margin-right: 30px;
margin-bottom: 30px;
padding-bottom: 10px;
}
.boundTo {
font-size: xx-small;
vertical-align: super;
padding: 2px;
}
.modeShift1 {
color: #FF8C00 !important;
}
.gyroShift1 {
color: #00FFFF !important;
}
.yBtn {
color: #F4D00F;
}
.xBtn {
color: #0084C4;
}
.aBtn {
color: #34A853;
}
.bBtn {
color: #fc0602;
}
As you have found page pages do not work inside of grid layout block. I tried everything I could think of, but just doesn't work.
The solution to my report was to do the page-break-before outside the grid layout block.
It makes it a little trick, but it can be done. You just have to make sure your page-break is outside any display: grid class.

Simple 2 columns layout

I would like to have a webpage with two columns. The first for buttons, and the second for content.
Here's a JsFiddle :
HTML:
<div data-role="page" data-theme="b" id="home">
<div data-role="header" data-position="fixed">
<div class="home-header">
<div class="content-header" data-tap-toggle="false">
Header
</div>
</div>
</div>
<div data-role="content">
<div>
<div class="ActionsMenu">
<button>button</button>
<button>button</button>
<button>button</button>
<button>button</button>
</div>
<div id="ActionsContent">
<h3 class="ui-bar ui-bar-a ui-corner-all">Heading</h3>
<div class="ui-body">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse accumsan blandit fermentum. Pellentesque cursus mauris purus, auctor commodo mi ullamcorper nec. Donec semper mattis eros, nec condimentum ante sollicitudin quis. Etiam orci sem, porttitor ut tellus nec, blandit posuere urna. Proin a arcu non lacus pretium faucibus. Aliquam sed est porttitor, ullamcorper urna nec, vehicula lorem. Cras porttitor est lorem, non venenatis diam convallis congue.</p>
</div>
</div>
</div>
</div>
<div data-role="footer" data-position="fixed" data-tap-toggle="false">
footer
</div>
CSS:
.ActionsMenu {
width: 100%;
float: none;
}
.ActionsContent {
width: 100%;
float: none;
}
#media all and (min-width: 400px) {
.ActionsMenu {
float: left;
width: 25%;
padding-right: 50px;
}
.ActionsContent {
float: none;
margin-left: 25%;
}
}
As you can see, the content is under the buttons and not where I need it...
The page also need to be responsive and display a single column for mobiles...
DEMO
Have width prpperty defined for both the divs.
As you are going for responsive design i suggest using % widths
.MainContent .ActionsMenu {
width: 25%;
float: none;
overflow-scrolling: auto;
}
.MainContent .ActionsContent {
width: 60%;
float: right;
}
Have float element to float the content right
And You should have a id ActionsMenu in HTML not class.
<div class="ActionsMenu"> ..</div>
EDIT:
You want to align to right-http://jsfiddle.net/VT9m3/11/ add padding based on that
.ActionsContent {
float: left;
width:65%;
padding-left:20px;
}
but as your padding on the same div might break at a resoultion if the width of .ActionsMenu+.Actionscontent+padding >100% so have the Action menu in another div and have width property to it then have .ActionContent and have the padding
Please replace these css lines
.ActionsMenu {
width: 25%;
float: left;
overflow-scrolling: auto;
}
#ActionsContent {
width: 60%;
float: right;
}
You're using a class selector to select an id. Either replacing id="ActionsContent" with class="ActionsContent" or replacing .ActionsContent with #ActionsContent should make sure the styles are actually applied ;)

Align image next to a paragraph

Not just a simple image next to a paragraph< but with some spaces like this
(source: gyazo.com)
So far of what I've done :
<div class="span6">
<span class="head">Header</span>
<img style="vertical-align:middle float: left;" src="img/pickaxe.png"/>
<span class="paragraph">
This is Photoshop's version of Lorem Ipsum.
Proin gravida nibh vel velit auctor aliquet.
Aenean sollicitudin, lorem quis bibendum auc
tor, nisi elit consequat ipsum, nec sagittis sem nibh i
</span>
</div>
.span8 {
width: 620px;
}
.head {
font-weight: bold;
font-size: 26px;
float: left;
}
.paragraph {
font-size: 14px;
width: 300px;
}
And it looks like this
(source: gyazo.com)
Ignore the line, it's a cropper image off the web.
What am I doing wrong? how can I fix this.
Thanks!
Here is a jsfiddle for you: http://jsfiddle.net/Xxw85/
The code should look more like this:
<div class="span6">
<p>Header</p>
<div class="head">
<img src="https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcRgMvCRHrTA30jksWsHfDZ4GwWfjJhM8Ck2RAtA_OLeOpnGRTrEXw"/>
</div>
<div class="paragraph">
This is Photoshop's version of Lorem Ipsum. Proin gravida nibh vel velit auctor aliquet. Aenean sollicitudin, lorem quis bibendum auc
tor, nisi elit consequat ipsum, nec sagittis sem nibh i
</div>
<div style="clear:both"></div>
</div>
and css:
.span6 {
width: 620px;
background-color:#efefef;
}
.head {
font-weight: bold;
font-size: 26px;
float: left;
color:red;
}
.paragraph {
font-size: 14px;
width: 300px;
float:left;
}
Good luck.
Consider this fiddle. I have used div element instead of the span element inside the parent div.
<div>
<div class="head">Header</div>
<img style="vertical-align:middle float: left;" src="img/pickaxe.png"/>
</div>
And float the content to the right by adding this.
.paragraph {
float:right;}
http://jsfiddle.net/AaXTm/8/
The width of the element was less than the parent element and since you didn't use any floats or clear, the elements were visible inline.

vertical align text near a floating div

like in the title i can't put some text centered vertically near a div with CSS, i searched on google and on stackoverflow so i decided to make a question here.
This is an example of what i need done with Paint:
I tried display table cell and box solutions but it works only without the floating div on top left.
When the text is longer than the blue div it should go under the div just like a normal text with a floating div.
I'm searching an only CSS solution, it can be done or not?
I am not completely sure if that is possible, but here is my best attempt at it, at least works for the first 2 examples.
<div class="wrap">
<div class="invisible"></div>
<img src="http://placehold.it/140x100">
<p>Lorem ipsum.</p>
</div>
<div class="wrap">
<div class="invisible"></div>
<img src="http://placehold.it/140x100">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur viverra, nibh in molestie sodales, risus turpis vehicula tellus, vitae lobortis ligula tortor in enim.</p>
</div>
<div class="wrap">
<div class="invisible"></div>
<img src="http://placehold.it/140x100">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur viverra, nibh in molestie sodales, risus turpis vehicula tellus, vitae lobortis ligula tortor in enim. Proin venenatis arcu id enim rutrum eget condimentum urna venenatis. Suspendisse at tortor nisi, in tempus ligula. Maecenas nisl felis, bibendum ut luctus nec, bibendum sit amet erat.</p>
</div>
CSS:
.wrap {
width:500px;
border:1px solid red;
margin:10px;
}
.wrap:before {
content:'';
display:inline-block;
height:100%;
vertical-align:middle;
margin-left:-0.25em; /* adjusts spacing */
}
p {
display:inline-block;
vertical-align:middle;
width:350px;
}
img {
float:left;
}
.invisible {
height:100px;
display:inline-block;
vertical-align:middle;
}
A fiddle.
This is possible with pure CSS.
body {
background: url("http://img08.deviantart.net/b5aa/i/2015/140/7/c/chalkboard_by_lorelinde-d8u2phm.jpg") no-repeat;
}
.container {
color: rgba(255, 255, 255, .9);
font-family: "Chalkduster", "Baskerville";
font-size: 18px;
padding: 0 10px;
width: 550px;
}
#user_portrait {
border-radius: 13px;
border: 3px solid rgba(255, 255, 255, .9);
float: left;
margin: 0 20px 0 0;
max-height: 300px;
max-width: 300px;
filter: sepia(50%);
}
#overview_text {
letter-spacing: 1px;
line-height: 1.3rem;
padding: 0 0 0 10px;
white-space: pre-line;
}
<body>
<p class="container">
<img id="user_portrait" src="https://pbs.twimg.com/profile_images/704337993293815810/PmkKs6yw.jpg">
<span id="overview_text">“Never hate your enemies. It affects your judgment.”
“My father held a gun to his head, and my father assured the bandleader that either his signature or his brains would be on the contract.”
“There are many things my father taught me here in this room. He taught me: keep your friends close, but your enemies closer.”
</span>
</p>
</body>
The key point is to put both image and text into non-inline parent tag and make them float.
This is impossible with css only. (i would be happy to be proved wrong.)

Resources