Numbers don't wrap to new line in fixed width - html

I have two <div>. One of them with 'Lorem ipsum' text, second - with numbers. I found, that div with numbers, don't wrap numbers to new line in fixed width <div>. Is anybody can explain, why number don't wrap to new line, maybe this situation described somewhere in specifications?
JSFiddle.
div {
width: 200px;
}
<div>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusantium quasi consequatur nobis magni molestias repudiandae rerum quisquam quo dolore dolorem! Sit eligendi accusamus aliquam consectetur inventore minima, fugiat qui quia.</div>
<div>111111111111111111111111111111111111111111111111</div>

Because the browser treats numerals as regular text and won't break it unless you tell it to with something like the word-wrap or word-break property. Add a rule like:
div {
width: 200px;
word-wrap:break-word;
}
to do that.
jsFiddle example

div {
width: 200px;
word-wrap: break-word;
}
<div>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusantium quasi consequatur nobis magni molestias repudiandae rerum quisquam quo dolore dolorem! Sit eligendi accusamus aliquam consectetur inventore minima, fugiat qui quia.</div>
<div>111111111111111111111111111111111111111111111111</div>

Related

How to influence div with checked input if div is far away and not a relative?

A have CSS-code:
.hide, .hide + label ~ div {
display: none;
}
.hide:checked + label + div {
display: block;
}
It allows me to manipulate div next to label next to checked input.
It works fine, but is there a way, that I can manipulate div with checked/unchecked that is far away from input?
My div has class "dropdown-menu" and it is not related to input in any way and like 50 lines of code after the input.
Can I connect checked value with my "dropdown-menu" div in any way with CSS?
CSS is limited in terms of how one selected element is able to help select and affect other elements in the DOM. You've highlighted two of the very cool combinators available to use already: the adjacent sibling combinator (+) and the general sibling combinator (~). You're no doubt familiar with the descendant combinator (_) <- that's a space. Finally, there's the child combinator (>).
Of these, the only two that I can imagine would be even potentially helpful are the general sibling combinator (~) and the descendant combinator(_). The other two describe relationships that assume very specific proximity relationships (+, >).
You can do what (I think) you're describing with the general sibling selector (at least you can if your markup structure has the dropdown menu div as a general sibling of the label element above it). I don't think it's likely to be in real life, but (assuming it is) here's a contrived example.
.me-too {
padding: 8px;
background-color: #fafafa;
margin-top: 16px;
margin-bottom: 16px;
}
.hider+label+div {
display: none;
}
.hider:checked+label+div {
display: block;
}
.hider+label~.dropdown-menu {
display: none;
}
.hider:checked+label~.dropdown-menu {
display: block;
}
.dropdown-menu {
margin-top: 16px;
}
<header>
<input id="my-checkbox" class="hider" name="my-checkbox" type="checkbox">
<label for="my-checkbox">Check me!</label>
<div>I can be hidden and revealed</div>
<div>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Odit et ipsum aperiam dolor animi necessitatibus inventore tempora reiciendis magni a delectus quidem veritatis fuga, praesentium illo beatae voluptates magnam nulla.</div>
<div>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Odit et ipsum aperiam dolor animi necessitatibus inventore tempora reiciendis magni a delectus quidem veritatis fuga, praesentium illo beatae voluptates magnam nulla.</div>
<div>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Odit et ipsum aperiam dolor animi necessitatibus inventore tempora reiciendis magni a delectus quidem veritatis fuga, praesentium illo beatae voluptates magnam nulla.</div>
<div>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Odit et ipsum aperiam dolor animi necessitatibus inventore tempora reiciendis magni a delectus quidem veritatis fuga, praesentium illo beatae voluptates magnam nulla.</div>
<div>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Odit et ipsum aperiam dolor animi necessitatibus inventore tempora reiciendis magni a delectus quidem veritatis fuga, praesentium illo beatae voluptates magnam nulla.</div>
<div>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Odit et ipsum aperiam dolor animi necessitatibus inventore tempora reiciendis magni a delectus quidem veritatis fuga, praesentium illo beatae voluptates magnam nulla.</div>
<div>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Odit et ipsum aperiam dolor animi necessitatibus inventore tempora reiciendis magni a delectus quidem veritatis fuga, praesentium illo beatae voluptates magnam nulla.</div>
<div>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Odit et ipsum aperiam dolor animi necessitatibus inventore tempora reiciendis magni a delectus quidem veritatis fuga, praesentium illo beatae voluptates magnam nulla.</div>
<div>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Odit et ipsum aperiam dolor animi necessitatibus inventore tempora reiciendis magni a delectus quidem veritatis fuga, praesentium illo beatae voluptates magnam nulla.</div>
<div>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Odit et ipsum aperiam dolor animi necessitatibus inventore tempora reiciendis magni a delectus quidem veritatis fuga, praesentium illo beatae voluptates magnam nulla.</div>
<div class="me-too dropdown-menu">
<h2>DROPDOWN MENU</h2>
<p>I too can be hidden and revealed!</p>
Link 1
Link 2
Link 3
Link 3
</div>
</header>
Personally, I really appreciate that you're trying to accomplish this using CSS. I think it's always better to use the simplest tool that can get the job done (HTML, CSS, HTML+CSS, or finally HTML+CSS+JS).
But if my contrived example above doesn't mirror your actual use case, you could surely use JavaScript to cover the gap right?
Let me know if I've misunderstood the intent of your question.
There is no way to do that. It would be possible if there were a parent combinator in CSS, but there isn't.
The solution is very simple with JS-code:
Here it is:
<script>
function myFunction() {
var x = document.getElementById("dropdown");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
}
</script>
Add this within container in HTML (of into JS-file if you know how to do that).
And add id to whatever block in div you are trying to hide/show.
ID in JS and ID in div should be the same
Also, remember that if you have basic value of display:block - everything works.
But if your basic display:FLEX, or INLINE, or else - you should change 4-th line of code (with BLOCK) to whatever value you need.
Have you tried data attributes?
https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes

