I have a query about CSS and I am having a hard time trying to figure it out.
Here is the HTML:
<div class='a'>
<div class='b'>
</div>
<div class='c'>
<div>
</div>
For e.g. I have a div with a class 'a'. I want this entire div to be scrollable if it overflows. In addition, I want the div with the class 'c' to scroll, but I want the div with the class 'b' to remain fixed on the page. It should show up at the same location even if the scrolling is provided for other divs.
Can someone let me know of a way, if there is one?
Unsure what sort of layout you are wanting, but you are looking to use overlow-y:scroll; in your css. Your div that you want to be scrollable, needs to have a specific height affixed to it.
I created an example that has .a scrollable and .c is as well. .b will stay at the top, UNLESS you scroll too far down in .a.
If you are wanting .b to be visible even when you scroll down in .a, then you'll have to do some non-intuitive positioning with position:fixed.
JSFiddle example
<style media="screen">
.a{
height: 200px;
overflow-y: scroll;
border: 1px solid black;
}
.b {
margin: 10px;
border: 1px solid blue;
}
.c {
height: 150px;
overflow-y: scroll;
background: #ddd;
}
</style>
<div class='a'>
<div class='b'>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
</div>
<div class='c'>
eiusmod <br> tempor incididunt <br> ut labore et dolore magna <br> aliqua. <br> <br> Ut enim ad minim veniam, quis <br> nostrud exercitation <br> ullamco laboris nis<br> i ut aliquip ex ea commodo<br> consequat. Duis aute irure dolor in<br> reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
<div class='d'>
eiusmod <br> tempor incididunt <br> ut labore et dolore magna <br> aliqua. <br> <br> Ut enim ad minim veniam, quis <br> nostrud exercitation <br> ullamco laboris nis<br> i ut aliquip ex ea commodo<br> consequat. Duis aute irure dolor in<br> reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
</div>
Related
image cant seem to fit in just one section and keep overflowing to another section.
tried putting tag in between but does not seems to work, img keep showing in two section.also tried the width and padding but i can't move the img to the left. can anyone help with only css and html? can't use js on this project.
#section1 {
height: 580px;
width: 1519px;
background-color: #0E2E3B;
padding: 50px;
}
<body>
<section id="section1">
</section>
<section class="main" id="section2" id="profil">
<h1>Lorem</h1>
<h2>Lorem</h2>
<p> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<img src="pancasila.jpg">
</section>
<body>
the html code
If you want to have same ratio you should create a container and hide parts of the image. Follow like this with an additional CSS file. Tweak the parameters in the CSS file as you wish and you can get your desired results.
HTML
<body>
</section>
<section class="main" id="section2" id="profil">
<h1>Lorem</h1>
<h2>Lorem</h2>
<p> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<img class="img" src="pancasila.jpg">
</section>
</body>
CSS
.container{
width:100%;
height:60px;
overflow:hidden;
}
.img {
width:100%;
}
Try adding some css for img. Also you first section doesn't seem to have opening tag.
img { width: 100% }
I mostly don't use html\css in my professional life, but for now I have a task that requires some work with markdown.
I have a text which should be no more than 80 character width. Here is a css:
.content {
width: 80ch;
margin-left:auto;
margin-right:auto;
}
I want to embed the image like this one:
<img src="https://ucarecdn.com/4922ea06-6240-4be5-bd43-06021daa81d4/accountcredentials.png">
If I apply it simply within the same div image would go beyond borders (it has bigger width)
How can I put image within width of text block?
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="centered">
<p class="content">
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<p class="img">
<img src="https://ucarecdn.com/4922ea06-6240-4be5-bd43-06021daa81d4/accountcredentials.png">
</p>
</div>
.centered {
}
.content {
width: 80ch;
margin-left:auto;
margin-right:auto;
}
Did you mean like that?
.content {
width: 80ch;
margin: 0 auto;
}
img {
width: 100%;
}
<div class="centered">
<p class="content">
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
<img src="https://ucarecdn.com/1d0fc207-9d61-4bf3-8e74-a273f1b4ce91/accountcredentials.png">
</p>
</div>
Image inside the p tag and width: 100%
fiddle
Set the image as a background.
.content {
width: 80ch;
margin-left:auto;
margin-right:auto;
background-image: url('https://ucarecdn.com/4922ea06-6240-4be5-bd43-06021daa81d4/accountcredentials.png');
background-size: cover;
}
You can then apply padding to the class to add spacing around the text, and the borders of the background.
Set a max-width on the image to prevent it overflowing the container.
.content img {
max-width: 100%;
}
I'm working on revamping an intranet page that was built years ago, and I'm trying to figure out the most effective CSS to properly lay out a page with the following requirements:
The page should occupy the full height and width of the viewport and should be responsive to resizing.
There should be a status bar that should always be visible at the bottom and should only be as tall as its contents.
If the user increases the font size, the status bar should properly adjust so the text isn't cut off.
If the content is taller than than the available screen height, scrollbars should appear in the content area to allow it to scroll (again, keeping the status bar visible).
Here's a mockup of the expected result:
As far as browser requirements go, this will ONLY be seen by a very specific group of users that will access it via Internet Explorer 11. No Chrome, no Firefox, no Edge - nothing except IE 11.
I've been experimenting with the "100vh" heights and flex, and I think I'm getting close but I'm just having some trouble getting everything the way I want. My current attempt looks like this:
body {
height: 96vh;
min-height: 96vh;
width: 95vw;
min-width: 95vw;
display: flex;
flex-direction: column;
}
#content
{
padding: 20px;
max-height: 95vh;
overflow:auto;
flex: 1 0 0;
}
#statusbar
{
background-color: #000;
color: #fff;
padding: 20px;
}
<div id="content">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
<footer id="statusbar">Status bar</footer>
I appreciate whatever help can be provided! Thanks in advance!
Here is a solution using display:flex where the footer has variable height and the content adjusts accordingly. The content area is set to overflow:auto in order to scroll if necessary.
html,
body {
height: 100%;
margin: 0
}
.box {
display: flex;
flex-flow: column;
height: 100%;
}
.box .row {
border: 1px dotted grey;
}
.box .row.footer {
flex: 0 1 auto;
}
.box .row.content {
flex: 1 1 auto;
overflow:auto;
}
<div class="box">
<div class="row content">
<p>
<b>content</b>
(fills remaining space)
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
some overflowing text
</p>
</div>
<div class="row footer">
<p><b>footer</b> (variable height)</p>
</div>
</div>
I'm stumped. I'm trying to figure out how to vertically center align a div with a border, to the right of a div with an image. The general problem is how to vertically center align any div next to any other div. Not just the text contents of a div. I've seen lots of potential solutions presented here, but none that work.
This is almost trivial with a table, but we're not supposed to use tables for positioning any more. I'm looking for a way to avoid using a table. I'm not finding one. One of the reasons cited for not using tables for positioning is how confusing they can be. I got news for those pundits. It can't possibly be more confusing than trying to do this with a div.
I have an example page with both. The title reflects my current attitude, which is why not use a table when it works?
http://popnowlin.com/whynot.html
<style type="text/css">
.mybox {
display:inline-block;
margin:0px 1em;
padding:1em;
border-style:solid;
}
</style>
...
<table style="width:100%">
<tr>
<td>
<img alt="" src="http://angelichomeservices.com/AHS.jpg" width=315 />
</td>
<td>
<div class=mybox>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
</td>
</tr>
</table>
...
<div style="width:100%;">
<img alt="" src="http://angelichomeservices.com/AHS.jpg" width=315 />
<div class=mybox style="width:calc(100% - 315px - 4em - 6px);float:left;vertical-align:middle;">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
</div>
The top example is using a table and it does just what I want. I can shrink or enlarge the width of the page, and the div with text in it shrinks and enlarges and stays vertically centered on the image.
The bottom example is my attempt to use div for the positioning, but all I can do is get the two to align vertically at the top. Also, having to use calc() in css is probably not the safest way to solve anything.
Anyone have a solution for this? Feel free to grab the code and go crazy. Thanks in advance.
CSS Tables would seem to be a solution.
JSFiddle demo
.parent {
display: table;
}
.child {
display: table-cell;
vertical-align: middle;
border: 1px solid grey;
}
<div class="parent">
<div class="mybox child">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
<img class="child" alt="" src="http://angelichomeservices.com/AHS.jpg" />
</div>
I have a grid with one div taking up around 30% and the other 70%. In the 30% div, I have 4 images stacked vertically. In the 70% div I have content. How could I dynamically resize and crop the 4 images equally so they equal the height of the 70% content div. I know I could resize the images manually, but I'd like them to auto-adjust if content is added or removed. Also, the design is responsive. Here is a jsfiddle:
http://jsfiddle.net/fETtm/
Here is my HTML:
<section>
<div id="inner-content" class="wrap">
<aside class="fourcol first">
<img src="https://www.slooh.com/images/signup/m42_png_sm.png">
<img src="https://www.slooh.com/images/signup/m42_png_sm.png">
<img src="https://www.slooh.com/images/signup/m42_png_sm.png">
<img src="https://www.slooh.com/images/signup/m42_png_sm.png">
</aside>
<article class="eightcol">
<h3>H3 Title</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</article>
</div>
</section>
Thank you for any help.
overflow: hidden will cut anything outside the element it is applied (here .wrap your container).
Demo: http://jsfiddle.net/fETtm/1/
By removing your images from the flow (position: absolute), only the right column is still in the flow and will define the size of its container. Now any bit of image that is outside this box won't be displayed.
As the left column was removed from the flow, your text now occupies the whole width of its container so it needs padding-left (same value as the width of your images).
HTML: same as yours
CSS:
.wrap {
position: relative;
overflow: hidden;
outline: 1px dashed purple;
max-width: 1140px;
width: 96%;
margin: 0 auto;
}
.fourcol {
width: 31.491712705%;
position: absolute;
}
.eightcol {
width: 65.74585634900001%;
position: relative;
float: left;
margin-left: 2.762430939%;
padding-left: 31.491712705%;
}
.first {
margin-left: 0;
}