CSS Fixed position and media queries - css

Im having a problem with media queries and sidebar div with a fixed position.
Basically when the viewport gets too narrow the main content moves to the left and then sits under the sidebar. I tried to set position to static with the media queries, but then it doesnt work/look the way I want.
Here is the original fiddle: http://jsfiddle.net/ym7sQ/1/
#media (max-width: 991px) {
#sidebar {
position: fixed;
}
}
Here is the one with position static: http://jsfiddle.net/ym7sQ/2/
#media (max-width: 991px) {
#sidebar {
position: static;
}
}
You can see that the sidebar is inside the content, but I want it to be overlaying the top and bottom just as it is above 991px. Below 768 its going to stack which is okay because there is not enought space for sidebar and main content. Could you help me with this please? Thanks.

#media (max-width: 991px)
#sidebar {
position: fixed;
}
I think you should use this.

check it on http://jsfiddle.net/ym7sQ/14/show
Source: http://jsfiddle.net/ym7sQ/14/
Sorry for change a lot. But the main amendment is move the whole #sidebar element out of the container.
HTML:
<div id="top">
<div class="container">
<div class="row">
<div class="col-md-9 col-md-push-3">
<h2>Home</h2>
</div>
</div>
</div>
</div>
<div id="sidebar" class="col-sm-3">
<nav role="navigation">
<ul>
<li class="active">Home</li>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</nav>
<hr />
<p>info#domain.com
<br />123 456 789</p>
<p>Something something</p>
</div>
<div id="content">
<div class="container">
<div class="row">
<div class="col-sm-3"></div>
<div class="col-sm-9">
<section id="main">
<div id="slider" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#slider" data-slide-to="0" class="active"></li>
<li data-target="#slider" data-slide-to="1"></li>
<li data-target="#slider" data-slide-to="2"></li>
</ol>
<div class="carousel-inner">
<div class="item active">
<img src="http://placekitten.com/1280/720" alt="Slide 1" />
</div>
<div class="item">
<img src="http://placekitten.com/1280/720g" alt="Slide 2" />
</div>
<div class="item">
<img src="http://placekitten.com/1280/720" alt="Slide 3" />
</div>
</div> <a class="left carousel-control" href="#slider" data-slide="prev">
</a>
<a class="right carousel-control" href="#slider" data-slide="next">
</a>
</div>
<div class="main-bottom">
<img src="http://placekitten.com/300/300" alt="Image" /> <a href="contact.html">
<img src="http://placekitten.com/100/100" alt="France" />
</a>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit</p>
</div>
</section>
</div>
</div>
</div>
</div>
<div id="footer">
<div class="container">
<div class="row">
<div class="col-md-9 col-md-push-3">
<p>2013 © All rights reserved.</p>
</div>
</div>
</div>
</div>

The sidebar overlaps with main content is because the element .logo has fixed width(150px) and fixed left/right margin (both 40px), so the the whole width of the .logo element is 230px, which is larger than width of #sidebar element when the page is narrow enough, so #sidebar element is expanded.
Solution:
make the .logo element width dynamic, like:
.logo { width: 80%; margin: 40px auto 70px; }
Then you may have to use <img> tag to show the logo instead of using background.

Related

Place a "col-lg-12" in a responsive container using