Flexbox - image disappear with column

I'm a little bit stuck to be honest. Here is an example of my original code, the problem is that when I change my flex direction from row to column my picture disappears and I don't understand why =>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
background-color: rgb(104, 92, 76);
}
.container {
display: flex;
flex-direction: row-reverse;
background-color: black;
max-width: 700px;
margin: 20vh auto;
}
.content {
width: 100%;
}
.text {
color: white;
}
.image {
background: url('https://www.silocreativo.com/en/wp-content/uploads/2017/04/flexbox-cssgrid-practical-example.png');
width: 100%;
}
<div class="container">
<div class="image"></div>
<div class="content">
<div class="text"> Lorem ipsum dolor sit amet consectetur adipisicing Lorem ipsum dolor sit amet consectetur adipisicing elit. Quia corporis repudiandae Lorem Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam aut
autem molestias debitis unde atque quam at assumenda. Atque sint illo rerum magnam aperiam suscipit commodi repudiandae officia! ipsum dolor sit, amet consectetur adipisicing elit. Fugiat quidem quasi sint culpa et rem quas deserunt labore laboriosam
mollitia. Consequatur lorem minus earum sint eius reiciendis, deleniti id vero sapiente. officiis consequuntur voluptas optio dolore nobis blanditiis adipisci maxime itaque ducimus sit incidunt, eveniet doloremque cupiditate debitis deserunt ad!
elit. Optio nihil officia commodi nostrum iure dignissimos officiis, consectetur, quae minus libero qui hic quis voluptas et quas similique vero neque facere. Lorem ipsum dolor sit amet consectetur adipisicing elit. Dolores tenetur, veniam nobis
nulla molestiae recusandae quia a reiciendis corrupti exercitationem delectus iure ducimus ea odio animi cumque et optio eum! </div>
</div>
</div>
Since there is nothing that specifies the height on the <div class="image"></div>, it has a height of 0px. You could set the height to a certain value, like x vh or px,
but I would recommend using the img tag instead:
<img src="https://www.silocreativo.com/en/wp-content/uploads/2017/04/flexbox-cssgrid-practical-example.png"/> in place of <div class="image"></div>.
This way, the width and height are set to the dimensions of the actual image if nothing else is specified.
Your image tag has not an height specified, you need something like this to set the size of the div:
.image {
flex-basis: 200px; // or height: 200px;
}
Otherwise you can use the img tag instead of the background, so you can show the image at his correct dimensions. Remember to set height: auto to the img tag in this case.
A flex item needs either a height setting or content adding (which will determine the height). As the image div has no content or height its height is set to 0.
I don't recommend setting height on flex items as this is contrary to how flex works. You should set a height on the flex container and use flex-basis to set the height of your flex items.
This will allow your flex items to be responsive. If you want the image to have a fixed height you should set it's flex property to flex:0 0 <height>;
.container {
display: flex;
flex-direction: column;
background-color: black;
max-width: 700px;
margin: 20vh auto;
height: 400px;
}
.image {
display: flex;
background: url('https://www.silocreativo.com/en/wp-content/uploads/2017/04/flexbox-cssgrid-practical-example.png');
flex: 1;
}
.content {
flex: 1;
}
.text {
color: white;
}
<div class="container">
<div class="image"></div>
<div class="content">
<div class="text">Hey la bonbone est remplis de cocaine Lorem ipsum dolor sit amet consectetur adipisicing Lorem ipsum dolor sit amet consectetur adipisicing elit. Quia corporis repudiandae Lorem Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam aut
autem molestias debitis unde atque quam at assumenda. Atque sint illo rerum magnam aperiam suscipit commodi repudiandae officia! ipsum dolor sit, amet consectetur adipisicing elit. Fugiat quidem quasi sint culpa et rem quas deserunt labore laboriosam
mollitia. Consequatur lorem minus earum sint eius reiciendis, deleniti id vero sapiente. officiis consequuntur voluptas optio dolore nobis blanditiis adipisci maxime itaque ducimus sit incidunt, eveniet doloremque cupiditate debitis deserunt ad!
elit. Optio nihil officia commodi nostrum iure dignissimos officiis, consectetur, quae minus libero qui hic quis voluptas et quas similique vero neque facere. Lorem ipsum dolor sit amet consectetur adipisicing elit. Dolores tenetur, veniam nobis
nulla molestiae recusandae quia a reiciendis corrupti exercitationem delectus iure ducimus ea odio animi cumque et optio eum! </div>
</div>
</div>

