Bootstrap divider displaced on smaller screens - html

I'm currently developing a website, one of my first bootstrap websites.
Facing a problem that I've been trying to solve for a few hours now.
I'm placing a divider or separator that I made in photoshop (png image) on the edge of a section.
It looks like this on desktop size:
https://www.dropbox.com/s/qxf7dheb0k79q2b/Screenshot%202014-09-30%2023.02.50.png?dl=0
But on smaller screens this happens:
https://www.dropbox.com/s/w4je7milallfrqn/Screenshot%202014-09-30%2023.10.50.png?dl=0
I'm sure it due to my bad CSS.
Here is my html and css:
<section class="hero-section text-center">
<img class="separator img-responsive"src="images/separator.png">
<div class="container">
<h1>Download Now</h1>
<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>
<hr>
<button class="btn btncta">Download Now</button>
<p class="small">*Needed for developers</p>
</div>
</section>
CSS:
.separator{
display: block;
margin-left: auto;
margin-right: auto;
position: relative;
top:318px;
}
Any way I could fix this?
Is it using a image for divider outdated (probably is)?

There's nothing wrong with using that separator image approach, but you're doing it wrong. Just replace your CSS like this:
.separator{
display: block;
margin-left: auto;
margin-right: auto;
position: relative;
top:0px;
width:100%; height:1px;
}
and your HTML like this:
<section class="hero-section text-center">
<div class="container">
<h1>Download Now</h1>
<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>
<hr>
<button class="btn btncta">Download Now</button>
<p class="small">*Needed for developers</p>
</div>
<img class="separator "src="images/separator.png">
</section>
I did a bootply so you can see (the background color is not needed, is just so you see the effect since I don't have your image)
Adding new method based in new information:
/* CSS used here will be applied after bootstrap.css */
body {
background:#f00;
}
.separator {
display: block;
margin-left: auto;
margin-right: auto;
position: relative;
top:0px;
background:#f00;
width:100%;
height:1px;
}
.hero-section {
background:#fff url('http://www.customstairsandmouldings.com/images/circle.jpg') no-repeat center bottom; / we center the background and position it at the bottom of the div */
padding-bottom: 100px; /* padding-bottom has to be enough to give room to the image in the background, so if image height is 80px, padding bottom should be at least 80px, or better 100px to add spacing */
}
See new Bootply here

Related

How to put embedded image within width of text block

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%;
}

Proper CSS for 100% Height Content with a Fixed-Height Status Bar

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>

Which approach is better for responsive design with fixed width sidebar?

so which approach is better for responsive design with fixed width sidebar ?
both are working normally, and now some people says that the second approach is better, some says first...
or it is all the same ?
approach 1: http://jsfiddle.net/56erp1my/33/
<div id="wrap">
<div id="header">Header</div>
<div id="sidebar">Static LEFT sidebar</div>
<div id="content">Main content: fluid div.<br/>Width is automatically adjusted between 300px and 700px</div>
<div id="footer">Footer</div>
</div>
#wrap { padding: 10px; max-width:1000px; margin: 0 auto;}
#header {background: #0f0;}
#sidebar {width: 200px; float: right; height: 200px; background: #ddd;}
#content {margin-right: 210px; min-height: 100px; background: #ddd;}
#footer {clear:both; background: #0f0;}
approach 2: http://jsfiddle.net/56erp1my/35/
<h2>With Content:</h2>
<div class="wrap">
<div class="right">
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.
</div>
<div class="left">
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.
</div>
</div>
.wrap {
background: #eee;
padding: 10px;
max-width: 960px;
overflow: hidden;
margin: 0 auto;
}
.left, .right {
padding: 5px;
}
.left {
background: tomato;
display: table-cell;
width: 9999px;
}
.right {
background: green;
width: 300px;
float: right;
}
Thank you
The second approach seems better in terms of maintenance. This is why:
If you want to change the width of the right sidebar in the first approach, you will also have to change the margin-right of the element with the class content.
While in the second approach, if you change the width of the right side bar, the content on the left will resize and re-position itself automatically.

CSS Floating Boxes Unexpected Corner Bump

I have a page layout which employs floating boxes with constant width and variable height, inside a variable-width container (which I'm going to make constant for the sake of this question). This is my page's code:
CSS:
#main {
width: 640px;
margin: 0 auto;
min-height: 100%;
}
.profile {
width: 300px;
min-height: 160px;
margin: 10px;
float: left;
}
HTML:
<body>
<div id="main">
<div class="profile">1: I'm tall. 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 class="profile">2: I'm short.</div>
<div class="profile">3: I'm also short.</div>
<div class="profile">4: I'm short too.</div>
</div>
</body>
When I apply this code, div 4 seems like it's "stuck" in the corner, instead of to the left of div 3 like it should be: (Codepen preview).
What am I doing wrong, and how should I fix this glitch?
You could clear the odd divs:
.profile:nth-child(odd) {
clear:left;
}
Updated Codepen
#main {
width: 640px;
margin: 0 auto;
background: #444;
}
.profile {
width: 300px;
min-height: 160px;
margin: 10px;
float: left;
background: silver;
}
.profile:nth-child(odd) {
clear: left;
}
<body>
<div id="main">
<div class="profile">1: 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 class="profile">2: I'm short.</div>
<div class="profile">3: I'm also short.</div>
<div class="profile">4: I'm short too.</div>
</div>
</body>

How to keep the div fixed inside another div with absolute positioning

On hover event I show a div which has absolute positioning, at the bottom of that div I need a fixed div.
Have a look at the image what I want to achieve.
I have following code for this:
CSS
.showpro{position:absolute;z-index:999;width:500px;height:auto;display:none;max-height:500px;}
.bottom{width:500px;position:fixed;bottom:0;left:0;}
CODE
<div class='showpro'>
<div class='top'>
</div>
<div class='bottom'>
</div>
</div>
With this code, it comes at left-bottom corner of Container div. Can anyone say why? Any help?
An element with position: fixed is always positioned relative to the browser window. Try using position: absolute for that "fixed" element.
Here is an example which shows your expected result.
.container{
position:relative;
width:100vw;
height:100vh;
background-color:brown;
}
.showpro{
position:absolute;
z-index:999;
width:200px;
height:auto;
max-height:300px;
padding-bottom:80px;
overflow:hidden;
background-color:red;
right:0;
}
.top{
overflow:auto;
max-height:220px;
margin-right: 20px;
}
.bottom{
width:200px;
position:absolute;
bottom:0;
left:0;
height:80px;
background-color:green;}
<div class="container"><div class='showpro'>
<div class='top'>
Here can be a lot of text. 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. 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.
</div>
<div class='bottom'>
This is the "fixed" element.
</div>
</div></div>
Change position to relative for both the main div and the div inside main div :
Example: use this css code
#four {
background-color: blue;
height: 200px;
position: relative;
top: 50px;
width: 100px;
}