I am trying to place Bootstrap breadcrumb navigation in a template.
What I would like is a full-width 100% with a background color, and then within that place a col-lg-12 but I can't figure it out.
This image might help:
<div class="container-fluid darkgrey">
<div class="row">
<div class="col-lg-12">
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item">Home</li>
<li class="breadcrumb-item">Section</a></li>
<li class="breadcrumb-item active" aria-current="page"><?php the_title();?></li>
</ol>
</nav>
</div>
</div>
</div>
I think I might need to "nest" columns but I can't figure it out.
Am I on the right path? Thanks
Read the docs, Luke :-)
Use .container-fluid for a full width container, spanning the entire width of the viewport.
You are using .container-fluid, so you get a fluid, 100% width container. Use .container to get a fixed with container.
Here's a workig JSFiddle.
Also note you have an unbalanced </a> after Section, maybe just a copy-paste error here on SO.
To align the contents to .content width while keeping section background full-page width, you could nest a .container inside your .container-fluid:
.darkgrey {
background-color: #e9ecef;
}
.darkgrey .breadcrumb {
background-color: transparent;
margin-bottom: 0;
padding: .75rem 0;
}
.darkgrey + .container {
padding-top: .75rem;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="container-fluid darkgrey">
<div class="container">
<div class="row">
<div class="col-12">
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href>Home</a></li>
<li class="breadcrumb-item">Section</li>
<li class="breadcrumb-item active" aria-current="page">
Test Post 3
</li>
</ol>
</nav>
</div>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-12">
<h2>Test Post 3</h2>
<p> Lorem ipsum dolor sit amet... </p>
</div>
</div>
Important note: .containers can be placed inside .container-fluids but should not be placed inside another .container.
Another note: you probably don't need the CSS (from the screenshot it looks like your theme already handles that part, but I needed it on SO).

How to make bootstrap corousal responsive

I am making bootstrap corousal of full width and height,The height is responsive but the width is not responsive (i.e) when i resize the window the image starts crop according to the width of the viewport,when it reaches to mobile screen size the left part the corousal crops,Below is the Bootstrap and css code,Can anyone help hoe to make image width responsive,Thanks
<header id="myCarousel" class="carousel slide">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
</ol>
<!-- Wrapper for Slides -->
<div class="carousel-inner">
<div class="item active">
<!-- Set the first background image using inline CSS below. -->
<div class="fill" style="background-image:url('images/corousal1.jpg');"></div>
<div class="carousel-caption">
<h2>Caption 2</h2>
</div>
</div>
<div class="item">
<!-- Set the second background image using inline CSS below. -->
<div class="fill" style="background-image:url('images/corousal2.jpg');"></div>
<div class="carousel-caption">
<h2>Caption 2</h2>
</div>
</div>
<div class="item">
<!-- Set the third background image using inline CSS below. -->
<div class="fill" style="background-image:url('images/corousal1jpg.jpg');"></div>
<div class="carousel-caption">
<h2>Caption 3</h2>
</div>
</div>
<div class="item">
<!-- Set the third background image using inline CSS below. -->
<div class="fill" style="background-image:url('images/corousal4.jpg');"></div>
<div class="carousel-caption">
<h2>Caption 3</h2>
</div>
</div>
</div>
<!-- Controls -->
<a class="left carousel-control" href="#myCarousel" data-slide="prev">
<span class="icon-prev"></span>
</a>
<a class="right carousel-control" href="#myCarousel" data-slide="next">
<span class="icon-next"></span>
</a>
<div class="drbatras-logo">
<img src="images/logo.png" alt="logo"/>
</div>
</header>
CSS
html,
body {
height: 100%;
}
.carousel,
.item,
.active {
height: 100%;
position: relative;
}
.carousel-inner {
height: 100%;
}
/* Background images are set within the HTML using inline CSS, not here */
.drbatras-logo{
position: absolute;
top:60px;
right: 170px;
}
.fill {
width: 100%;
height: 100%;
background-position: center;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
-o-background-size: cover;
}
you can use <img> tag and set class="img-responsive"
<img class="img-responsive" src="img_chania.jpg" alt="Chania" width="460" height="345">
you can use this
<div class="fill" id="fill"> </div>
css
#fill{
background:url('images/corousal1.jpg') no-repeat center center;
background-size:100% auto;
}

Bring carousel caption on top of the overlay

I have this Bootstrap carousel:
HTML:
<div id="carousel-example" class="carousel slide" data-ride="carousel">
<div class="carousel-overlay"></div>
<ol class="carousel-indicators">
<li data-target="#carousel-example" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example" data-slide-to="1"></li>
<li data-target="#carousel-example" data-slide-to="2"></li>
</ol>
<div class="carousel-inner">
<div class="item active">
<img src="http://placekitten.com/1600/600" />
<div class="carousel-caption">
<h3>Meow</h3>
<p>Just Kitten Around</p>
</div>
</div>
<div class="item">
<img src="http://placekitten.com/1600/600" />
<div class="carousel-caption">
<h3>Meow</h3>
<p>Just Kitten Around</p>
</div>
</div>
<div class="item">
<img src="http://placekitten.com/1600/600" />
<div class="carousel-caption">
<h3>Meow</h3>
<p>Just Kitten Around</p>
</div>
</div>
</div>
<a class="left carousel-control" href="#carousel-example" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
</a>
<a class="right carousel-control" href="#carousel-example" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
</a>
</div>
CSS:
.carousel-overlay{
background-color: black;
width: 100%;
opacity: 0.3;
height: 100%;
position: absolute;
z-index: 15;
}
I want the caption and arrow buttons to be on the top the overlay like the carousel indicators. I tried using z-index, but it is not working.
here's a fiddle: http://jsfiddle.net/bM32G/39/
I put the captions and arrow buttons on top of the overlay with z-index in this Fiddle:
http://jsfiddle.net/1xu2fpc8/
I used some !important for simplicity, but it seems to work for me.
To change the color of the content of the carousel you need to refer to, in this case, img. Add the following code to your CSS:
img{
-webkit-filter: sepia(90%) hue-rotate(90deg);
}
Remove or comment out the following line in your HTML:
<div class="carousel-overlay"></div>
You can also look into the following posts:
Tint image using CSS without overlay
CSS image overlay with color and transparency
Since z-index is not working for you..
Try this
.item a img {
opacity: 0.6;
}
.carousel-control {
opacity: 1;
}
.item .carousel-caption {
opacity: 1;
}
FIDDLE

