I'm still fairly new to HTML and CSS.
Does anyone know how I can move my scroll bar just a few pixels to the left, away from the edge?
This is what it currently looks like:
Current scroll bar
And this is the CSS code I'm working with:
::-webkit-scrollbar {
width: 7px;
height: 0px;
right: 3px
}
::-webkit-scrollbar-button {
width: 10px;
height: 0px;
}
::-webkit-scrollbar-thumb {
background: #FFFFFF;
border: 5px none;
border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
background: #FFFFFF;
}
::-webkit-scrollbar-thumb:active {
background: #FFFFFF;
}
::-webkit-scrollbar-track {
background: rgba(0, 0, 0, 0.2);
border: 5px none;
border-radius: 2px;
}
::-webkit-scrollbar-track:hover {
background: rgba(0, 0, 0, 0.2);
}
::-webkit-scrollbar-track:active {
background: #FFFFFF;
}
::-webkit-scrollbar-corner {
background: #FFFFFF;
}
There's a trick.
Set margin-right to the parent element.
body {
background-color: grey;
}
.container-wrapper {
border: 1px solid blue;
margin-bottom: 24px;
}
.container {
border: 1px solid red;
height: 100px;
overflow-y: auto;
margin-right: 24px;
}
::-webkit-scrollbar {
width: 7px;
height: 0px;
right: 3px;
}
::-webkit-scrollbar-button {
width: 10px;
height: 0px;
}
::-webkit-scrollbar-thumb {
background: #FFFFFF;
border: 5px none;
border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
background: #FFFFFF;
}
::-webkit-scrollbar-thumb:active {
background: #FFFFFF;
}
::-webkit-scrollbar-track {
background: rgba(0, 0, 0, 0.2);
border: 5px none;
border-radius: 2px;
}
::-webkit-scrollbar-track:hover {
background: rgba(0, 0, 0, 0.2);
}
::-webkit-scrollbar-track:active {
background: #FFFFFF;
}
::-webkit-scrollbar-corner {
background: #FFFFFF;
}
<div class="container-wrapper">
<div class="container">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ut nibh sit amet nisl semper condimentum ac a lectus. Mauris volutpat aliquet justo, consequat scelerisque enim laoreet in. In nibh nisi, ultricies eget augue imperdiet, blandit ultricies lacus.
Aenean turpis ex, interdum sit amet ante quis, malesuada maximus quam. Pellentesque venenatis mi eu risus mollis sagittis. Nulla facilisi. Pellentesque consectetur sagittis turpis. Maecenas eu neque scelerisque felis faucibus pellentesque. Aliquam
id mauris in lectus tincidunt aliquet. In imperdiet lacus et lorem iaculis, nec vulputate velit efficitur. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Morbi sit amet metus arcu. Quisque id purus tortor. Nullam
vitae molestie augue, et varius orci. Aliquam erat volutpat. Suspendisse commodo quam id arcu condimentum, vitae tempor quam auctor. Aliquam sit amet bibendum dolor. Fusce maximus eleifend velit, at faucibus erat lacinia eget. Cras eget nibh nec magna
gravida dictum. Aliquam vehicula erat in pretium imperdiet. Aenean id felis in enim dignissim iaculis. Nam vel pulvinar quam. Vestibulum quis mauris hendrerit, efficitur libero et, accumsan nisl. Proin hendrerit, ligula in finibus iaculis, nisi ligula
rhoncus tortor, quis commodo sem neque non sem. Nulla sollicitudin nulla ut nibh rutrum, in hendrerit magna maximus. Quisque commodo pulvinar ipsum, nec porta magna ullamcorper ac. Donec efficitur elit eget lorem dictum, quis pretium leo congue. Aliquam
dictum leo vel tortor dapibus, sit amet viverra leo efficitur. Fusce ultricies sem quis accumsan dignissim. Phasellus aliquam nisl a malesuada tristique. Ut sed diam nec lectus pharetra gravida. Nulla vel dolor at est auctor eleifend ac nec arcu.
Suspendisse eget lobortis lacus. Nunc lobortis libero lectus, sed luctus erat eleifend sit amet. In at blandit leo. Curabitur congue mauris at ante interdum molestie. Nullam dignissim elementum purus id tempor. Donec id nisi a leo sollicitudin convallis.
Nulla quis suscipit lacus. Nam vitae ante quis nulla dignissim volutpat. Morbi nibh mi, placerat ac eleifend ac, malesuada nec ligula. Morbi finibus nibh augue, dapibus ultrices purus pretium ac. Quisque id vulputate sem, eu suscipit neque. Nunc et
augue at odio facilisis varius. Vivamus fermentum est ipsum, a tincidunt augue luctus at. Maecenas vel bibendum nunc. Quisque vitae sapien sit amet lorem gravida vehicula. Maecenas ac neque vestibulum, aliquam quam non, sagittis tellus. Nulla urna
risus, dictum sit amet ultricies ut, interdum nec ante.
</div>
</div>
If you remove borders, it looks like the scrollbar is pushed away from the right side of the viewport.
body {
background-color: grey;
}
.container-wrapper {
margin-bottom: 24px;
}
.container {
height: 100px;
overflow-y: auto;
margin-right: 24px;
}
::-webkit-scrollbar {
width: 7px;
height: 0px;
right: 3px;
}
::-webkit-scrollbar-button {
width: 10px;
height: 0px;
}
::-webkit-scrollbar-thumb {
background: #FFFFFF;
border: 5px none;
border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
background: #FFFFFF;
}
::-webkit-scrollbar-thumb:active {
background: #FFFFFF;
}
::-webkit-scrollbar-track {
background: rgba(0, 0, 0, 0.2);
border: 5px none;
border-radius: 2px;
}
::-webkit-scrollbar-track:hover {
background: rgba(0, 0, 0, 0.2);
}
::-webkit-scrollbar-track:active {
background: #FFFFFF;
}
::-webkit-scrollbar-corner {
background: #FFFFFF;
}
<div class="container-wrapper">
<div class="container">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ut nibh sit amet nisl semper condimentum ac a lectus. Mauris volutpat aliquet justo, consequat scelerisque enim laoreet in. In nibh nisi, ultricies eget augue imperdiet, blandit ultricies lacus.
Aenean turpis ex, interdum sit amet ante quis, malesuada maximus quam. Pellentesque venenatis mi eu risus mollis sagittis. Nulla facilisi. Pellentesque consectetur sagittis turpis. Maecenas eu neque scelerisque felis faucibus pellentesque. Aliquam
id mauris in lectus tincidunt aliquet. In imperdiet lacus et lorem iaculis, nec vulputate velit efficitur. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Morbi sit amet metus arcu. Quisque id purus tortor. Nullam
vitae molestie augue, et varius orci. Aliquam erat volutpat. Suspendisse commodo quam id arcu condimentum, vitae tempor quam auctor. Aliquam sit amet bibendum dolor. Fusce maximus eleifend velit, at faucibus erat lacinia eget. Cras eget nibh nec magna
gravida dictum. Aliquam vehicula erat in pretium imperdiet. Aenean id felis in enim dignissim iaculis. Nam vel pulvinar quam. Vestibulum quis mauris hendrerit, efficitur libero et, accumsan nisl. Proin hendrerit, ligula in finibus iaculis, nisi ligula
rhoncus tortor, quis commodo sem neque non sem. Nulla sollicitudin nulla ut nibh rutrum, in hendrerit magna maximus. Quisque commodo pulvinar ipsum, nec porta magna ullamcorper ac. Donec efficitur elit eget lorem dictum, quis pretium leo congue. Aliquam
dictum leo vel tortor dapibus, sit amet viverra leo efficitur. Fusce ultricies sem quis accumsan dignissim. Phasellus aliquam nisl a malesuada tristique. Ut sed diam nec lectus pharetra gravida. Nulla vel dolor at est auctor eleifend ac nec arcu.
Suspendisse eget lobortis lacus. Nunc lobortis libero lectus, sed luctus erat eleifend sit amet. In at blandit leo. Curabitur congue mauris at ante interdum molestie. Nullam dignissim elementum purus id tempor. Donec id nisi a leo sollicitudin convallis.
Nulla quis suscipit lacus. Nam vitae ante quis nulla dignissim volutpat. Morbi nibh mi, placerat ac eleifend ac, malesuada nec ligula. Morbi finibus nibh augue, dapibus ultrices purus pretium ac. Quisque id vulputate sem, eu suscipit neque. Nunc et
augue at odio facilisis varius. Vivamus fermentum est ipsum, a tincidunt augue luctus at. Maecenas vel bibendum nunc. Quisque vitae sapien sit amet lorem gravida vehicula. Maecenas ac neque vestibulum, aliquam quam non, sagittis tellus. Nulla urna
risus, dictum sit amet ultricies ut, interdum nec ante.
</div>
</div>
There are different ways of solving this issue. However, I guess none of them just work exactly as you would expect.
The easiest way to solve your issue would be to give your body absolute positioning:
html {
overflow: auto;
background: blue;
}
body {
position: absolute;
top: 20px;
left: 20px;
bottom: 20px;
right: 20px;
padding: 30px;
overflow-y: scroll;
overflow-x: hidden;
}
Edit: As pointed out in the other answer you could also use margin to imitate this behavior.
You could also give your scrollbar the same border color as the background, e.g.
body {
scrollbar-width: thin;
scrollbar-color: var(--thumbBG) var(--scrollbarBG);
}
body::-webkit-scrollbar-track {
background: var(--scrollbarBG);
border-right: 15px solid blue;
}
body::-webkit-scrollbar-thumb {
background-color: var(--thumbBG) ;
border: 0px solid blue;
border-right: 15px solid blue;
}
Find more information about the Webkit Scrollbar at https://css-tricks.com/custom-scrollbars-in-webkit/
Related
I'm trying to have my text inside the 'container' div show up entirely but it seems to get cut off? .. It works if there is only a bit of text but if the text is more than 1 page it will cut it off.. Also the page seems to load very long because of the background image (defined in stylesheet.css) How do I fix this the best ? Thanks in advance!
* {
box-sizing: border-box;
}
#font-face {
font-family: 'zcool';
src: url('fonts/zcool.ttf') format('ttf');
local: url('fonts/zcool.ttf') format('ttf');
font-weight: normal;
font-style: normal;
}
html,
body {
height: 100%;
width: 100%;
}
body {
padding: 0;
margin: 0;
border: 0;
background-attachment: fixed;
background-size: 100% auto;
background-image: url("img/bg.png");
background-repeat: no-repeat;
background-size: 100% 100%;
}
#media (max-width: 768px) { /* when screen size is < 768px apply the following styles */
body {
padding: 0;
margin: 0;
border: 0;
background-attachment: fixed;
background-size: 100% auto;
background-image: url("img/bgm.png");
background-repeat: no-repeat;
background-size: 100% 100%;
}
}
ul#horizontal-list {
list-style: none;
}
ul#horizontal-list li {
display: inline;
}
ul {
margin: 0;
padding: 0;
overflow: hidden;
}
li {
float: center;
}
li a {
display: block;
color: white;
text-align: center;
padding: 16px;
text-decoration: none;
}
li a:hover {
background-color: red;
}
.navbar {
position: fixed;
top: 0;
height: 50px;
width: 100%;
background-color: black;
color: white;
text-align: center;
left: 0;
right: 0;
z-index: 1;
}
.navbar ul {
display: flex;
align-items: center;
justify-content: center;
list-style-type: none;
margin-top: 0px;
}
.header {
background-image: url(img/j.svg);
background-repeat: no-repeat;
background-size: 100% 100%;
height: 100%;
width: 100%;
margin-top: 10%;
margin-bottom: 10%;
}
#media (max-width: 768px) { /* when screen size is < 768px apply the following styles */
.header {
background-image: url("img/johnswork-mobile.svg");
background-repeat: no-repeat;
background-size: 100% 100%;
height: 100%;
width: 100%;
margin-top: 10%;
margin-bottom: 10%;
}
}
.body {
height: 100%;
width: 90%;
margin: auto;
padding: 0;
border: 0;
color: black;
padding-left: 5%;
padding-right: 5%;
overflow: hidden;
/*background-color: grey;*/
}
.johnswork {
background-image: url(img/johnswork.svg);
background-repeat: no-repeat;
background-size: 100% 100%;
height: 20%;
width: 100%;
margin-bottom: 5%;
}
.content {
margin: auto;
height: 100%;
width: 90%;
background-color: white;
color: black;
border-right: double;
border-left: double;
box-shadow: 0px -21px 28px 7px rgb(162, 27, 27);
text-align: justify;
font-size: 20px;
padding-top: 2%;
padding-bottom: 10%;
padding-left: 5%;
padding-right: 5%;
}
#media (max-width: 768px) { /* when screen size is < 768px apply the following styles */
.content {
margin: auto;
height: 100%;
width: 90%;
background-color: white;
color: black;
border-right: double;
border-left: double;
box-shadow: 0px -21px 28px 7px rgb(27, 125, 162);
text-align: justify;
font-size: 20px;
padding-top: 2%;
padding-bottom: 10%;
padding-left: 5%;
padding-right: 5%;
}
}
.social {
margin: auto;
display: flex;
justify-content: center;
}
.me {
float: left;
margin-right: 3%;
height: 100%;
}
.footer {
height: 50px;
width: 72%;
background-color: black;
color: white;
vertical-align: middle;
margin: auto auto 50px;
}
#copyright {
display: table;
}
#cpy{
display: table-cell;
vertical-align: middle;
}
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="stylesheet.css"/>
<!--<link rel="stylesheet" type="text/css" href="stylesheet-m.css" media="handheld" />-->
<link rel="icon" type="image/x-icon" href="img/favicon.ico"/>
<meta name="description" content="My Personal Portfolio">
<title>John's Work</title>
</head>
<body>
<nav class="navbar">
<ul>
<li>HOME</li>
<li>ABOUT</li>
<li>CONTACT</li>
</ul>
</nav>
<header class="header">
<!-- background defined in stylesheet.css-->
</header>
<section class="body">
<section class="content">
<section class="johnswork">
<!-- background defined in stylesheet.css-->
</section>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla ac ipsum non diam faucibus dignissim. Praesent a dolor tincidunt, rutrum diam ut, convallis orci. Maecenas eleifend, sapien id blandit rutrum, enim augue cursus magna, vitae varius orci nulla eu arcu. Cras ultrices condimentum libero nec vulputate. Praesent id ante dignissim, congue elit id, iaculis eros. Aliquam lacus quam, facilisis et pulvinar quis, hendrerit varius erat. Duis feugiat imperdiet lobortis. Ut et faucibus dui. Integer quis bibendum tortor, at mattis dolor. Sed id lacus nec nisi iaculis blandit. Duis nec ligula orci. Quisque tincidunt, orci id tincidunt consequat, eros erat dictum urna, vel ultricies sem nisl eu nunc. Nulla facilisi. Suspendisse at malesuada magna, in suscipit purus.
Fusce facilisis pharetra dui, ut cursus orci maximus non. Cras nec magna ac odio ornare ornare. Proin id commodo eros. Phasellus dui est, malesuada non mi sit amet, fringilla rhoncus ante. Phasellus non elit id est cursus malesuada. Maecenas accumsan erat in urna pulvinar, sit amet egestas felis facilisis. Nullam tincidunt porta nulla, a consectetur sapien venenatis in. Phasellus elementum est sit amet sem accumsan tincidunt. In semper vulputate risus, sed sollicitudin libero consectetur eget. Curabitur pulvinar eleifend augue. Sed facilisis ligula sed arcu vulputate tempus.
Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Ut mi nisi, mattis sed est a, luctus aliquet metus. Integer fringilla, massa nec laoreet dapibus, odio sem convallis massa, a vestibulum tellus mi in massa. Sed at vulputate velit, id sagittis sem. Vestibulum ac libero massa. Vivamus et libero vel orci auctor sodales a a quam. Vivamus semper tortor eget lacus euismod, non dignissim tellus feugiat. Donec tincidunt nisi at ornare ullamcorper. Nulla at mi nulla. Phasellus ligula ante, vehicula sit amet mauris et, consectetur mollis odio.
Donec massa risus, ultricies et enim quis, vestibulum consectetur arcu. Nunc sed convallis dui, sagittis imperdiet metus. Sed non ultrices velit. Nullam arcu sem, varius non pulvinar id, convallis eget erat. Nam porta tincidunt lorem, non venenatis sapien hendrerit vitae. Suspendisse nec est leo. Nunc commodo, lectus nec facilisis laoreet, ex velit dapibus dui, et aliquet lacus est non velit. Vestibulum nisl velit, tempor vel lacus at, ultricies pellentesque nisi. Mauris velit tortor, aliquam a magna eget, efficitur fringilla erat. Praesent massa nisl, maximus sit amet viverra in, varius vel urna.
Pellentesque eget leo vitae neque dictum egestas at ullamcorper nulla. Aenean lacinia venenatis metus, in faucibus dolor sollicitudin eget. Sed volutpat sit amet urna vel molestie. Donec dignissim velit tortor, a blandit ligula commodo dapibus. Vestibulum ac dolor facilisis mauris maximus mattis. Nullam vitae libero ut ligula sodales accumsan et vel dui. Quisque dapibus, lacus accumsan interdum efficitur, tellus augue maximus ipsum, quis ultricies dolor justo in diam. Pellentesque id lobortis diam. Suspendisse mollis eget orci eu auctor. Nullam porttitor arcu mi, nec varius magna viverra quis. Fusce eleifend sodales turpis et hendrerit.
</section>
</section>
<footer class="footer" id="copyright" style="text-align:center">
<div id="cpy">© DA COSTA JOAO (2019)</div>
</footer>
</body>
</html>
As for the text cutting off, the below css seems to fix it without cutting off the image.
.body{
height: auto;
}
As for the background image, it may be the file size. I usually use https://compressor.io/ to reduce my file sizes while maintaining image quality.
Getting rid of
html,
body {
height: 100%;
}
Seems to fix the problem of the text getting cut off.
I am assuming you want an image with text going around it. You can try this out!
.image-container {
float: left;
margin: 0px 20px 5px 0px;
<section class="content">
<div class="image-container">
<img src="https://images.pexels.com/photos/374811/pexels-photo-374811.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500" alt="">
</div>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla ac ipsum non diam faucibus dignissim. Praesent a dolor tincidunt, rutrum diam ut, convallis orci. Maecenas eleifend, sapien id blandit rutrum, enim augue cursus magna, vitae varius orci nulla
eu arcu. Cras ultrices condimentum libero nec vulputate. Praesent id ante dignissim, congue elit id, iaculis eros. Aliquam lacus quam, facilisis et pulvinar quis, hendrerit varius erat. Duis feugiat imperdiet lobortis. Ut et faucibus dui. Integer
quis bibendum tortor, at mattis dolor. Sed id lacus nec nisi iaculis blandit. Duis nec ligula orci. Quisque tincidunt, orci id tincidunt consequat, eros erat dictum urna, vel ultricies sem nisl eu nunc. Nulla facilisi. Suspendisse at malesuada magna,
in suscipit purus. Fusce facilisis pharetra dui, ut cursus orci maximus non. Cras nec magna ac odio ornare ornare. Proin id commodo eros. Phasellus dui est, malesuada non mi sit amet, fringilla rhoncus ante. Phasellus non elit id est cursus malesuada.
Maecenas accumsan erat in urna pulvinar, sit amet egestas felis facilisis. Nullam tincidunt porta nulla, a consectetur sapien venenatis in. Phasellus elementum est sit amet sem accumsan tincidunt. In semper vulputate risus, sed sollicitudin libero
consectetur eget. Curabitur pulvinar eleifend augue. Sed facilisis ligula sed arcu vulputate tempus. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Ut mi nisi, mattis sed est a, luctus aliquet metus. Integer
fringilla, massa nec laoreet dapibus, odio sem convallis massa, a vestibulum tellus mi in massa. Sed at vulputate velit, id sagittis sem. Vestibulum ac libero massa. Vivamus et libero vel orci auctor sodales a a quam. Vivamus semper tortor eget lacus
euismod, non dignissim tellus feugiat. Donec tincidunt nisi at ornare ullamcorper. Nulla at mi nulla. Phasellus ligula ante, vehicula sit amet mauris et, consectetur mollis odio. Donec massa risus, ultricies et enim quis, vestibulum consectetur arcu.
Nunc sed convallis dui, sagittis imperdiet metus. Sed non ultrices velit. Nullam arcu sem, varius non pulvinar id, convallis eget erat. Nam porta tincidunt lorem, non venenatis sapien hendrerit vitae. Suspendisse nec est leo. Nunc commodo, lectus
nec facilisis laoreet, ex velit dapibus dui, et aliquet lacus est non velit. Vestibulum nisl velit, tempor vel lacus at, ultricies pellentesque nisi. Mauris velit tortor, aliquam a magna eget, efficitur fringilla erat. Praesent massa nisl, maximus
sit amet viverra in, varius vel urna. Pellentesque eget leo vitae neque dictum egestas at ullamcorper nulla. Aenean lacinia venenatis metus, in faucibus dolor sollicitudin eget. Sed volutpat sit amet urna vel molestie. Donec dignissim velit tortor,
a blandit ligula commodo dapibus. Vestibulum ac dolor facilisis mauris maximus mattis. Nullam vitae libero ut ligula sodales accumsan et vel dui. Quisque dapibus, lacus accumsan interdum efficitur, tellus augue maximus ipsum, quis ultricies dolor
justo in diam. Pellentesque id lobortis diam. Suspendisse mollis eget orci eu auctor. Nullam porttitor arcu mi, nec varius magna viverra quis. Fusce eleifend sodales turpis et hendrerit.
</p>
</section>
I used column-count, but it looks like I found a bug when an element has an absolute position and overflowed from the parent.
#master {
column-count: 2;
}
.Books {
display: table;
column-break-inside: avoid;
-webkit-column-break-inside: avoid;
}
JSFiddle
There are two issues. One, the two red elements are not balanced (see the purple line) and second, the red element dropped on the bottom.
Just add margin-top: -1px; in the .bookmarkAds class.
And margin-top: 10px; in .books class .
#master {
column-count: 2;
}
#rule {
position: absolute;
width: 100%;
height: 1px;
background: #9C27B0;
top: 7px;
left: 0;
}
.Books {
width: 100%;
font-family: tahoma;
font-size: 12px;
border: 1px solid #ddd;
line-height: 150%;
background: #FFFFF6;
float: right;
box-sizing: border-box;
padding: 5px 5px 10px 5px;
margin: 3px;
margin-top: 10px;
position: relative;
display: table;
column-break-inside: avoid;
-webkit-column-break-inside: avoid;
min-height: 200px;
}
.bookmarkAds {
margin-top: -1px;
position: absolute;
left: 4px;
color: #9e9e9e;
cursor: pointer;
text-shadow: 1px 2px 2px rgba(0, 0, 0, 0.30);
top: -10px;
font-size: 22px;
background: red;
}
<div id="rule"></div>
<div id="master">
<div class="Books">
<div id="Bookmark" class="bookmarkAds RedHeart" title="" data-id="653373">x</div>
Lorem ipsum dolor sit amet, duis mattis pharetra vehicula nec phasellus sed, vestibulum mauris porttitor ipsum nostra tellus, bibendum aliquam nibh, libero elementum ut suspendisse ante dolor sit, erat quis tellus iaculis mauris sed. Nam fusce hac in metus facilisis, dictum urna nulla nulla, metus porttitor donec irure facilisis, curabitur sed id sapien gravida, eu a dolor autem et. Varius sollicitudin odio ut, eget maecenas, lacinia lobortis adipiscing id praesent orci varius, bibendum euismod tenetur pellentesque, in justo et massa nisl. Odio quis eget mauris dui consectetuer, lorem mi quis mollis arcu, ullamcorper lobortis sem, cras urna lacus sed eu. Nec taciti aliquet, praesent risus rutrum ac, sagittis eu. Sit id a, vel ultrices parturient etiam magna at. Phasellus hendrerit lacinia ac eros.
</div>
<div class="Books">
<div id="Bookmark" class="bookmarkAds RedHeart" title="" data-id="653373">x</div>
Lorem ipsum dolor sit amet, duis mattis pharetra vehicula nec phasellus sed, vestibulum mauris porttitor ipsum nostra tellus, bibendum aliquam nibh, libero elementum ut suspendisse ante dolor sit, erat quis tellus iaculis mauris sed. Nam fusce hac in metus facilisis, dictum urna nulla nulla, metus porttitor donec irure facilisis, curabitur sed id sapien gravida, eu a dolor autem et. Varius sollicitudin odio ut, eget maecenas, lacinia lobortis adipiscing id praesent orci varius, bibendum euismod tenetur pellentesque, in justo et massa nisl. Odio quis eget mauris dui consectetuer, lorem mi quis mollis arcu, ullamcorper lobortis sem, cras urna lacus sed eu. Nec taciti aliquet, praesent risus rutrum ac, sagittis eu. Sit id a, vel ultrices parturient etiam magna at. Phasellus hendrerit lacinia ac eros.
Lorem ipsum dolor sit amet, duis mattis pharetra vehicula nec phasellus sed, vestibulum mauris porttitor ipsum nostra tellus, bibendum aliquam nibh, libero elementum ut suspendisse ante dolor sit, erat quis tellus iaculis mauris sed. Nam fusce hac in metus facilisis, dictum urna nulla nulla, metus porttitor donec irure facilisis, curabitur sed id sapien gravida, eu a dolor autem et. Varius sollicitudin odio ut, eget maecenas, lacinia lobortis adipiscing id praesent orci varius, bibendum euismod tenetur pellentesque, in justo et massa nisl. Odio quis eget mauris dui consectetuer, lorem mi quis mollis arcu, ullamcorper lobortis sem, cras urna lacus sed eu. Nec taciti aliquet, praesent risus rutrum ac, sagittis eu. Sit id a, vel ultrices parturient etiam magna at. Phasellus hendrerit lacinia ac eros.
</div>
</div>
This is the way column-count works. Add margin-top: 10px; to your .Books class and the issue will be fixed. Like this: https://jsfiddle.net/x6ms3nxr/5/
Red element dropped to the bottom is actually a part of bookmark from second column that is cut and gone to the first column.
Some additional details regarding columns support in browsers can be found here:
http://zomigi.com/blog/deal-breaker-problems-with-css3-multi-columns/
The goal is to set a single contiguous outline around a <span> nested within a <p> and <div>. I found this solution: CSS/Javascript: How to draw minimal border around an inline element? which only works if there is no line-height set on any elements. Is it possible to draw a single outline (pictured) while preserving my line height? mockup of desired result
Here's my code:
.note_text_theme {
outline: 2px solid blue;
outline-style: dashed;
}
.note_text_theme span {
border: 1px solid white;
background-color: white;
position: relative;
z-index: 1000;
}
p {
margin: 10px;
}
.text_paragraph {
font-size: 18px;
line-height: 170%;
}
<div class="text_paragraph">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin id lobortis purus. Nunc nibh metus, dictum sit amet mi sed, sagittis fermentum mauris. Mauris tincidunt lectus quam, quis tincidunt mi finibus at. <span class="note_text_theme">Cras feugiat accumsan magna, vel malesuada sem pulvinar nec. Curabitur a sem quis metus sodales rhoncus. Phasellus tempus ante magna, a gravida est pellentesque sed. Nam volutpat tortor nec lobortis aliquam. Fusce ornare pharetra tristique. Cras fringilla, nunc ac lobortis posuere, libero est</span>
<span></span>blandit justo, ut placerat nisl erat viverra odio. Praesent finibus viverra neque, quis feugiat felis porttitor a. Vestibulum ante ipsum primis in faucibus orci luctus.
</p>
</div>
You'll notice that if the line-height property is commented out, the outline behaves as desired. This property is commented out in the snippet below.
.note_text_theme {
outline: 2px solid blue;
outline-style: dashed;
}
.note_text_theme span {
border: 1px solid white;
background-color: white;
position: relative;
z-index: 1000;
}
p {
margin: 10px;
}
.text_paragraph {
font-size: 18px;
//line-height: 170%;
}
<div class="text_paragraph">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin id lobortis purus. Nunc nibh metus, dictum sit amet mi sed, sagittis fermentum mauris. Mauris tincidunt lectus quam, quis tincidunt mi finibus at. <span class="note_text_theme">Cras feugiat accumsan magna, vel malesuada sem pulvinar nec. Curabitur a sem quis metus sodales rhoncus. Phasellus tempus ante magna, a gravida est pellentesque sed. Nam volutpat tortor nec lobortis aliquam. Fusce ornare pharetra tristique. Cras fringilla, nunc ac lobortis posuere, libero est</span>
<span></span>blandit justo, ut placerat nisl erat viverra odio. Praesent finibus viverra neque, quis feugiat felis porttitor a. Vestibulum ante ipsum primis in faucibus orci luctus.
</p>
</div>
Add a padding to the note_text_theme to adjust for the increased line-height
.note_text_theme {
outline: 2px solid blue;
outline-style: dashed;
padding: 5px 0px;
}
.note_text_theme span {
border: 1px solid white;
background-color: white;
position: relative;
z-index: 1000;
}
p {
margin: 10px;
}
.text_paragraph {
font-size: 18px;
line-height: 170%;
}
<div class="text_paragraph">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin id lobortis purus. Nunc nibh metus, dictum sit amet mi sed, sagittis fermentum mauris. Mauris tincidunt lectus quam, quis tincidunt mi finibus at. <span class="note_text_theme">Cras feugiat accumsan magna, vel malesuada sem pulvinar nec. Curabitur a sem quis metus sodales rhoncus. Phasellus tempus ante magna, a gravida est pellentesque sed. Nam volutpat tortor nec lobortis aliquam. Fusce ornare pharetra tristique. Cras fringilla, nunc ac lobortis posuere, libero est</span>
<span></span>blandit justo, ut placerat nisl erat viverra odio. Praesent finibus viverra neque, quis feugiat felis porttitor a. Vestibulum ante ipsum primis in faucibus orci luctus.
</p>
</div>
I'm currently having trouble with http://jsfiddle.net/XB2r7/6/, or:
.content {
margin-right: auto;
margin-left: auto;
background-color:rgba(64,64,64,0.9);
width: 1000px;
height: auto;
padding-top: 10px;
padding-left: 10px;
padding-right: 10px;
padding-bottom: 10px;
border: 1px solid #333;
color: #fff;
overflow: auto;
margin-bottom: 20px;
box-shadow: 0px 1px 1px #333;
}
.clear {
clear: both;
}
.sidebar {
width: 23.5%;
height: auto;
display: block;
float: left;
color: #000;
padding-left: 5px;
padding-top: 5px;
padding-right: 5px;
padding-bottom: 5px;
margin-bottom: 10px;
background-color: rgba(255,255,255,0.9);
}
.content2 {
width: 73.5%;
height: auto;
display: block;
float: right;
color: #000;
padding-left: 5px;
padding-top: 5px;
padding-right: 5px;
padding-bottom: 5px;
margin-bottom: 10px;
background-color: rgba(255,255,255,0.9);
}
.h1 {
font-weight: bold;
}
.content hr {
border: 0;
height: 2px;
background: url('bg3.jpg');
}
As you can see at JSFiddle the sidebar is going down as I place a second content2-div. Is there a way to fix this without placing it both in other containers?
Remove float:left from .sidebar class
.sidebar {
float:left; /*remove*/
}
Demo
I've updated your fiddle.
Just removed .sidebar {float:left}
try this
<div class="content">
<div class="sidebar">
<h1>Consectetur adipiscing elit.</h1>
<hr>
Morbi vel porttitor augue, eu rhoncus massa. Vivamus venenatis, arcu at euismod semper, ipsum nunc interdum ante, in semper mauris metus eu risus. Aliquam nibh massa, venenatis in turpis vitae, tempor lacinia metus. Vestibulum sed metus ut lectus lacinia tincidunt ac eu erat. Phasellus eu fermentum lacus. Duis vitae bibendum magna, a ullamcorper libero. In hac habitasse platea dictumst. Phasellus molestie nisl id lectus blandit, ac rhoncus dui pellentesque. Praesent sit amet tempus turpis, eu elementum mauris. Sed ipsum dui, luctus eu vehicula id, eleifend nec libero. Donec.
<h1>Consectetur adipiscing elit.</h1>
<hr>
Morbi vel porttitor augue, eu rhoncus massa. Vivamus venenatis, arcu at euismod semper, ipsum nunc interdum ante, in semper mauris metus eu risus. Aliquam nibh massa, venenatis in turpis vitae, tempor lacinia metus. Vestibulum sed metus ut lectus lacinia tincidunt ac eu erat. Phasellus eu fermentum lacus. Duis vitae bibendum magna, a ullamcorper libero. In hac habitasse platea dictumst. Phasellus molestie nisl id lectus blandit, ac rhoncus dui pellentesque. Praesent sit amet tempus turpis, eu elementum mauris. Sed ipsum dui, luctus eu vehicula id, eleifend nec libero. Donec.
</div>
<div class="content2">
<h1>Duis ac felis neque. Ut leo massa, hendrerit et nulla at.</h1>
<hr>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque aliquet leo at eros convallis rhoncus. Sed malesuada tincidunt dolor, nec ornare sem tincidunt vel. Maecenas placerat ipsum eu quam semper, eu tincidunt felis fringilla. Ut placerat vehicula vulputate. Sed id ultricies odio, eu congue nisi. Vivamus venenatis mauris id urna ullamcorper, ut posuere ipsum sodales. Proin gravida varius urna eu eleifend. Praesent a interdum sapien. Cras scelerisque nisi sit amet nibh convallis bibendum a eu diam. Nam porttitor elementum fringilla. Etiam accumsan dictum metus vitae cursus.
<br><br>
Vivamus ante mi, tincidunt quis commodo tempor, consequat vel nisl. Phasellus vestibulum elit a dui laoreet, nec congue velit vulputate. Interdum et malesuada fames ac ante ipsum primis in faucibus. Nam condimentum orci sit amet orci imperdiet gravida. Proin porta luctus quam, quis bibendum urna lobortis porttitor. Pellentesque nec lobortis ipsum. Pellentesque sit amet felis quis risus luctus semper in id ante. Nullam condimentum neque eget sollicitudin interdum. Duis imperdiet enim felis, in facilisis nisl facilisis at. Aliquam ut enim vehicula ligula dignissim molestie. Quisque dignissim quis ante ut eleifend. Suspendisse vitae mi vitae ligula interdum egestas ut sed nibh.
<br><br>
Mauris sit amet egestas augue. Aliquam ultrices tristique dolor vel luctus. Vestibulum cursus eleifend magna nec varius. Sed cursus magna in mi feugiat eleifend id quis purus. Fusce sollicitudin ultricies augue ac viverra. Curabitur tempor feugiat justo eu porta. Suspendisse eu sollicitudin ipsum. Proin rutrum turpis id massa molestie sollicitudin. Maecenas sit amet justo cursus, blandit mi sit amet, scelerisque quam. Nam ut arcu fringilla, sodales nibh sed, sodales elit. Nam vel tortor sed erat interdum sollicitudin sed non libero. Donec tristique, justo id interdum fermentum, lacus augue dictum nisl, sit amet adipiscing est enim vitae neque.
</div>
<div class="content2">
<h1>Duis ac felis neque. Ut leo massa, hendrerit et nulla at.</h1>
<hr>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque aliquet leo at eros convallis rhoncus. Sed malesuada tincidunt dolor, nec ornare sem tincidunt vel. Maecenas placerat ipsum eu quam semper, eu tincidunt felis fringilla. Ut placerat vehicula vulputate. Sed id ultricies odio, eu congue nisi. Vivamus venenatis mauris id urna ullamcorper, ut posuere ipsum sodales. Proin gravida varius urna eu eleifend. Praesent a interdum sapien. Cras scelerisque nisi sit amet nibh convallis bibendum a eu diam. Nam porttitor elementum fringilla. Etiam accumsan dictum metus vitae cursus.
<br><br>
Vivamus ante mi, tincidunt quis commodo tempor, consequat vel nisl. Phasellus vestibulum elit a dui laoreet, nec congue velit vulputate. Interdum et malesuada fames ac ante ipsum primis in faucibus. Nam condimentum orci sit amet orci imperdiet gravida. Proin porta luctus quam, quis bibendum urna lobortis porttitor. Pellentesque nec lobortis ipsum. Pellentesque sit amet felis quis risus luctus semper in id ante. Nullam condimentum neque eget sollicitudin interdum. Duis imperdiet enim felis, in facilisis nisl facilisis at. Aliquam ut enim vehicula ligula dignissim molestie. Quisque dignissim quis ante ut eleifend. Suspendisse vitae mi vitae ligula interdum egestas ut sed nibh.
<br><br>
Mauris sit amet egestas augue. Aliquam ultrices tristique dolor vel luctus. Vestibulum cursus eleifend magna nec varius. Sed cursus magna in mi feugiat eleifend id quis purus. Fusce sollicitudin ultricies augue ac viverra. Curabitur tempor feugiat justo eu porta. Suspendisse eu sollicitudin ipsum. Proin rutrum turpis id massa molestie sollicitudin. Maecenas sit amet justo cursus, blandit mi sit amet, scelerisque quam. Nam ut arcu fringilla, sodales nibh sed, sodales elit. Nam vel tortor sed erat interdum sollicitudin sed non libero. Donec tristique, justo id interdum fermentum, lacus augue dictum nisl, sit amet adipiscing est enim vitae neque.
</div>
</div>
Change the order of your HTML elements:
http://jsfiddle.net/XB2r7/6/
<div class="content"></div>
<div class="sidebar"></div>
<div class="content"></div>
<div class="sidebar"></div>
try this in your css file :
.content {
margin-right: auto;
margin-left: auto;
background-color:rgba(64,64,64,0.9);
width: 1000px;
height: auto;
padding-top: 10px;
padding-left: 10px;
padding-right: 10px;
padding-bottom: 10px;
border: 1px solid #333;
color: #fff;
overflow: auto;
margin-bottom: 20px;
box-shadow: 0px 1px 1px #333;
}
.clear {
clear: both;
}
.sidebar {
width: 23.5%;
height: auto;
display: block;
color: #000;
padding-left: 5px;
padding-top: 5px;
padding-right: 5px;
padding-bottom: 5px;
margin-bottom: 10px;
background-color: rgba(255,255,255,0.9);
}
.content2 {
width: 73.5%;
height: auto;
display: block;
float: right;
color: #000;
padding-left: 5px;
padding-top: 5px;
padding-right: 5px;
padding-bottom: 5px;
margin-bottom: 10px;
background-color: rgba(255,255,255,0.9);
}
.h1 {
font-weight: bold;
}
.content hr {
border: 0;
height: 2px;
background: url('bg3.jpg');
}
it works :
I am looking to position the box that is floating on the right of the window on the following page.
http://mikegeorge.org/acej/index.html
I would like to position this relative to the white div with all the text in it, so instead of it being attached to the side of the window, it floats maybe 10-20px away from the content area.
CSS Source
#float-box {
position: fixed;
right: 10px;
top: 100px;
width: 150px;
padding: 10px 5px;
text-align: center;
background-color: #fff;
border: 5px solid rgba(180, 180, 180, .7);
-webkit-border-radius: 8px;
-moz-border-radius: 8px;
border-radius: 8px;
display: none;
}
.fb-1 {
height: 62px;
margin-bottom: 10px;
}
.fb-2 {
height: 60px;
margin-bottom: 10px;
}
.fb-3 {
height: 60px;
}
Thanks for your help!
You will need to put social-float inside wrapper div and update its style right:-160px. 160px is the width of social-float and 10px more is extra margin. And don't forget to add position:relative to #wrapper
Please replace social-float css with below
position: fixed;
left: 50%;
top: 100px;
width: 150px;
padding: 10px 5px;
text-align: center;
background-color:
white;
border: 5px solid
rgba(180, 180, 180, .7);
-webkit-border-radius: 8px;
-moz-border-radius: 8px;
border-radius: 8px;
display: none;
margin-left: 380px;
Please replace your style for social-float id with this:
#social-float {
background-color: #FFFFFF;
border: 5px solid rgba(180, 180, 180, 0.7);
border-radius: 8px 8px 8px 8px;
display: none;
float: right;
margin-left: 715px;
padding: 10px 5px;
position: fixed;
text-align: center;
top: 100px;
width: 150px;
}
move your div inside #Wraper,
<div id="wrapper">
<p>Curabitur id neque eget justo ultrices semper. Suspendisse eget sapien eros, sed dapibus justo. Fusce ullamcorper, felis vitae consequat malesuada, tortor metus mattis ligula, nec pellentesque nisl sapien vel velit. Sed augue sem, malesuada ut elementum dictum, blandit vitae lorem. Aliquam eu nulla neque, vitae feugiat tortor. In id augue nisl. Donec congue arcu vel mi semper sit amet porttitor tortor condimentum. Donec non eros tempor dolor bibendum venenatis. Donec ornare imperdiet leo, non venenatis odio mollis et. Suspendisse in sapien eu sapien egestas elementum. </p>
<p>Sed cursus consequat euismod. Pellentesque sagittis, odio et luctus sagittis, tellus mauris malesuada leo, in tincidunt nisl urna ac urna. Morbi vestibulum faucibus elit vel volutpat. Aliquam erat volutpat. Donec posuere velit vitae risus mattis molestie. Curabitur posuere egestas justo, quis iaculis leo convallis ut. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Ut tristique augue et leo consectetur in porttitor felis euismod. Aliquam ac mi condimentum arcu euismod molestie.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus porttitor adipiscing turpis, eu tristique tellus congue sit amet. In non ipsum risus. In hac habitasse platea dictumst. Sed eu mauris nulla. Ut vitae arcu urna, eu sodales enim. Curabitur porta elementum diam at adipiscing. Sed consectetur convallis neque, eu fermentum lectus mattis in. Ut tristique feugiat elementum. Quisque rutrum dui quis massa commodo id tempor dui vulputate. </p>
<p>In nisi felis, venenatis at pellentesque et, bibendum eget justo. Sed imperdiet commodo rutrum. Proin massa felis, porttitor et commodo at, semper eu sapien. Curabitur eu neque libero. Proin consequat sagittis felis, ut ultricies orci auctor eget. Sed a vehicula risus. Vivamus nulla nisi, lobortis a semper nec, lobortis vel felis. Cras et sem magna, vel ullamcorper justo. Quisque volutpat massa eget leo blandit ultricies eget non nisl. Nunc vel lacus quis risus placerat consectetur vitae quis lectus. Nullam a ante ut nibh facilisis viverra. Nullam mollis, risus sit amet eleifend mattis, massa lorem tempor mauris, sed dictum nisl enim accumsan velit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam in faucibus enim. Nulla at mi orci, vel commodo felis. Donec ac tristique ante. </p>
<p>Nunc eu tellus lectus. Vivamus tellus orci, scelerisque a gravida id, suscipit ut purus. Duis eu elit magna. Mauris quis tellus tellus. Fusce sed lorem in lectus aliquam cursus. Etiam orci lectus, fringilla sed imperdiet id, pharetra ut nisi. In hac habitasse platea dictumst. Vestibulum sed metus vel justo pulvinar vehicula ut lobortis mi. Cras viverra porta enim et malesuada. Quisque ullamcorper justo turpis, eu consequat ligula. Nam eget massa enim, in dictum felis. Nam cursus augue eu augue dignissim venenatis. Vestibulum in dignissim odio. Vivamus pulvinar, diam in tempor varius, tortor dolor tempus arcu, vel fringilla lectus eros at mi. </p>
**<div id="social-float" style="display: block; ">
<div class="sf-twitter">
Yo! Sign up fo' this!
</div>
<div class="sf-facebook">
You know you want to!
</div>
<div class="sf-plusone">
Click Me, Por Favor!
</div>
</div>**
</div>
use below css,
#social-float {
left: 1020px;
top: 100px;
width: 150px;
padding: 10px 5px;
text-align: center;
background-color:
white;
border: 5px solid
rgba(180, 180, 180, .7);
-webkit-border-radius: 8px;
-moz-border-radius: 8px;
border-radius: 8px;
display: none;
}