Why css float does not work as expected - css

I have created 2 div one with float: left and one with float : right, each with 50% column width. Still they don't flow as expected. The second float not just on the right side of the first div but below the first div. Float doesn't behave according to the rule. So what rule am I missing here ?
<html>
<head>
<title>
</title>
<style type="text/css">
.column {
width: 50%;
}
div.right {
float: right;
}
}
div.left {
float: left;
}
img {
float: right;
margin: 0 0 1em 1em;
}
</style>
</head>
<body>
<div class='left column'>
<img src="css-float.png">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus imperdiet, nulla et dictum interdum, nisi lorem egestas odio, vitae scelerisque enim ligula venenatis dolor. Maecenas nisl est, ultrices nec congue eget, auctor vitae massa. Fusce luctus vestibulum augue ut aliquet. Mauris ante ligula, facilisis sed ornare eu, lobortis in odio. Praesent convallis urna a lacus interdum ut hendrerit risus congue. Nunc sagittis dictum nisi, sed ullamcorper ipsum dignissim ac. In at libero sed nunc venenatis imperdiet sed ornare turpis. Donec vitae dui eget tellus gravida venenatis. Integer fringilla congue eros non fermentum. Sed dapibus pulvinar nibh tempor porta. Cras ac leo purus. Mauris quis diam velit.
</div>
<div class='right column'>
<img src="css-float.png">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus imperdiet, nulla et dictum interdum, nisi lorem egestas odio, vitae scelerisque enim ligula venenatis dolor. Maecenas nisl est, ultrices nec congue eget, auctor vitae massa. Fusce luctus vestibulum augue ut aliquet. Mauris ante ligula, facilisis sed ornare eu, lobortis in odio. Praesent convallis urna a lacus interdum ut hendrerit risus congue. Nunc sagittis dictum nisi, sed ullamcorper ipsum dignissim ac. In at libero sed nunc venenatis imperdiet sed ornare turpis. Donec vitae dui eget tellus gravida venenatis. Integer fringilla congue eros non fermentum. Sed dapibus pulvinar nibh tempor porta. Cras ac leo purus. Mauris quis diam velit.
</div>
</body>
</html>

Your CSS is invalid, so stopping the rest of your stylesheet loading.
See here:
div.right {
float: right;
}
}
You are closing the rule twice, remove the second closing bracket

Fiddle
.column {
width: 49%;
}
div.left, div.right {
float: left;
border-right: 1px solid;
}
Reduce your width. You need side by side, So you add float left since both are under same container.

Demo.
.column {
width: 50%;
}
div.right {
float: right;
}
div.left {
float: left;
}
img {
float: right;
padding-right: 15px;
margin: 0 0 1em 1em;
}

Related

Gap left of header, despite width set to 100% (CSS) [duplicate]