Materialize making slider images responsive

I'm trying to develop a website with Materialize and there is a slider in site. Materialize is responsive and working well at various resolutions. However, When I decrease the screen size, the slider width is decreasing as well (as it should be). But the image in it just getting cropped instead of scaling it to the size of the slider. I added the responsive-img class to the img but nothing changed.
Slider code
<div class="slider">
<ul class="slides">
<li>
<img src="images/slider/slide_1.jpg">
<div class="caption center-align">
<h3>Eraltek Kurumsal</h3>
<h5 class="light grey-text text-lighten-3">Sitemize hoşgeldiniz</h5>
</div>
</li>
<li>
<a href="panoramic/panoramic.html">
<img src="images/slider/slide_2.jpg">
<div class="caption right-align">
<h3>Eraltek Mağaza</h3>
<h5 class="light yellow-text text-darken-1">360 derece mağaza turu için tıklayınız</h5>
</div>
</a>
</li>
<li>
<img src="images/slider/slide_3.jpg">
</li>
<li>
<img src="images/slider/slide_4.jpg">
</li>
<li>
<img src="images/slider/slide_5.jpg">
</li>
</ul>
</div>
Try to define in your css file
.slider .slides li img {
background-size:100% auto;
background-repeat: no-repeat;
}
You should try adding a css
max-width : 100%;
to the <img> tag. Hope this will resolve the issue. Also don't forget to add responsive-img class to <img>
Use img-responsive class with img tag.(you are using responsive-img, It is a bootstrap class. It is not working in materialize design)
$(document).ready(function () {
$('.slider').slider({full_width: true});
});
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<!-- Compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.3/js/materialize.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.3/css/materialize.min.css">
<div class="slider">
<ul class="slides">
<li>
<img class="img-responsive" src="http://lorempixel.com/580/250/nature/1">
<div class="caption center-align">
<h3>This is our big Tagline!</h3>
<h5 class="light grey-text text-lighten-3">Here's our small slogan.</h5>
</div>
</li>
<li>
<img class="img-responsive" src="http://lorempixel.com/580/250/nature/2">
<div class="caption left-align">
<h3>Left Aligned Caption</h3>
<h5 class="light grey-text text-lighten-3">Here's our small slogan.</h5>
</div>
</li>
</ul>
</div>
Try
.slider li img{max-width:100%;height:auto;}

Centering an image in a bootstrap carousel, while maintaining the aspect ratio, and filling the entire carousel?

I have a bootstrap carousel that fills the entire browser window, and I want to have images fit the entire carousel. I got the filling up and maintaining the correct aspect-ratio part done.
Code:
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Carousel indicators -->
<ol class="carousel-indicators" id = "indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
</ol>
<!-- Carousel items -->
<div class="carousel-inner">
<div class="item active">
<div class = "im">
<img src = "images/image.jpg">
<div class="carousel-caption">
<h3>First slide label</h3>
<h6>Lorem ipsum dolor sit amet consectetur…</h6>
</div></div>
</div>
<div class="item">
<div class = "im">
<img src = "images/image2.jpg">
<div class="carousel-caption">
<h3>Second slide label</h3>
<h6>Aliquam sit amet gravida nibh, facilisis gravida…</p>
</div></div>
</div>
<div class="item">
<div class = "im">
<img src = "images/image3.jpg">
<div class="carousel-caption">
<h3>Third slide label</h3>
<h6>Praesent commodo cursus magna vel…</h6>
</div></div>
</div>
</div>
<!-- Carousel nav -->
<a class="carousel-control left" href="#myCarousel" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
</a>
<a class="carousel-control right" href="#myCarousel" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
</a>
CSS:
.im {
height: 100%;
width: 100%;
background-color: red;
float: left;
overflow: hidden;
position:relative;
}
.im img {
min-width: 100%;
min-height: 100%;
}
#indicators {
padding-bottom: 30px;
}
However, the problem is the image doesn't center and that looks kind of strange on smaller screens because all you're seeing is a part of the background and not the main graphic.
Any ideas?
EDIT:
Heres a JSFiddle: http://jsfiddle.net/461q48by/
As you can see the image fits and the aspect ratio is maintained but the image is off center and all you can see are the frog's feet.
Fix your syntax errors.
Take out your extra </div>'s
Move the closing </div> for the myCarousel div to the end of the carousel. The carousel includes the carousel nav area.
Then mess with your CSS but this should take care of it.

Resources