Icon/Image at start of Div

I'm trying to place an 17x17 px png image at the beginning of a centered div text like that:
[img] text text
text text text text text
text text text text text
<div style="text-align: center; height: 45px; width: 200px">
<img src="icon" />
<div>
Some longer text.
</div>
</div>
The "difficulty": The text must remain in the div and the div must not contain anything but the text. And the div also must stay a div, or at least must have a height property.
I tried a lot with css but it never works out how I need it. Thanks!
EDIT: The text inside the div is not necessarily long. It can also be just one word.
You can use the pseudo-element ::before to display your image inside your div:
#myDiv::before {
content: url('image.png');
}
Here's a working fiddle.
I think you need something along these lines:
A header to have the icon and the title centered
A section with the rest of the text
And that can easly be done with some lines of flex box. Something along these lines:
<header class="center-text">
<img src="https://forum.starmen.net/include/images/smilies/cool3.png" /> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Molestiae, eum, debitis earum dignissimos nobis quos, nulla voluptates temporibus voluptatum ad repellat, nam dicta. Recusandae
ea quasi eligendi, nulla labore molestias.
</header>
<section>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perspiciatis sint voluptatem, id fuga adipisci dolor ut deleniti, est provident quis expedita nostrum ipsum sunt maiores obcaecati esse repellat tempore sed. Lorem ipsum dolor sit amet, consectetur
adipisicing elit. Perspiciatis sint voluptatem, id fuga adipisci dolor ut deleniti, est provident quis expedita nostrum ipsum sunt maiores obcaecati esse repellat tempore sed. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perspiciatis sint
voluptatem, id fuga adipisci dolor ut deleniti, est provident quis expedita nostrum ipsum sunt maiores obcaecati esse repellat tempore sed. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perspiciatis sint voluptatem, id fuga adipisci dolor
ut deleniti, est provident quis expedita nostrum ipsum sunt maiores obcaecati esse repellat tempore sed. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perspiciatis sint voluptatem, id fuga adipisci dolor ut deleniti, est provident quis expedita
nostrum ipsum sunt maiores obcaecati esse repellat tempore sed.
</section>
<style>
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
.center-text {
display: flex;
justify-content: center;
}
</style>

CSS "position: sticky" not sticking [duplicate]