This question already has answers here:
How wide is the default `<body>` margin?
(4 answers)
Closed 7 months ago.
Edit
Apparently my question is similar to a question about the margin width of a document's body. Which is kind of odd, because that question itself is the answer to mine. It's the answers here which refer to that question, and since I'm asking for those answers I can't know that. Hope this makes sense.
I have a webpage with fixed header and footer, for which I set the width to 100%. Nevertheless there is an 8 pixel gap to the left of both. How do I get rid of them?
CSS
#main {
width: 1200px;
height: 100%;
margin: 60px auto 0 auto;
padding: 1em;
}
/* pertaining header ------------------------------------ */
header, #main::before {
height: 60px;
}
header {
position: fixed;
top: 0;
width: 100%;
margin: auto;
background: linear-gradient(180deg, #91C1CC, #468795);
border-bottom: 1px solid black;
}
header div {
width: 1200px;
margin: 0 auto;
padding: 0;
}
header div p {
margin-top: 16px;
margin-left: 1000px;
font-family: Whitehall, Verdana, Geneva, sans-serif;
font-size: 2.5em;
color: white;
}
/* pertaining footer ------------------------------------ */
#container::after {
content: "";
display: block;
}
footer, #main::after {
height: 40px;
}
footer {
position: fixed;
bottom: 0;
width: 100%;
margin: auto;
background: linear-gradient(0, #91C1CC, #468795);
border-top: 1px solid black;
}
footer div {
width: 1200px;
margin: auto;
padding: 1em;
}
#departments {
margin: 0;
padding: 0 1em;
margin-top: -8px;
margin-left: -22px;
font-size: 85%;
}
#departments a {
margin-right: 3em;
color: black;
}
#departments a:link, #departments a:visited {
text-decoration: none;
}
JSfiddle at https://jsfiddle.net/stevenvh/65dao4pt/5/
The 8 pixel gap is cause by the HTML body tag, it has a default margin of 8px on all the four sides.
To get ride of all the gap around the element, just use CSS property of margin: 0; like this,
body {
/* to remove gaps from four sides */
margin: 0;
}
Working Example:
#font-face {
font-family: Whitehall;
src: url('fonts/Whitehall.woff') format('woff'), url('fonts/Whitehall.ttf') format('truetype');
}
body {
font-family: Verdana, Geneva, sans-serif;
line-height: 1.6em;
/* to remove gaps from four sides */
margin: 0;
}
#main {
width: 1200px;
height: 100%;
margin: 60px auto 0 auto;
padding: 1em;
}
/* pertaining header ------------------------------------ */
header,
#main::before {
height: 60px;
}
header {
position: fixed;
top: 0;
width: 100%;
margin: auto;
background: linear-gradient(180deg, #91C1CC, #468795);
border-bottom: 1px solid black;
}
header div {
width: 1200px;
margin: 0 auto;
padding: 0;
}
header div p {
margin-top: 16px;
margin-left: 1000px;
font-family: Whitehall, Verdana, Geneva, sans-serif;
font-size: 2.5em;
color: white;
}
/* pertaining footer ------------------------------------ */
#container::after {
content: "";
display: block;
}
footer,
#main::after {
height: 40px;
}
footer {
position: fixed;
bottom: 0;
width: 100%;
margin: auto;
background: linear-gradient(0, #91C1CC, #468795);
border-top: 1px solid black;
}
footer div {
width: 1200px;
margin: auto;
padding: 1em;
}
#departments {
margin: 0;
padding: 0 1em;
margin-top: -8px;
margin-left: -22px;
font-size: 85%;
}
#departments a {
margin-right: 3em;
color: black;
}
#departments a:link,
#departments a:visited {
text-decoration: none;
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Test</title>
</head>
<body>
<div id="container">
<header>
<div>
<p>Main title</p>
</div>
</header>
<div id="main">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam sit amet sem quam. Donec vehicula sed urna a tempor. Mauris facilisis malesuada varius. In ut dapibus lorem. Nullam iaculis tortor eget mauris sagittis, sed elementum mi semper. Aliquam
faucibus vel felis quis tempus. Pellentesque cursus risus at venenatis volutpat. Duis elementum, nulla at pulvinar pharetra, ligula purus scelerisque libero, quis fermentum dui ante blandit dui. Vivamus bibendum, mauris vitae hendrerit aliquam,
metus quam elementum est, sed viverra enim ipsum nec dui. Duis rutrum, eros a dignissim laoreet, enim justo feugiat massa, et pretium ex ligula et nunc. Praesent quis quam scelerisque, hendrerit diam in, suscipit felis. Curabitur iaculis congue
augue, sit amet rutrum nisi luctus id. Praesent ac massa quis ligula fermentum laoreet. Vivamus sed faucibus elit. Aliquam faucibus vel felis quis tempus. Pellentesque cursus risus at venenatis volutpat.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam sit amet sem quam. Donec vehicula sed urna a tempor. Mauris facilisis malesuada varius. In ut dapibus lorem. Nullam iaculis tortor eget mauris sagittis, sed elementum mi semper. Aliquam
faucibus vel felis quis tempus. Pellentesque cursus risus at venenatis volutpat. Duis elementum, nulla at pulvinar pharetra, ligula purus scelerisque libero, quis fermentum dui ante blandit dui. Vivamus bibendum, mauris vitae hendrerit aliquam,
metus quam elementum est, sed viverra enim ipsum nec dui. Duis rutrum, eros a dignissim laoreet, enim justo feugiat massa, et pretium ex ligula et nunc. Praesent quis quam scelerisque, hendrerit diam in, suscipit felis. Curabitur iaculis congue
augue, sit amet rutrum nisi luctus id. Praesent ac massa quis ligula fermentum laoreet. Vivamus sed faucibus elit. Aliquam faucibus vel felis quis tempus. Pellentesque cursus risus at venenatis volutpat.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam sit amet sem quam. Donec vehicula sed urna a tempor. Mauris facilisis malesuada varius. In ut dapibus lorem. Nullam iaculis tortor eget mauris sagittis, sed elementum mi semper. Aliquam
faucibus vel felis quis tempus. Pellentesque cursus risus at venenatis volutpat. Duis elementum, nulla at pulvinar pharetra, ligula purus scelerisque libero, quis fermentum dui ante blandit dui. Vivamus bibendum, mauris vitae hendrerit aliquam,
metus quam elementum est, sed viverra enim ipsum nec dui. Duis rutrum, eros a dignissim laoreet, enim justo feugiat massa, et pretium ex ligula et nunc. Praesent quis quam scelerisque, hendrerit diam in, suscipit felis. Curabitur iaculis congue
augue, sit amet rutrum nisi luctus id. Praesent ac massa quis ligula fermentum laoreet. Vivamus sed faucibus elit. Aliquam faucibus vel felis quis tempus. Pellentesque cursus risus at venenatis volutpat.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam sit amet sem quam. Donec vehicula sed urna a tempor. Mauris facilisis malesuada varius. In ut dapibus lorem. Nullam iaculis tortor eget mauris sagittis, sed elementum mi semper. Aliquam
faucibus vel felis quis tempus. Pellentesque cursus risus at venenatis volutpat. Duis elementum, nulla at pulvinar pharetra, ligula purus scelerisque libero, quis fermentum dui ante blandit dui. Vivamus bibendum, mauris vitae hendrerit aliquam,
metus quam elementum est, sed viverra enim ipsum nec dui. Duis rutrum, eros a dignissim laoreet, enim justo feugiat massa, et pretium ex ligula et nunc. Praesent quis quam scelerisque, hendrerit diam in, suscipit felis. Curabitur iaculis congue
augue, sit amet rutrum nisi luctus id. Praesent ac massa quis ligula fermentum laoreet. Vivamus sed faucibus elit. Aliquam faucibus vel felis quis tempus. Pellentesque cursus risus at venenatis volutpat.
</p>
</div>
<footer>
<div>
<p id="departments">
◼ About ◼ Contact ◼ Sitemap
</p>
</div>
</footer>
</div>
</body>
</html>
HTML's body tag has a margin on all sides set by default. By adding margin: 0 to your body you can fix that quite easily.
#font-face {
font-family: Whitehall;
src: url('fonts/Whitehall.woff') format('woff'),
url('fonts/Whitehall.ttf') format('truetype');
}
body {
font-family: Verdana, Geneva, sans-serif;
line-height: 1.6em;
margin: 0;
}
#main {
width: 1200px;
height: 100%;
margin: 60px auto 0 auto;
padding: 1em;
}
/* pertaining header ------------------------------------ */
header, #main::before {
height: 60px;
}
header {
position: fixed;
top: 0;
width: 100%;
margin: auto;
background: linear-gradient(180deg, #91C1CC, #468795);
border-bottom: 1px solid black;
}
header div {
width: 1200px;
margin: 0 auto;
padding: 0;
}
header div p {
margin-top: 16px;
margin-left: 1000px;
font-family: Whitehall, Verdana, Geneva, sans-serif;
font-size: 2.5em;
color: white;
}
/* pertaining footer ------------------------------------ */
#container::after {
content: "";
display: block;
}
footer, #main::after {
height: 40px;
}
footer {
position: fixed;
bottom: 0;
width: 100%;
margin: auto;
background: linear-gradient(0, #91C1CC, #468795);
border-top: 1px solid black;
}
footer div {
width: 1200px;
margin: auto;
padding: 1em;
}
#departments {
margin: 0;
padding: 0 1em;
margin-top: -8px;
margin-left: -22px;
font-size: 85%;
}
#departments a {
margin-right: 3em;
color: black;
}
#departments a:link, #departments a:visited {
text-decoration: none;
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Test</title>
</head>
<body>
<div id="container">
<header>
<div>
<p>Main title</p>
</div>
</header>
<div id="main">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam sit amet sem quam. Donec vehicula sed urna a tempor. Mauris facilisis malesuada varius. In ut dapibus lorem. Nullam iaculis tortor eget mauris sagittis, sed elementum mi semper. Aliquam faucibus vel felis quis tempus. Pellentesque cursus risus at venenatis volutpat. Duis elementum, nulla at pulvinar pharetra, ligula purus scelerisque libero, quis fermentum dui ante blandit dui.
Vivamus bibendum, mauris vitae hendrerit aliquam, metus quam elementum est, sed viverra enim ipsum nec dui. Duis rutrum, eros a dignissim laoreet, enim justo feugiat massa, et pretium ex ligula et nunc. Praesent quis quam scelerisque, hendrerit diam in, suscipit felis. Curabitur iaculis congue augue, sit amet rutrum nisi luctus id. Praesent ac massa quis ligula fermentum laoreet. Vivamus sed faucibus elit. Aliquam faucibus vel felis quis tempus. Pellentesque cursus risus at venenatis volutpat.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam sit amet sem quam. Donec vehicula sed urna a tempor. Mauris facilisis malesuada varius. In ut dapibus lorem. Nullam iaculis tortor eget mauris sagittis, sed elementum mi semper. Aliquam faucibus vel felis quis tempus. Pellentesque cursus risus at venenatis volutpat. Duis elementum, nulla at pulvinar pharetra, ligula purus scelerisque libero, quis fermentum dui ante blandit dui.
Vivamus bibendum, mauris vitae hendrerit aliquam, metus quam elementum est, sed viverra enim ipsum nec dui. Duis rutrum, eros a dignissim laoreet, enim justo feugiat massa, et pretium ex ligula et nunc. Praesent quis quam scelerisque, hendrerit diam in, suscipit felis. Curabitur iaculis congue augue, sit amet rutrum nisi luctus id. Praesent ac massa quis ligula fermentum laoreet. Vivamus sed faucibus elit. Aliquam faucibus vel felis quis tempus. Pellentesque cursus risus at venenatis volutpat.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam sit amet sem quam. Donec vehicula sed urna a tempor. Mauris facilisis malesuada varius. In ut dapibus lorem. Nullam iaculis tortor eget mauris sagittis, sed elementum mi semper. Aliquam faucibus vel felis quis tempus. Pellentesque cursus risus at venenatis volutpat. Duis elementum, nulla at pulvinar pharetra, ligula purus scelerisque libero, quis fermentum dui ante blandit dui.
Vivamus bibendum, mauris vitae hendrerit aliquam, metus quam elementum est, sed viverra enim ipsum nec dui. Duis rutrum, eros a dignissim laoreet, enim justo feugiat massa, et pretium ex ligula et nunc. Praesent quis quam scelerisque, hendrerit diam in, suscipit felis. Curabitur iaculis congue augue, sit amet rutrum nisi luctus id. Praesent ac massa quis ligula fermentum laoreet. Vivamus sed faucibus elit. Aliquam faucibus vel felis quis tempus. Pellentesque cursus risus at venenatis volutpat.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam sit amet sem quam. Donec vehicula sed urna a tempor. Mauris facilisis malesuada varius. In ut dapibus lorem. Nullam iaculis tortor eget mauris sagittis, sed elementum mi semper. Aliquam faucibus vel felis quis tempus. Pellentesque cursus risus at venenatis volutpat. Duis elementum, nulla at pulvinar pharetra, ligula purus scelerisque libero, quis fermentum dui ante blandit dui.
Vivamus bibendum, mauris vitae hendrerit aliquam, metus quam elementum est, sed viverra enim ipsum nec dui. Duis rutrum, eros a dignissim laoreet, enim justo feugiat massa, et pretium ex ligula et nunc. Praesent quis quam scelerisque, hendrerit diam in, suscipit felis. Curabitur iaculis congue augue, sit amet rutrum nisi luctus id. Praesent ac massa quis ligula fermentum laoreet. Vivamus sed faucibus elit. Aliquam faucibus vel felis quis tempus. Pellentesque cursus risus at venenatis volutpat.
</p>
</div>
<footer>
<div>
<p id="departments">
◼ About
◼ Contact
◼ Sitemap
</p>
</div>
</footer>
</div>
</body>
</html>
As you've set the header as position: fixed; you could add left: 0; to the header and it will force it to the left. Then you don't need to set the width.

