I have a button in a sidebar div which I want to position so half of it sticks out of the container. The problem is because the sidebar needs its own scrollbar this makes the button get cut off. Example here: http://jsfiddle.net/z5dy7t4x/19/
Why does the button get cut off when adding overflow-y: scroll; to the container?
Is it possible to show the button without modifying the HTML?
Couldn't figure out a CSS only solution. Solved it by adding an inner container and putting the scroll on that. Working example: http://jsfiddle.net/37ow2pqy/2/
<div class="sidebar">
<button class="close">
CLOSE
</button>
<div class="sidebar-content">
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Voluptatum enim nulla incidunt illo, at consequuntur eaque distinctio, dolorem, nemo quam ipsum accusantium vitae! Nam rem, dolor quod quas nobis, dolorem veniam molestias laboriosam blanditiis autem sequi tenetur, dolore distinctio beatae voluptates doloremque excepturi officia ratione quisquam. Eveniet aperiam rerum iusto, odit excepturi saepe, ullam et quo sint, delectus vel velit repellat quibusdam aut earum architecto corrupti? Dignissimos ullam sit autem numquam nihil adipisci dicta non officiis, tenetur excepturi hic ex saepe corporis animi asperiores nesciunt quo, voluptate libero sapiente. Totam, modi quaerat! Exercitationem fuga autem magnam id repudiandae doloremque voluptatem?
</div>
</div>
.sidebar{
width: 300px;
border: 1px solid #000;
position: absolute;
right: 0;
}
.close {
position: absolute;
top: 20px;
left: -25px;
}
.sidebar-content {
overflow-y: scroll;
height: 300px;
}
You added position absolute for the button, that's why your button is hidden
#parent{
position: absolute;
right: 0;
}
#close {
background-color: red;
color: white;
position: absolute;
left: -50px;
}
#child{
border: solid 1px black;
width: 200px;
height: 200px;
overflow-y: scroll;
margin-left: auto;
margin-right: auto;
}
<div id=parent>
<button id=close>
abololute child
</button>
<div id=child>
This is the child
</div>
</div>
Error to be addressed first:
In your CSS, you have position: relative;, and also position: absolute;, the latter being the one I believe you are going for, you need to remove the position: relative;.
Your First Question
Why does the button get cut off when adding overflow-y: scroll; to the container?
Because, by default, overflow is set to overflow: visible;, so you are changing that (overflow-y of course, being part of overflow).
Your Second Question
Is it possible to show the button without modifying the HTML?
Well, if you want the button halfway outside the <div>'s box, I would guess that you don't want the button to scroll with the content. If this is the case, then you will need to put the <button>...</button> outside of the <div> that the content (Lorem ipsum, etc.) is in (and change its positioning).
(Another way is to just use position: fixed; instead, but I seriously doubt that that's what you want)
Here it is:
.box{
width: 300px;
border: 1px solid Black;
position: absolute;
right: 0;
}
#close {
position: absolute;
top: 20px;
left: -31px;
}
.content {
overflow-y: scroll;
height: 250px;
}
<div class="box">
<button id="close">
CLOSE
</button>
<div class="content">
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Voluptatum enim nulla incidunt illo, at consequuntur eaque distinctio, dolorem, nemo quam ipsum accusantium vitae! Nam rem, dolor quod quas nobis, dolorem veniam molestias laboriosam blanditiis autem sequi tenetur, dolore distinctio beatae voluptates doloremque excepturi officia ratione quisquam. Eveniet aperiam rerum iusto, odit excepturi saepe, ullam et quo sint, delectus vel velit repellat quibusdam aut earum architecto corrupti? Dignissimos ullam sit autem numquam nihil adipisci dicta non officiis, tenetur excepturi hic ex saepe corporis animi asperiores nesciunt quo, voluptate libero sapiente. Totam, modi quaerat! Exercitationem fuga autem magnam id repudiandae doloremque voluptatem?
</div>
</div>
Related
Making a Reactjs app. Referring to the code, I would like to make the height of the colorTab div, equal and responsive to that of the content div. The height of content must be dynamic given that I would like it to be defined by the amount of text in tile + description, which is variable, and the width of the window.
Currently, when I omit min-height from colorTab's CSS and simply have height: 100%; defining colorTab's height, colorTab disappears. Adding the min-height gives it that height but then it becomes unresponsive to the height of content which is the goal. How do I solve this issue?
JSX:
<div className="wrapper">
<div className="colorTab" style={color}>
</div>
<div className="content">
<tr>
<td className="title">
<a href={link}>{title}</a>
</td>
</tr>
<tr>
<td className="description">
{description}
</td>
</tr>
</div>
</div>
CSS:
.wrapper {
min-height: 48px;
overflow: hidden;
}
.colorTab {
float: left;
position: relative;
width: 5px;
min-height: 48px;
height: 100%;
border-radius: 5px;
margin-left: 15px;
}
.title {
padding-top: 0 !important;
padding-bottom: 0 !important;
}
.description {
padding-top: 0 !important;
padding-bottom: 0 !important;
}
Flexbox will offer the functionality you need.
Put display: flex on your container class. And flex: 1 on your content div. No matter how much content you place in the content div the colorTab div will match its height.
Example in pure HTML/CSS (no React):
.wrapper {
overflow: hidden;
display: flex;
}
.colorTab {
position: relative;
width: 5px;
border-radius: 5px;
background: red;
}
.content {
flex: 1;
}
<div class="wrapper">
<div class="colorTab">
</div>
<div class="content">
<div class="title">
<a>Your Title</a>
</div>
<div class="description">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Rem nam perspiciatis aperiam mollitia obcaecati molestiae, consequuntur saepe repellendus cumque aliquid. Ullam reiciendis praesentium repellendus ipsam, qui illum. At, aliquid quidem. Reprehenderit eligendi voluptatem maiores deleniti id nulla, pariatur ipsa ducimus accusantium! Unde ea nostrum eligendi suscipit impedit, laborum adipisci accusamus ducimus temporibus eius inventore optio officia reiciendis porro eos assumenda numquam velit obcaecati. Perferendis, ipsum! Facilis fuga dolorum nobis nihil illo nam, voluptate suscipit excepturi sunt non. Modi perferendis ex illum eaque pariatur laudantium saepe accusantium vel, blanditiis, aperiam odit! Suscipit ullam, necessitatibus est distinctio obcaecati, odio ipsa blanditiis consequatur.
</div>
</div>
Now, I would absolutely recommend the flexbox mentioned in the other answer but...
but for some other outdated browsers which do not support it (cough
cough looking at you, grandpa, using that same old version of IE)... it
might be good idea to provide extra version support.
So, for answer's completion sake:
The other option is to utilize the tables.
.wrapper {
display: table;
}
.description {
display: table-cell;
}
.colorTab {
display: table-cell;
width: 5px;
border-radius: 5px;
background: red;
}
// not necessary, but for esthetic reasons
.content {
position: relative;
left: 10px;
}
<div class="wrapper">
<div class="colorTab">
</div>
<div class="content">
<div class="title">
<a>Your Title</a>
</div>
<div class="description">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Rem nam perspiciatis aperiam mollitia obcaecati molestiae, consequuntur saepe repellendus cumque aliquid. Ullam reiciendis praesentium repellendus ipsam, qui illum. At, aliquid quidem. Reprehenderit eligendi voluptatem maiores deleniti id nulla, pariatur ipsa ducimus accusantium! Unde ea nostrum eligendi suscipit impedit, laborum adipisci accusamus ducimus temporibus eius inventore optio officia reiciendis porro eos assumenda numquam velit obcaecati. Perferendis, ipsum! Facilis fuga dolorum nobis nihil illo nam, voluptate suscipit excepturi sunt non. Modi perferendis ex illum eaque pariatur laudantium saepe accusantium vel, blanditiis, aperiam odit! Suscipit ullam, necessitatibus est distinctio obcaecati, odio ipsa blanditiis consequatur.
</div>
</div>
So I have a fixed div with title and image below the title, and I want to then have another div, in the flow immediately under the fixed div. The fixed div with title and image will change size as the browser width changes, up to a maximum width of 700px. As the fixed div with image changes size the div containing text under the fixed div should maintain a a relative position below the bottom of the image.
I've tried implementing a wrapper around the fixed div, and also tried margin-top for the div containing the text but no matter what I try the text flows under the fixed div.
Any help on what I'm doing wrong would be much appreciated! This is what I currently have:
html, body {
height: 100%;
width:100%;
}
.container {
width: 100%;
margin: 0 auto;
max-width: 700px;
}
.title-wrapper {
width: 100%;
position: fixed;
}
.title {
width:100%;
max-width: 700px;
}
.image {
width: 100%;
}
.image img {
width:100%;
}
.text {
text-align: center;
}
h2 {
text-align: center;
background-color: grey;
width: 100%;
}
h3 {
text-align: center;
background-color: green;
width: 100%;
max-width: 700px;
}
<body>
<div class="container">
<div class="title-wrapper">
<div class="title">
<h2>Planes</h2>
<div class="image">
<img src="https://images.pexels.com/photos/47044/aircraft-landing-reach-injection-47044.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb" alt="Plane1">
<!-- <img src="https://images.pexels.com/photos/40753/military-raptor-jet-f-22-airplane-40753.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb" alt="Plane2">
<img src="https://images.pexels.com/photos/164646/pexels-photo-164646.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb" alt="Plane3"> -->
</div>
</div>
</div>
<div class="text">
<div>
<h3>TEXT 1</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Praesentium veniam consequuntur libero? Explicabo consectetur rerum odit? Qui ea dolore culpa. Provident, exercitationem reiciendis voluptatum nulla quo nihil iste? Non doloremque officia ex dicta, ea molestias corporis. Quisquam, tenetur! Consequatur totam quaerat ullam incidunt quas nostrum expedita, quidem iste tempora est blanditiis corrupti sunt id! Esse necessitatibus non harum, ad quisquam unde, eius placeat est explicabo ex repudiandae suscipit, ipsum tempora a quibusdam facere porro officia magnam dolorum fuga iste. Quam, consequatur provident reiciendis quis doloribus at hic itaque soluta maiores libero voluptas assumenda, ut alias mollitia corrupti nulla fuga autem sapiente recusandae, aspernatur ad sed quasi earum. Nostrum, alias veritatis est qui quae ratione. Dignissimos et eum modi, beatae odio porro totam, minus debitis eius expedita mollitia ea est veritatis, ut possimus delectus! Nesciunt, ad quos quasi soluta error cum veritatis aliquam, temporibus optio, commodi fuga perferendis aperiam dignissimos debitis?</p>
</div>
</div>
</div>
</body>
Use z-index to control the stacking context. You can also use planes image as background on .text div.
CSS for z-index below:
.title-wrapper {
width: 100%;
position: fixed;
z-index: 1;
}
.text {
text-align: center;
position: relative;
z-index: 10;
}
I want to wrap text in oval shape arround an image but the text keep overlapping over the image. I tried changind the border-radius, width and height properties etc. of the wraping element (i.e image) but it doesn't work. Below is my html and css code:
Html:
<div id="circular-shape">
<img src="blackberries-basket.jpg" class="curve">
<p>/*...text to wrap around circle side...*/
</p>
</div>
CSS:
#circular-shape {
font-family: Open Sans, sans-serif;
margin: 2rem;
}
#circular-shape p {
line-height: 1.8;
}
#circular-shape .curve {
width: 33%;
height: 33%;
min-width: 250px;
float: left;
border-radius: 50%;
-webkit-shape-outside:circle();
shape-outside:circle();
}
How can I stop the text from touching/overlapping the image at the left.Please help.
Just add margin:
img {
float: left;
margin: .5em;
border-radius: 50%;
-webkit-shape-outside: circle(50%);
shape-outside: circle(50%);
}
<div class="wrap">
<img src="http://www.fillmurray.com/g/100/100" alt="" />
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cupiditate ipsam harum enim omnis, iure laboriosam perferendis neque minima aspernatur culpa recusandae sunt quae minus, est quo ipsum ipsa laborum aperiam itaque facere sequi similique dignissimos
repellendus excepturi! Doloribus, voluptate! Voluptatibus facere nisi nesciunt aliquid maxime vitae soluta earum sint quis distinctio, molestias quod dicta deleniti debitis accusantium at fugiat illum voluptatum dignissimos dolore temporibus obcaecati
sunt non. Amet, et? Consequatur iusto nihil blanditiis amet placeat deleniti perspiciatis odit esse officia, dolor molestiae illum quo maiores quia nam delectus ut libero temporibus eveniet aperiam, nemo cupiditate, similique porro reprehenderit.
Molestiae, perspiciatis!</p>
</div>
Add this to your CSS
p {
position: relative;
left: 35px;
}
Increase the pixels if you want to.
This question already has answers here:
Margin on child element moves parent element
(18 answers)
Closed 6 years ago.
Well, now I've this problem, I want to adjust just the margin on the "c2" but when I set it to X, it changes the "c1" div margin :S
Here's the code I'm using:
<header>
<div class="jumbotron">
<center><h1>Bienvenidos a JVasconcelos.me</h1></center>
</div>
</header>
<div class="container">
<div class="row">
<div class="col-md-12 col-centered">
<div class="c1">
<div class="c2">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quis inventore illum quaerat laboriosam eos, vel sed suscipit cumque laborum est animi aliquid tempora iusto beatae quam quisquam porro dolore! Ullam tenetur doloribus ducimus, totam voluptatum, deleniti vero voluptatem eius architecto velit neque voluptas aliquam quidem sed eveniet! Nobis ex eos iste dolorum tempora doloremque non deleniti, aperiam quibusdam corrupti officia consequatur, impedit. Exercitationem debitis iste voluptatum, illo nulla iure culpa ex fugit, aliquid dolorem excepturi, impedit voluptates quae quidem error earum natus, provident eum vitae. Tempore ducimus laborum voluptates, qui aspernatur odit dolorum modi quas cupiditate unde quam earum amet!
</p>
</div>
</div>
</div>
</div>
</div>
CSS
div.c1 { height: 100vh; background: #417ba1; margin-top: -30px; padding: 0px 30px; }
div.c2 { height: 90%; background: #fff; margin-top: 0px; padding: 60px 30px; }
.jumbotron { background: url("../img/header_bg.png") no-repeat; height: 100%; }
Ah. You're looking for
.c1 {
overflow: auto; // or hidden or overlay
}
This behavior is due to the collapsing margins part of the box model spec. Putting overflow: auto|hidden|overlay on the parent will establish a new block formatting context and stop the margins from collapsing.
This is because the border of the c1 and c2 are collapsing. You have to hide the overflow (with overflow: hidden or any overflow different that default, which is visible) of the container to avoid that the c1 also get the margin of c2.
div.c1 { height: 100vh; background: #417ba1; overflow: hidden; margin-top: -30px; padding: 0px 30px; }
div.c2 { height: 90%; background: #fff; margin-top: 20px; padding: 60px 30px; }
.jumbotron { background: url("../img/header_bg.png") no-repeat; height: 100%; }
<header>
<div class="jumbotron">
<center><h1>Bienvenidos a JVasconcelos.me</h1></center>
</div>
</header>
<div class="container">
<div class="row">
<div class="col-md-12 col-centered">
<div class="c1">
<div class="c2">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quis inventore illum quaerat laboriosam eos, vel sed suscipit cumque laborum est animi aliquid tempora iusto beatae quam quisquam porro dolore! Ullam tenetur doloribus ducimus, totam voluptatum, deleniti vero voluptatem eius architecto velit neque voluptas aliquam quidem sed eveniet! Nobis ex eos iste dolorum tempora doloremque non deleniti, aperiam quibusdam corrupti officia consequatur, impedit. Exercitationem debitis iste voluptatum, illo nulla iure culpa ex fugit, aliquid dolorem excepturi, impedit voluptates quae quidem error earum natus, provident eum vitae. Tempore ducimus laborum voluptates, qui aspernatur odit dolorum modi quas cupiditate unde quam earum amet!
</p>
</div>
</div>
</div>
</div>
</div>
I assume you mean when you change the margin-top on the div.c2 your div.c1 also shifts down. This is due to the default definition of a div+div construct.
To achieve what you want you will need to create the following extra css definition on your div.c1:
display: inline-block;
Have a look at this codepen: http://codepen.io/anon/pen/beNjbW
Difference of or greater margin of c1 or c2 will be rendered due to collapsible margins.
In this case your total distance will be 0 (they cancel each other):
div.c1 {
margin-top: -30px;
}
div.c2 {
margin-top: 30px;
}
In this case your distance will be 10px from the top:
div.c1 {
margin-top: -30px;
}
div.c2 {
margin-top: 40px;
}
One of top margins can be omitted in this case. You can control the distance to header by adjusting margin-top of either one
codePen example
How do I use the parent div (#warped) to move and contain, my rotated span elements (which are in fact 'curved words' that I want to keep in said position) in one movement?
I have used this link to help generate the curvature: http://csswarp.eleqtriq.com/
The <span> tags are placed within the #warped parent element in my HTML document, but despite this on the webpage itself they appear to be located outside of #warped div
I would like to, for example, move the entire curved word to the left of the page. How would I do this?
Here is the CSS:
#warped {
position: relative;
display: block;
}
#warped>span[class^=w]:nth-of-type(n+0) {
display: block;
position: absolute;
transform-origin: 50% 100%;
}
#warped span {
font-family: 'ABeeZee';
font-size: 38px;
font-weight: regular;
font-style: normal;
line-height: 0.65;
white-space: pre;
overflow: visible;
padding: 0px;
}
#warped .w0 {
transform: rotate(0.91rad);
width: 20px;
height: 24px;
left: 552.15px;
top: 152.55px;
}
#warped .w1 {
transform: rotate(1.06rad);
width: 23px;
height: 24px;
left: 565.17px;
top: 174.68px;
}
etc etc
Here is the HTML as well:
<div id='warped'>
<span class='w0'>F</span><span class='w1'>a</span><span class='w2'>n</span><span class='w3'>t</span><span class='w4'>a</span><span class='w5'>s</span><span class='w6'>t</span><span class='w7'>i</span><span class='w8'>c</span><span class='w9'>!</span><span class='w10'>!</span><span class='w11'>!</span><span class='w12'>!</span>
</div>
The issue is the position:absolute and display:block on the span elements. Change it to:
#warped>span[class^=w]:nth-of-type(n+0) {
display: inline-block;
transform-origin: 50% 100%;
}
As long as you donĀ“t have a specified width on your #warped it will be 100% of the browser and the text will look like it's outside.
Try this: http://jsfiddle.net/54L30x1j/
Basically on their site: http://csswarp.eleqtriq.com/, you can re-size the window and make it small. Then your self you can further reduce the extra size. Put your text in top left corner as much as possible.
<div id='warped'> <span class='w0'>F</span><span class='w1'>a</span><span class='w2'>n</span><span class='w3'>t</span><span class='w4'>a</span><span class='w5'>s</span><span class='w6'>t</span><span class='w7'>i</span><span class='w8'>c</span>
</div>
<p>
<span>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptatum quasi ad ipsum cum ipsa repellendus recusandae in molestias fugiat placeat maiores aspernatur numquam neque id blanditiis. Iusto amet odio natus.</span>
<span>Ipsam quas incidunt deserunt molestias asperiores deleniti temporibus quisquam vel sapiente dolores aliquam eum optio minus cupiditate ipsum illo veritatis eligendi obcaecati porro ea rerum dolore repudiandae neque earum voluptatem.</span>
<span>Totam officiis saepe tenetur tempore voluptate cupiditate fugit exercitationem voluptatem illum possimus. Dicta similique dolore laboriosam ipsum modi minus saepe accusantium consectetur natus architecto harum commodi porro eius est nemo.</span>
<span>Officiis labore quibusdam modi autem velit neque reiciendis unde quaerat delectus expedita consectetur nemo nobis assumenda officia porro cum quos voluptates molestiae enim debitis commodi saepe id dolorum. Repudiandae repellat.</span>
<span>Aspernatur non nobis nesciunt deserunt possimus nulla repellat voluptatibus fuga asperiores error optio ipsa adipisci voluptate quidem esse commodi recusandae molestias dolores iure minima sapiente laborum molestiae dolor quisquam ratione.</span>
</p>