This question already has an answer here:
Why position:sticky is not working when the element is wrapped inside another one?
(1 answer)
Closed 4 years ago.
I'm making my first website and I want to make the tab bar to stick to the top of the screen and stay on screen when you scroll, but position:sticky doesn't seem to be doing this.
div#tabBar {
position: sticky;
top: 0;
display: flex;
flex-direction: row;
background-color: #29335C;
}
<div>
<div id="tabBar">
<a class="tabLinks">Home</a>
<a class="tabLinks">About Me</a>
</div>
<h1 id="homeFrame">Anna Grace</h1>
<div id="projectList"></div>
</div>
If you want it to the top of the screen, simply switch to position: fixed;
Position fixed is always relative to the upper left corner of the window, which is convinient in your case. Be aware that, because a fixed elenmet has no width, the content will start under/behind it. You might wat to give your body a padding top equal to the height of your header.
Position sticky works differently. It remains as a block/normal element until it's at the given top position, than it switches to fixed behaviour. Think like those advertisements that appear nexto content and stay where they are when you scroll down.
In your case the difference will be minimal, as the header start at 0, so it instanly switches to fixed,it just might behave a little more unpredictable.
it's works. I deleted parent div.
#tabBar{
position: sticky;
top:0;
background-color: #29335C;
display:flex;
flex-direction:row;
}
p {
font-size:36px;
}
<div id="tabBar">
<a class="tabLinks">Home</a>
<a class="tabLinks">About Me</a>
</div>
<div id="projectList"></div>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Minus necessitatibus ad voluptates? Libero harum perspiciatis incidunt voluptatum aliquam magni facere officia debitis? Placeat, saepe dolores praesentium culpa a voluptate quia?</p>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Minus necessitatibus ad voluptates? Libero harum perspiciatis incidunt voluptatum aliquam magni facere officia debitis? Placeat, saepe dolores praesentium culpa a voluptate quia?</p>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Vel, deleniti blanditiis neque id libero, sit consectetur harum optio omnis dolorem quo laborum quaerat doloremque ullam corporis pariatur sunt excepturi maiores!</p>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Non neque error quod nam repellat placeat vitae odit, nulla a deserunt nostrum est nihil sed dicta accusamus molestiae recusandae modi saepe.</p>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Facere eligendi quod accusamus dignissimos minus eum dolorum, commodi enim asperiores dicta nesciunt officiis praesentium quasi voluptas, explicabo sapiente neque atque perferendis!</p>
give outer div some height and the try. thanks
div#tabBar {
position: sticky;
top: 0;
display: flex;
flex-direction: row;
background-color: #29335C;
}
.outer{
height:1000px}
<div class="outer">
<div id="tabBar">
<a class="tabLinks">Home</a>
<a class="tabLinks">About Me</a>
</div>
<h1 id="homeFrame">Anna Grace</h1>
<div id="projectList"></div>
</div>

How can I show an absolutely positioned div inside a fixed positioned div?

I have this HTML:
<div id="main">
<div class="dummy">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Reiciendis enim molestias illo id voluptas tempora minima sunt fugiat voluptatibus voluptatem dolores omnis iste. Fuga facilis adipisci similique explicabo sunt alias! Lorem ipsum dolor sit amet, consectetur adipisicing elit. Totam omnis esse saepe eveniet modi harum quae laborum eaque vero nesciunt consequuntur placeat nisi velit commodi minima itaque voluptatem necessitatibus quasi.</div>
<div id="inner">I want this div to slide left on some action</div>
<div class="dummy">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Reiciendis enim molestias illo id voluptas tempora minima sunt fugiat voluptatibus voluptatem dolores omnis iste. Fuga facilis adipisci similique explicabo sunt alias! Lorem ipsum dolor sit amet, consectetur adipisicing elit. Totam omnis esse saepe eveniet modi harum quae laborum eaque vero nesciunt consequuntur placeat nisi velit commodi minima itaque voluptatem necessitatibus quasi.</div>
</div>
Please refer to this fiddle to view the full code with associated CSS.
I want the black inner div container to be visible even outside the main div container, but also want to give overflow:auto to the main div so that if content in the red div increases, a scroll bar should come. These things are not working together.
Please suggest how to achieve this.
Did you mean something like this?
I added the following:
HTML:
<div id="preventOverflow">
CSS:
#preventOverflow
{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
overflow: auto;
}
It is not possible to merge two scroll bars of seperate blocks with a div in between them. I would recommend changing the layout.
do you mean this...
#inner {
background: none repeat scroll 0 0 #000000;
color: #FFFFFF;
left: 59px;
position: inherit;
top: 5px;
width: 80px;
}
http://jsfiddle.net/kisspa/xRasu/