Rotate text button in flex?

I would be grateful for advice about how to rotate a button in a flex context. I have a flex container with a "row" direction (that is, the three content items are arranged from left to right in a row), and the leftmost content item is a <div> that contains just a <button> with a few words of text in it. I want that <div> to be rendered vertically (so that the text reads from bottom to top), to hug the left edge of the container, and to be just the width of its one line of text.
The sample at https://jsfiddle.net/djbpitt/gth3nck9/74/ works as I need it to in Firefox 89, but in Chrome 90 (and Safari 14.1.1) the button is not rotated. caniuse.com tells me that vendor prefixes should not be required for CSS transform: rotate() or writing-mode: vertical-lr;, and adding a -webkit prefix doesn't seem to help anyway.
I would be grateful if someone could please advise me about how I can obtain the behavior I need in the versions of Firefox, Chrome, and Safari mentioned above (which are the latest versions as I write this). I would prefer a pure HTML/CSS (that is, no JavaScript) solution. Thank you!
html {
height: 100%;
}
body {
display: flex;
flex-direction: row;
height: 100%;
margin-left: 0;
padding-left: 0;
}
body > * {
overflow-y: auto;
height: 100vh;
}
body > section {
flex: auto;
}
div#button {
display: flex;
flex: 0 0 1em;
border: none;
justify-content: center;
transform: rotate(180deg);
margin: 0 5px 0 0;
padding: 0;
overflow: visible;
}
button {
margin: auto;
border: 1px black solid;
border-radius: 10px 0 0 10px;
padding: 3px;
}
button > span {
writing-mode: vertical-lr;
width: 1em;
margin: 3px;
}
nav {
flex: 0 0 20em;
margin-right: 1em;
padding-right: 1em;
border-right: 1px gray solid;
}
nav ul {
list-style-type: none;
padding-left: 0;
}
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>test</title>
</head>
<body>
<div id="button">
<button><span>Rotate me!</span></button>
</div>
<nav>
<ul>
<li>first</li>
<li>section</li>
</ul>
</nav>
<main>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis dignissim tristique est, et facilisis urna aliquet et. Vivamus porta laoreet mi non cursus. Integer volutpat tortor lectus, interdum gravida libero interdum ac. Curabitur malesuada cursus laoreet. Donec nec varius est, ac venenatis velit. Vivamus ac ipsum et nibh dictum dignissim. Fusce eget turpis in sem rutrum congue. Donec vitae sollicitudin nunc, elementum porta tortor. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Pellentesque convallis quam leo, pretium fermentum ante imperdiet sit amet. Quisque egestas risus vitae ante fermentum tincidunt. Sed consectetur efficitur tempus. Nunc tincidunt nunc sed semper accumsan. Ut eu tortor scelerisque, aliquet leo eget, ullamcorper dolor.</p>
<p>Duis non nisi vitae felis ultricies dapibus pulvinar quis ex. Nullam imperdiet, risus sed pharetra aliquam, mi nulla condimentum purus, tincidunt hendrerit ex metus vitae nisl. Nullam venenatis turpis libero, a bibendum elit venenatis ut. Aenean et orci ac metus pretium pellentesque. Phasellus sed faucibus est. Aenean a dui non augue aliquet sagittis quis at ex. Vestibulum lorem lectus, sodales efficitur lacinia id, iaculis id ante. Fusce aliquam erat libero, a ultrices dolor volutpat et. Vivamus at euismod nisl. Donec hendrerit non lacus vel mollis.</p>
<p>Phasellus gravida non nisi quis vehicula. Curabitur sagittis nec nulla eget sollicitudin. Mauris sit amet mattis ligula. Nulla pretium posuere diam vitae tempor. Aenean consequat ligula luctus quam vestibulum, vel rhoncus turpis laoreet. Etiam nec aliquam ipsum, ut tristique lorem. In nec auctor arcu. Proin sed finibus ligula. Sed scelerisque lorem ligula. Nam quis quam vehicula, hendrerit nibh nec, rhoncus elit. Praesent porttitor, tellus nec aliquam sollicitudin, justo orci sagittis nisl, non imperdiet ligula mauris sit amet eros. In dignissim placerat laoreet. Aenean ipsum lorem, aliquet id arcu id, rhoncus porta justo. Integer egestas mauris quam, eget placerat metus sagittis eget. Aenean volutpat eleifend nisi eget interdum.</p>
<p>
Vestibulum in ante lectus. Mauris luctus imperdiet facilisis. Nunc sagittis velit lacus, eget gravida arcu efficitur vitae. Sed sodales felis elit, eget volutpat dui congue sit amet. Fusce mi velit, cursus volutpat dapibus in, auctor id dolor. Maecenas convallis nisl justo. Cras sollicitudin tellus nec dui dictum finibus. Fusce nec feugiat metus. Aliquam sit amet congue nulla. Sed cursus fringilla sapien et malesuada. Duis aliquet, nunc eget consectetur fringilla, felis lectus ultrices mi, id maximus justo mauris a mi.</p>
<p>
Vivamus ac est vitae nulla dignissim posuere ac id arcu. Duis sed tortor pretium, tempus orci vel, efficitur ex. Quisque aliquet enim mattis odio tincidunt lacinia. Vestibulum blandit congue neque ac bibendum. Proin at consequat tortor, id malesuada dolor. Integer interdum purus sit amet leo venenatis, gravida porttitor ipsum eleifend. Donec venenatis maximus faucibus. Duis et magna vitae arcu malesuada sodales.</p>
</main>
</body>
</html>
The problem seems to lie with Chrome/Edge settings for button. They have for example amongst other things:
-webkit-writing-mode: horizontal-tb !important;
So this snippet gives up trying to style a button and replaces it with a div. Obviously you'll want to style that as you wish:
html {
height: 100%;
}
body {
display: flex;
flex-direction: row;
height: 100%;
margin-left: 0;
padding-left: 0;
}
body>* {
overflow-y: auto;
height: 100vh;
}
div#button {
position: relative;
display: flex;
flex: 0 0 1em;
writing-mode: vertical-lr;
border: none;
justify-content: center;
transform: rotate(180deg);
margin: 0 5px 0 0;
padding: 0;
overflow: visible;
}
#button div {
background-color: #eeeeee;
padding: 10px 5px 10px 5px;
border: 1px solid black;
border-radius: 5px;
}
nav {
flex: 0 0 20em;
margin-right: 1em;
padding-right: 1em;
border-right: 1px gray solid;
}
nav ul {
list-style-type: none;
padding-left: 0;
}
nav ul {
list-style-type: none;
padding-left: 0;
}
<div id="button">
<div>Rotate me!</div>
</div>
<nav>
<ul>
<li>first</li>
<li>section</li>
</ul>
</nav>
<main>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis dignissim tristique est, et facilisis urna aliquet et. Vivamus porta laoreet mi non cursus. Integer volutpat tortor lectus, interdum gravida libero interdum ac. Curabitur malesuada cursus
laoreet. Donec nec varius est, ac venenatis velit. Vivamus ac ipsum et nibh dictum dignissim. Fusce eget turpis in sem rutrum congue. Donec vitae sollicitudin nunc, elementum porta tortor. Class aptent taciti sociosqu ad litora torquent per conubia
nostra, per inceptos himenaeos. Pellentesque convallis quam leo, pretium fermentum ante imperdiet sit amet. Quisque egestas risus vitae ante fermentum tincidunt. Sed consectetur efficitur tempus. Nunc tincidunt nunc sed semper accumsan. Ut eu tortor
scelerisque, aliquet leo eget, ullamcorper dolor.</p>
<p>Duis non nisi vitae felis ultricies dapibus pulvinar quis ex. Nullam imperdiet, risus sed pharetra aliquam, mi nulla condimentum purus, tincidunt hendrerit ex metus vitae nisl. Nullam venenatis turpis libero, a bibendum elit venenatis ut. Aenean et
orci ac metus pretium pellentesque. Phasellus sed faucibus est. Aenean a dui non augue aliquet sagittis quis at ex. Vestibulum lorem lectus, sodales efficitur lacinia id, iaculis id ante. Fusce aliquam erat libero, a ultrices dolor volutpat et. Vivamus
at euismod nisl. Donec hendrerit non lacus vel mollis.</p>
<p>Phasellus gravida non nisi quis vehicula. Curabitur sagittis nec nulla eget sollicitudin. Mauris sit amet mattis ligula. Nulla pretium posuere diam vitae tempor. Aenean consequat ligula luctus quam vestibulum, vel rhoncus turpis laoreet. Etiam nec aliquam
ipsum, ut tristique lorem. In nec auctor arcu. Proin sed finibus ligula. Sed scelerisque lorem ligula. Nam quis quam vehicula, hendrerit nibh nec, rhoncus elit. Praesent porttitor, tellus nec aliquam sollicitudin, justo orci sagittis nisl, non imperdiet
ligula mauris sit amet eros. In dignissim placerat laoreet. Aenean ipsum lorem, aliquet id arcu id, rhoncus porta justo. Integer egestas mauris quam, eget placerat metus sagittis eget. Aenean volutpat eleifend nisi eget interdum.</p>
<p>
Vestibulum in ante lectus. Mauris luctus imperdiet facilisis. Nunc sagittis velit lacus, eget gravida arcu efficitur vitae. Sed sodales felis elit, eget volutpat dui congue sit amet. Fusce mi velit, cursus volutpat dapibus in, auctor id dolor. Maecenas
convallis nisl justo. Cras sollicitudin tellus nec dui dictum finibus. Fusce nec feugiat metus. Aliquam sit amet congue nulla. Sed cursus fringilla sapien et malesuada. Duis aliquet, nunc eget consectetur fringilla, felis lectus ultrices mi, id maximus
justo mauris a mi.</p>
<p>
Vivamus ac est vitae nulla dignissim posuere ac id arcu. Duis sed tortor pretium, tempus orci vel, efficitur ex. Quisque aliquet enim mattis odio tincidunt lacinia. Vestibulum blandit congue neque ac bibendum. Proin at consequat tortor, id malesuada dolor.
Integer interdum purus sit amet leo venenatis, gravida porttitor ipsum eleifend. Donec venenatis maximus faucibus. Duis et magna vitae arcu malesuada sodales.</p>
</main>
OP here. Thank you, A Haworth, for the pointer to the !important user agent setting for writing-mode in Webkit. I knew that browsers had default styling, of course, but I didn't realize that some of that styling apparently could not be overridden with user specifications.
Your insight led me to give up on changing the writing-mode value for the <button>, as you suggest, and I approached the task by wrapping a <span> around the text inside my <button> and specifying the writing-mode for the <span>. The new version is at https://jsfiddle.net/djbpitt/gth3nck9/86/. HTML and CSS are copied below:
<div id="button">
<button>
<span>Rotate me!</span>
</button>
</div>
I had to do some additional fiddling with the CSS to get the rendering I wanted:
html {
height: 100%;
}
body {
display: flex;
flex-direction: row;
height: 100%;
margin-left: 0;
padding-left: 0;
}
body > * {
overflow-y: auto;
height: 100vh;
}
body > section {
flex: auto;
}
div#button {
display: flex;
flex: 0 0 1em;
border: none;
justify-content: center;
transform: rotate(180deg);
margin: 0 5px 0 0;
padding: 0;
overflow: visible;
}
button {
margin: auto;
border: 1px black solid;
border-radius: 10px 0 0 10px;
padding: 3px;
}
button > span {
writing-mode: vertical-lr;
width: 1em;
margin: 3px;
}
nav {
flex: 0 0 20em;
margin-right: 1em;
padding-right: 1em;
border-right: 1px gray solid;
}
nav ul {
list-style-type: none;
padding-left: 0;
}

