Here is a sample of the problem
FIDDLE DEMO
When you make the viewing windows smaller, so that the footer is overlapping the other content and the scroll bar appears.
When scrolling down the footer is stuck in its previous position and doesn't go back down. I don't want the footer fixed (position:fixed) if possible.
Could this be fixed with some thing min/max-height property or z-index?
HTML:
<header>something here</header>
<div>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tempora temporibus illum aliquam voluptatum at blanditiis itaque tenetur laborum officia culpa maiores quasi accusantium excepturi! Quidem alias ullam praesentium quod eius.</div>
<footer>© 2014 some text</footer>
CSS :
header {
width: 100%;
height: 100px;
text-align: center;
color: #fff;
background-color: #333;
}
div {
height: 200px;
background-color: #ccc;
}
footer {
color: #fff;
background-color: #333;
height: auto;
width: 100%;
text-align: center;
bottom: 0px;
position: absolute;
}
The issue here is bottom:0 !!
I hope this is what you want -> Fiddle Demo
I added height:100% hoping that, that is what you want.
You can change it if you want
html,body{
width:100%;
height:100%;
}
header {
width: 100%;
height: 100px;
text-align: center;
color: #fff;
background-color: #333;
}
div {
height: 100%;
background-color: #ccc;
}
footer {
color: #fff;
background-color: #333;
height: auto;
width: 100%;
text-align: center;
position: absolute;
}
Related
How can I make an image fill the full height in a flexbox item? The image should be stretched to fill the height while keeping the aspect ratio.
body {
background: #20262E;
padding: 20px;
font-family: Arial;
}
.banner-message {
background: #eee;
border-radius: 20px;
padding: 0px;
overflow: hidden;
width: 500px;
display: flex;
align-items: stretch;
}
.banner-message .banner-message-media {
flex: 1;
}
.banner-message .banner-message-content {
padding: 20px;
flex: 2;
}
<div class="banner-message">
<div class="banner-message-media">
<img src="https://picsum.photos/id/1068/250/150" />
</div>
<div class="banner-message-content">
<h3>Content Title</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Recusandae delectus, quod veniam necessitatibus saepe error dicta voluptatem vitae incidunt nulla fugit! Quasi minus libero reiciendis similique cupiditate eum veniam tenetur.</p>
</div>
</div>
Add height:100%; and width:fit-content;
img {
height: 100%;
width: fit-content;
}
SCCS:
body {
background: #20262E;
padding: 20px;
font-family: Arial;
}
.banner-message {
background: #eee;
border-radius: 20px;
padding: 0px;
overflow: hidden;
width: 500px;
display: flex;
align-items: stretch;
.banner-message-media {
border-radius: 10px;
flex: 1;
img {
height:100%;
width:fit-content;
}
}
.banner-message-content {
padding: 20px;
flex: 2;
}
}
body {
background: #20262e;
padding: 20px;
font-family: Arial;
}
.banner-message {
background: #eee;
border-radius: 20px;
padding: 0px;
overflow: hidden;
width: 500px;
display: flex;
align-items: stretch;
}
.banner-message .banner-message-media {
border-radius: 10px;
flex-grow: 1;
}
.banner-message .banner-message-content {
padding: 20px;
flex-grow: 2;
}
img {
height: 100%;
width: fit-content;
}
<div class="banner-message">
<div class="banner-message-media">
<img src="https://picsum.photos/id/1068/250/150" />
</div>
<div class="banner-message-content">
<h3>Content Title</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Recusandae delectus, quod veniam necessitatibus saepe error dicta voluptatem vitae incidunt nulla fugit! Quasi minus libero reiciendis similique cupiditate eum veniam tenetur.</p>
</div>
</div>
Use object-fit property in your .banner-message-media css class. Like this
object-fit: fill or object-fit: cover.
I have a problem with text-indent.
Here is the image what I want to make.
I don't want to use <li>.
I want to make custom list style.
Here is my code.
.dotted-style{
width: 200px;
word-break: break-all;
}
.dotted-style::before{
display: inline-block;
content: '';
width: 4px;
height: 4px;
background-color: gray;
border-radius: 100%;
margin: auto 5px;
vertical-align: middle;
}
<p class="dotted-style">Lorem ipsum dolor sit amet consectetur, adipisicing elit. Possimus aliquam non aspernatur reprehenderit, velit, laboriosam harum aut dolorum, quasi a iure maiores. Eos laboriosam exercitationem quasi magni doloribus fuga rerum?
</p>
Try this with margin:
CSS:
.dotted-style {
width: 200px;
word-break: break-all;
margin-left: 15px;/*added*/
}
.dotted-style::before {
display: inline-block;
content: '';
width: 4px;
height: 4px;
background-color: gray;
border-radius: 100%;
margin: auto 5px auto -10px;/*modified*/
vertical-align: middle;
}
Demo: http://jsfiddle.net/lotusgodkk/GCu2D/2189/
Try this:
.dotted-style{
width: 200px;
word-break: break-all;
position:relative;
padding-left:15px;
}
.dotted-style::before{
display: inline-block;
content: '';
width: 4px;
height: 4px;
background-color: gray;
border-radius: 100%;
margin: auto 5px;
vertical-align: middle;
position:absolute;
left:0;
top:10px;
}
i created a responsive rectangle and a responsive triangle with css only.
How can i align the triangle so it is always vertically centered on the right side of the box?
I´d like to do it just with css but if it is not possible i appreciate any hint for alternative options.
HTML:
<div class="container">
<div class="box green rightbox">
<div class="innerbox">Lorem ipsum....</div>
</div>
<div class="mother-triangle">
<div class="triangle-right green"></div>
</div>
</div>
CSS:
.container {
max-width: 1200px;
margin-right: auto;
margin-left: auto;
z-index: 1;
position: relative;
}
.box {
height: auto!important;
min-height: 300px;
}
.box.green {
background-color: rgba(51, 223, 9, 0.75)!important;
}
.innerbox {
padding: 12px;
}
.triangle-right {
width: 0;
height: 0;
padding-top: 10%;
padding-bottom: 10%;
padding-left: 10%;
overflow: hidden;
position: relative;
margin-top: auto;
margin-bottom: auto;
display: inline-block;
vertical-align: middle;
}
.triangle-right:after {
content: "";
display: block;
width: 0;
height: 0;
margin-top: -500px;
margin-left: -500px;
border-top: 500px solid transparent;
border-bottom: 500px solid transparent;
border-left: 500px solid rgba(51, 223, 9, 0.75);
}
.rightbox {
width: 90%;
float: left;
}
JSFiddel demo:
You can use absolute positioning to do that.
Just change position: relative to position: absolute in .triangle-right.
Add top: 50% to move the triangle to the vertical middle.
Updated fiddle
.container {
max-width: 1200px;
margin-right: auto;
margin-left: auto;
z-index: 1;
position: relative;
}
.box {
height: auto!important;
min-height: 300px;
}
.box.green {
background-color: rgba(51, 223, 9, 0.75)!important;
}
.innerbox {
padding: 12px;
}
.triangle-right {
width: 0;
height: 0;
padding-top: 10%;
padding-bottom: 10%;
padding-left: 10%;
overflow: hidden;
position: absolute;
margin-top: auto;
margin-bottom: auto;
display: inline-block;
vertical-align: middle;
top: 50%;
}
.triangle-right:after {
position: absolute;
content: "";
display: block;
width: 0;
height: 0;
margin-top: -500px;
margin-left: -500px;
border-top: 500px solid transparent;
border-bottom: 500px solid transparent;
border-left: 500px solid rgba(51, 223, 9, 0.75);
}
.rightbox {
width: 90%;
float: left;
}
<!-----container start---->
<div class="container">
<div class="box green rightbox">
<div class="innerbox">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>
<div class="mother-triangle">
<div class="triangle-right green"></div>
</div>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
</div>
<!-----container end ---->
I am trying to position a styled heading to be centered and to sit slightly above it's parent div. I assumed the heading would have to be absolutely positioned to be able to be shifted outside of the parent by adding a negative margin to the top. I can center it when it's position is relative, but I can not add a negative margin to bring it outside of the parent.
HTML
<div class="container">
<div class="row">
<div class="col-md-6">
<div class="content">
<h2 class="content-box-title">A Heading</h2>
<div class="content-body">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsam, culpa illum! Sint maiores numquam provident, consequatur voluptatibus, repudiandae, dolorum sed, itaque saepe magni fugit mollitia! Repellat dignissimos, quas esse itaque.</p>
</div>
</div>
</div>
</div>
</div>
CSS
.content {
position: relative;
background-color: #d5d5d5;
}
.content-box-title {
position: absolute;
background-color: grey;
text-align: center;
padding: 10px;
margin: -40px auto;
}
.content-body {
padding: 20px;
}
http://jsfiddle.net/LsohxL3m/
By making the title an inline-block, you can center it using text-align: center on the parent div. You don't need absolute positioning or auto margin then, so you can just use a negative top margin. You can use text-align left on the content to keep that left aligned:
.content {
background-color: #d5d5d5;
text-align: center;
}
.content-box-title {
display: inline-block;
background-color: grey;
text-align: center;
padding: 10px;
margin-top: -40px;
}
.content-body {
padding: 20px;
text-align: left;
}
Here's a fiddle.
I adjusted that fiddle to include this css content:
.content h2 {
box-sizing: border-box;
margin: -60px auto 0;
width: 100%;
}
an it seemed to center the h2 and set it just a bit above the content div.
but after deeper investigation, it looks like you just need to as a width to your original tag, and the box-sizing rule to assist with the padding/margin on the element.
I appended this to your existing .content-box-title css and it worked fine:
width: 100%;
box-sizing: border-box;
Check now: http://jsfiddle.net/LsohxL3m/1/
I changed the styling of the title as follows:
.content-box-title {
background-color: grey;
text-align: center;
padding: 10px;
margin-top: -40px;
margin-left: auto;
margin-right: auto;
}
You can use translate:
.content-box-title {
position: absolute;
background-color: grey;
text-align: center;
padding: 10px;
margin-top: -40px;
left:50%;
transform: translate(-50%, 0);
}
http://jsfiddle.net/LsohxL3m/6/
change
.content-box-title {
position: absolute;
background-color: grey;
text-align: center;
padding: 10px;
margin: -40px auto;
}
.content-body {
padding: 20px;
}
to
.content-box-title {
transform: translateY(-60px);
background-color: grey;
margin-top: 60px;
text-align: center;
padding: 10px;
}
.content-body {
padding: 0 20px 20px 20px;
}
Here is a sample
I am using display:flex in order to center/vertically center the content on the page. I have set a media query so that there is a hamburger menu for mobile size. However, there appears to be a right margin on the homePage. No matter what I try, I can't get the margin to go away. Here's a jsfiddle of it. Please help!
http://jsfiddle.net/crcommons/Lxepj9ko/2/
(p.s. make sure you adjust the browser size so that it is in mobile).
$('.hamburger').on('click', function() {
$('.menu').slideToggle();
});
function setPageHeight () {
var windowHeight = $(window).height();
var headerHeight = $('header').height();
pageHeight = (windowHeight - headerHeight);
$('.homePage').css('min-height', pageHeight + 'px');
};
setPageHeight();
$(window).resize(setPageHeight);
*, *:after, *:before {
box-sizing: border-box
}
body {
font-size: 18px;
}
.container {
margin: 0 auto;
}
nav {
background-color: white;
max-width: 100%;
padding-top: .75em;
}
.mainNav {
max-width: 1024px;
margin: 0 auto;
}
.mainNav li {
width: 19%;
display: inline-block;
border-right: 1px solid black;
text-align: center;
}
.mainNav li:last-child {
border-right: none;
}
.hamburger {
display: none;
line-height: .3em;
}
.hamburger:before {
content: "≡";
}
.homePage {
background-color: #CBD5D2;
max-width: 100%;
display: flex;
}
.introduction {
max-width: 40em;
margin: auto;
}
.logo {
text-align: center;
}
.tagline {
font-size: 3em;
text-align: center;
}
.introduction p {
text-align: justify;
}
#media screen and (max-width: 479px) {
.wrapper {
padding: 1.5em;
}
nav {
display: none;
}
.hamburger {
display: inline-block;
font-size: 3.5em;
text-decoration: none;
float: right;
}
.navigation {
float: left;
float: left;
position: absolute;
right: 0;
margin-top: 30px;
padding: 0;
background: gray;
}
.mainNav {
padding: 0;
}
.mainNav li {
display: block;
padding: .5em;
width: 100%;
}
.homePage {
padding: 1em;
}
.tagline {
font-size: 2em;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<div class="container">
<header>
<div>
</div>
<nav class="navigation menu">
<ul class="mainNav">
<li>Home</li>
<li>Page 1</li>
<li>Page 2</li>
<li>About</li>
<li>Contact</li>
</ul>
</nav>
</header>
<div class="homePage">
<div class="introduction">
<h1 class="logo">Title</h1>
<h2 class="tagline">Lorem ipsum dolor sit.</h2>
<p class="introP">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Officiis nam velit, voluptates dolore consequuntur ea tempore laborum mollitia, corporis impedit distinctio aperiam itaque perspiciatis repellat neque facilis esse molestiae maiores eum, incidunt eius quaerat! Dicta illo ut, incidunt ratione magni cum unde architecto obcaecati illum harum tempora veniam placeat voluptatem.</p>
</div>
</div>
</body>
One option to solve this would be within the .hamburger class media query setting position: absolute; right: 0px;
This is happening because .hamburger is floating right, and there is nothing to clear the float. .homepage has a max-width: 100% but the width is not set. Since the homepage isn't 100%, it will float around the hamburger.
Clear the float:
header::after {
content: '';
display: block;
clear: both;
}
Set homepage width to 100%:
.homepage {
background-color: #CBD5D2;
max-width: 100%;
width: 100%;
display: flex;
}