make element visible only if scrolled down or page higher than video, CSS only

I want absolute element appear only when page is scrolled down, or at least when page height is higher than window height.
Is this possible with pure CSS? How?
example code:
<body>
content...
<button id="return">return to top</button>
</body>
want to show #return only if 1 page is higher than window OR 2 scrollbar is visible OR 3 even better scrollbar is visible and scrolled down
Here is one idea where the element will appear after a small scroll and will sticky to the bottom:
p {
font-size: 35px;
padding: 10px;
}
body {
margin:0;
position: relative; /* relative to the body */
}
.fixed {
position: absolute;
top: 110vh; /* defined when the element will appear */
bottom: 0;
left: 0;
right: 0;
/* needed to push the sticky element down */
display:flex;
flex-direction:column;
justify-content:flex-end;
/* to hide element if content is short*/
clip-path:polygon(0 0,100% 0,100% 100%,0 100%);
}
.fixed>div {
/* stick to the bottom */
position: sticky;
bottom: 0;
background: red;
padding: 15px;
color: #fff;
text-align: center;
}
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin ac risus ac est pulvinar finibus cursus non augue. Proin turpis tortor, dapibus vel metus eget, fermentum aliquam diam. Quisque sodales est sed diam mollis dictum. Aliquam ut volutpat nisi.
Aenean luctus turpis in malesuada malesuada. Praesent non ligula ut ligula feugiat convallis porttitor nec leo. Integer vel risus eget metus viverra ultrices vel vel enim. Sed vitae laoreet ex. Fusce tristique feugiat odio non consequat. Sed bibendum
tempor est, sed vestibulum ex aliquet quis. Nam libero quam, laoreet at elementum in, scelerisque vel ex. Vivamus ac purus eget orci vehicula gravida. Aliquam eleifend felis eget porttitor sollicitudin. Donec ut sodales eros. Sed a eros urna.
tempor est, sed vestibulum ex aliquet quis. Nam libero quam, laoreet at elementum in, scelerisque vel ex. Vivamus ac purus eget orci vehicula gravida. Aliquam eleifend felis eget porttitor sollicitudin. Donec ut sodales eros. Sed a eros urna.
</p>
<div class="fixed">
<div class="banner">some content here</div>
</div>
With some fading effect:
p {
font-size: 35px;
padding: 10px;
}
body {
margin:0;
position: relative; /* relative to the body */
}
.fixed {
position: absolute;
top: 110vh; /* defined when the element will appear */
bottom: 0;
left: 0;
right: 0;
/* needed to push the sticky element down */
display:flex;
flex-direction:column;
justify-content:flex-end;
/*fading*/
-webkit-mask:linear-gradient(to bottom,transparent,#fff 200px);
mask:linear-gradient(to bottom,transparent,#fff 200px);
}
.fixed>div {
/* stick to the bottom */
position: sticky;
bottom: 0;
background: red;
padding: 15px;
color: #fff;
text-align: center;
}
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin ac risus ac est pulvinar finibus cursus non augue. Proin turpis tortor, dapibus vel metus eget, fermentum aliquam diam. Quisque sodales est sed diam mollis dictum. Aliquam ut volutpat nisi.
Aenean luctus turpis in malesuada malesuada. Praesent non ligula ut ligula feugiat convallis porttitor nec leo. Integer vel risus eget metus viverra ultrices vel vel enim. Sed vitae laoreet ex. Fusce tristique feugiat odio non consequat. Sed bibendum
tempor est, sed vestibulum ex aliquet quis. Nam libero quam, laoreet at elementum in, scelerisque vel ex. Vivamus ac purus eget orci vehicula gravida. Aliquam eleifend felis eget porttitor sollicitudin. Donec ut sodales eros. Sed a eros urna.
tempor est, sed vestibulum ex aliquet quis. Nam libero quam, laoreet at elementum in, scelerisque vel ex. Vivamus ac purus eget orci vehicula gravida. Aliquam eleifend felis eget porttitor sollicitudin. Donec ut sodales eros. Sed a eros urna.
</p>
<div class="fixed">
<div class="banner">some content here</div>
</div>
To avoid the extra scroll when the content is short here is a trick using min() (it won't work on Firefox for now)
p {
font-size: 35px;
padding: 10px;
}
body {
margin:0;
position: relative; /* relative to the body */
}
.fixed {
position: absolute;
top: min(100%,110vh); /* defined when the element will appear */
bottom: 0;
left: 0;
right: 0;
/* needed to push the sticky element down */
display:flex;
flex-direction:column;
justify-content:flex-end;
/*fading*/
-webkit-mask:linear-gradient(to bottom,transparent,#fff 200px);
mask:linear-gradient(to bottom,transparent,#fff 200px);
}
.fixed>div {
/* stick to the bottom */
position: sticky;
bottom: 0;
background: red;
padding: 15px;
color: #fff;
text-align: center;
}
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin ac risus ac est pulvinar finibus cursus non augue. Proin turpis tortor, dapibus vel metus eget, fermentum aliquam diam. Quisque sodales est sed diam mollis dictum. Aliquam ut volutpat nisi.
Aenean luctus turpis in malesuada malesuada. Praesent non ligula ut ligula feugiat convallis porttitor nec leo. Integer vel risus eget metus viverra ultrices vel vel enim. Sed vitae laoreet ex. Fusce tristique feugiat odio non consequat. Sed bibendum
tempor est, sed vestibulum ex aliquet quis. Nam libero quam, laoreet at elementum in, scelerisque vel ex. Vivamus ac purus eget orci vehicula gravida. Aliquam eleifend felis eget porttitor sollicitudin. Donec ut sodales eros. Sed a eros urna.
tempor est, sed vestibulum ex aliquet quis. Nam libero quam, laoreet at elementum in, scelerisque vel ex. Vivamus ac purus eget orci vehicula gravida. Aliquam eleifend felis eget porttitor sollicitudin. Donec ut sodales eros. Sed a eros urna.
</p>
<div class="fixed">
<div class="banner">some content here</div>
</div>

Why setting background color for my header div also sets color for the rest of other divs?

I set color-background for .header and .footer to yellow. But it also sets same background colors for the content div, why ? It isn't logicial.
<html>
<head>
<title>
</title>
<style type="text/css">
.header {
background-color: yellow;
}
.footer {
background-color: yellow;
}
.column {
width: 50%;
}
div.right {
float: right;
}
div.left {
float: left;
}
img {
float: right;
margin: 0 0 1em 1em;
}
</style>
</head>
<body>
<div class='header'>
header
</div>
<div class='left column'>
<img src="css-float.png">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus imperdiet, nulla et dictum interdum, nisi lorem egestas odio, vitae scelerisque enim ligula venenatis dolor. Maecenas nisl est, ultrices nec congue eget, auctor vitae massa. Fusce luctus vestibulum augue ut aliquet. Mauris ante ligula, facilisis sed ornare eu, lobortis in odio. Praesent convallis urna a lacus interdum ut hendrerit risus congue. Nunc sagittis dictum nisi, sed ullamcorper ipsum dignissim ac. In at libero sed nunc venenatis imperdiet sed ornare turpis. Donec vitae dui eget tellus gravida venenatis. Integer fringilla congue eros non fermentum. Sed dapibus pulvinar nibh tempor porta. Cras ac leo purus. Mauris quis diam velit.
</div>
<div class='right column'>
<img src="css-float.png">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus imperdiet, nulla et dictum interdum, nisi lorem egestas odio, vitae scelerisque enim ligula venenatis dolor. Maecenas nisl est, ultrices nec congue eget, auctor vitae massa. Fusce luctus vestibulum augue ut aliquet. Mauris ante ligula, facilisis sed ornare eu, lobortis in odio. Praesent convallis urna a lacus interdum ut hendrerit risus congue. Nunc sagittis dictum nisi, sed ullamcorper ipsum dignissim ac. In at libero sed nunc venenatis imperdiet sed ornare turpis. Donec vitae dui eget tellus gravida venenatis. Integer fringilla congue eros non fermentum. Sed dapibus pulvinar nibh tempor porta. Cras ac leo purus. Mauris quis diam velit.
</div>
<div class='footer'>
footer
</div>
</body>
</html>
You haven't cleared the floats so the divs are collapsing
You can fix it with
.footer {
background-color: yellow;
clear:both;
}
JSfiddle Demo
Mathiasaurus is spot on. You could clear your non floating elements, mainly the footer.
.header,
.footer {
width: 100%;
clear: both;
}
or add
.header,
.footer {
width: 100%;
float: left;
}
to include them in the flow.
Putting display: inline-block and setting widths to your header and footer seem to remedy the issue!
http://jsfiddle.net/MathiasaurusRex/jm78Z/4/
div{
display: inline-block;
width: 100%;
}
.header{
width: 100%;
}
.footer{
width: 100%;
}
because u have the same class name for the different div's! And Also the same id's i guess!
<div class='header'>
header
try doing dis for your next div tag
<div class='header1' >
header
in order for the css to work in different manner for different div tags u must have different identites of each div tag!
I think this link will help you
http://www.w3schools.com/css/css_selectors.asp

Image-alignment error in Wordpress

I'm developing a theme for Wordpress.
As usual, there are the main page (index.php or home.php) with post summary and single.php file to display a certain post.
On the main page, the image alignment works as follow:
When I resize the page...
Inside single.php, it shows so:
I'm using this stylesheet:
/* Images */
.alignright {
float:right;
margin: 0 0 10px 20px;
}
.alignleft {
float:left;
margin: 0 20px 10px 0;
}
.aligncenter {
display: block;
margin: 0 auto 1px auto;
clear: both;
}
.wp-caption {
border: 1px solid #ddd;
text-align: center;
background-color: #f3f3f3;
padding-top: 4px;
}
.wp-caption img {
margin: 0;
padding: 0;
border: 0 none;
}
.wp-caption p.wp-caption-text {
font-size: 12px;
font-style: italic;
line-height: 20px;
padding: 0 5px;
margin: 5px 0;
}
How can I fix these problems?
Best regards, Vi.
Note: code of post body is:
<article class="post-9 post type-post status-publish format-standard hentry category-uncategorized tag-ipsum tag-lorem tag-smashing tag-sticky" id="post-9">
<!-- Display the Post's content in a div box. -->
<div class="entry">
<div id="attachment_10" class="wp-caption alignright" style="width: 253px"><img class="size-medium wp-image-10" alt="Smashing Pumpkins" src="http://localhost/~vdenotaris/wordpress/wp-content/uploads/2012/12/SP-Poster-243x300.jpg" width="243" height="300" /><p class="wp-caption-text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque et sapien metus. Nulla a sollicitudin nunc.</p></div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque et sapien metus. Nulla a sollicitudin nunc. <ins datetime="2012-12-19T17:23:48+00:00">Donec diam sem, porta id facilisis sit amet</ins>, auctor et justo. Mauris sapien urna, imperdiet imperdiet pharetra in, tempus id augue. Sed vitae leo purus. Donec consectetur porta leo vitae luctus. Sed sed mollis nulla.</p>
<p>Praesent venenatis gravida pellentesque. Pellentesque sit amet orci sem, vitae gravida massa. Maecenas suscipit volutpat felis. Proin placerat est at ipsum fermentum vulputate.</p>
<p>In ac erat lacus, ac congue urna. Nunc egestas luctus orci, ut elementum neque gravida vel. Vivamus blandit nunc vitae mauris convallis ac euismod felis ultricies. Phasellus ac ligula lorem, in adipiscing velit. Aliquam auctor ultricies est, vitae condimentum tellus consequat eget.</p>
<div id="attachment_34" class="wp-caption alignleft" style="width: 250px"><img class="size-medium wp-image-34 " alt="Benuimaru" src="http://localhost/~vdenotaris/wordpress/wp-content/uploads/2012/12/Benimaru-Nikaido-240x300.jpg" width="240" height="300" /><p class="wp-caption-text">Benimaru Nikaido</p></div>
<p>Nulla tempor, ante pulvinar vehicula faucibus, turpis mi pellentesque est, eget egestas lectus nulla vel nisl. Curabitur in turpis id eros ultrices gravida. Nam vel mauris in nibh blandit facilisis et ut dui. Donec in dignissim diam. Maecenas aliquam porttitor sapien, at tempus mauris tincidunt ut. Donec ut lectus id ante fermentum pretium. Curabitur auctor orci eu magna ultrices auctor. Etiam placerat, magna nec ultricies convallis, elit turpis mattis felis, ut dapibus lorem orci in enim. Fusce ipsum felis, commodo et posuere quis, commodo ut lacus. Pellentesque tristique augue varius arcu blandit mollis. Donec aliquam purus vitae augue vehicula placerat. Aenean libero nulla, rutrum in volutpat id, viverra id nunc.</p>
<ul>
<li>Quisque auctor consequat sagittis. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</li>
<li>Nullam luctus placerat lorem ornare volutpat. Integer <code>euismod magna</code> a neque fringilla eget mollis orci tristique.</li>
</ul>
<pre>Etiam sagittis augue vitae nunc imperdiet ut vehicula diam condimentum. Etiam non massa libero. Nam eget mi felis, nec dapibus neque. Cras viverra eleifend cursus. Aliquam sagittis auctor accumsan. Vivamus tincidunt, metus a varius condimentum, nisl erat commodo libero, et faucibus urna dolor eget nisi. Cras mi lectus, dictum sed volutpat eu, laoreet non mi. Aliquam dolor odio, malesuada sed volutpat et, facilisis sit amet eros.</pre>
<p>Aenean hendrerit feugiat leo, eget sollicitudin mauris pretium non. Suspendisse potenti. Quisque eget nunc magna. Proin lectus dolor, consequat et vulputate id, vehicula id velit. Cras at elit id turpis luctus pretium sed eu ante.<del> Nunc rutrum pulvinar dapibus. Mauris nisl mauris, porttitor in pulvinar nec, auctor ac felis.</del> Aliquam malesuada purus sed augue condimentum et lacinia turpis porttitor. Donec tempor aliquet ligula, elementum facilisis est congue eget.</p>
<blockquote><p>Nullam dapibus aliquet sem, vel mollis elit sagittis vel. Etiam quis leo ante, ut ultricies orci.</p></blockquote>
<p>Mauris eget ipsum orci, et euismod tortor. Integer gravida justo nisl, in dictum eros. Maecenas<strong> venenatis erat eu tortor consequat porttitor eu et lectus</strong>. Maecenas volutpat nibh quis nisl tempor quis faucibus enim rhoncus. Vestibulum placerat, dolor in faucibus lacinia, augue odio rhoncus justo, sed facilisis lectus nulla eget tortor. Donec vitae purus nulla. Quisque ut tellus quis turpis fermentum bibendum. <a title="Sample" href="http://sample">Mauris ullamcorper, massa in suscipit luctus, metus dui auctor est, et mattis dolor tortor quis elit.</a> Nulla felis massa, auctor vel adipiscing malesuada, tempor a velit. Sed tincidunt congue turpis eget pharetra.</p>
</div>
</article>
You may be able to force it by adding a clear:left to the .wp-caption classes that also have .alignright and visa versa. Having a URL to your site would be helpful to get you something more specific.
Update: You're using a responsive layout, so things will change depending on the browser, but basically it looks like you aren't happy with the way the first image on single.php floats so that it cuts the second paragraph to one word in the first line. There isn't much you can do about that, though, without making writing posts a PITA later on. Your homepage and your single.php are displaying slightly differently, the first paragraph on the homepage is much longer - by about 1-2 lines- than on single.php so that's why the first image floating to the right is behaving differently. As for the unordered lists, this is a typical pain with WordPress image alignment unfortunately, see it all the time. Easiest way to deal with it is to try to structure your posts such that the images don't end up alongside a list or, barring that, set your UL so that it forces a new line using 'clear' and 'display' properties.
The only solution that I've found is the follow:
article .entry ul {
margin: 10px 0 10px 2px;
}
article .entry ul > li {
margin: 5px 0;
list-style-position: inside;
}
/* Images */
.alignright {
display: inline;
float: right;
margin: 0 0 10px 20px;
}
.alignleft {
display: inline;
float: left;
margin: 0 20px 10px 0;
}
.aligncenter {
display: block;
margin: 0 auto 1px auto;
clear: both;
}
.wp-caption {
border: 1px solid #ddd;
text-align: center;
background-color: #f3f3f3;
padding-top: 4px;
}
.wp-caption img {
margin: 0;
padding: 0;
border: 0 none;
}
.wp-caption p.wp-caption-text {
font-size: 12px;
font-style: italic;
line-height: 20px;
padding: 0 5px;
margin: 5px 0;
}
And there is the result:
That isn't the best technique there can possibly be, but the result may be considered acceptable (I think).

Resources