P.V. P.V. - 1 year ago 43
CSS Question

carousel change text when affix triggers

I'm working on a project that's a bit like a news page and I manage to make the news show in a carousel (without images, only text) and now I added an affix to the carousel so when I scroll down keeps changing the news... However I want to format the text when the affix triggers because it looks quite small.
Any idea on how I could display the text in one line instead of two?

I almost forgot, is there any way to make the affix with a 2% margin ? I have been trying but it only makes the margin in one part of the screen...



body{
height: 100%;
}

#divHead{
margin:1%!important;
background-image: url(../img/bhead.jpg);
background-size: cover;
background-repeat: no-repeat;
color:white;
}
#myCarousel{
background-color:rgba(144,195,212,0.2);
border: 1px solid black;
margin-left:2%;
margin-right: 2%;
color:aliceblue;
}

.divNoticias{
margin: 1%;
text-align: center;

}
#newsImg{
max-height: 200px;
max-width: 200px;
}


#divAire{
margin: 1% !important;
}

.mid{
color: black;
text-align: center;
}

/*
Bootstrap Carousel Fade Transition (for Bootstrap 3.3.x)
CSS from: http://codepen.io/transportedman/pen/NPWRGq
and: http://stackoverflow.com/questions/18548731/bootstrap-3-carousel-fading-to-new-slide-instead-of-sliding-to-new-slide
Inspired from: http://codepen.io/Rowno/pen/Afykb
*/
.carousel-fade .carousel-inner .item {
opacity: 0;
transition-property: opacity;
}

.carousel-fade .carousel-inner .active {
opacity: 1;
}

.carousel-fade .carousel-inner .active.left,
.carousel-fade .carousel-inner .active.right {
left: 0;
opacity: 0;
z-index: 1;
}

.carousel-fade .carousel-inner .next.left,
.carousel-fade .carousel-inner .prev.right {
opacity: 1;
}

.carousel-fade .carousel-control {
z-index: 2;
}

/*
WHAT IS NEW IN 3.3: "Added transforms to improve carousel performance in modern browsers."
Need to override the 3.3 new styles for modern browsers & apply opacity
*/
@media all and (transform-3d), (-webkit-transform-3d) {
.carousel-fade .carousel-inner > .item.next,
.carousel-fade .carousel-inner > .item.active.right {
opacity: 0;
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
.carousel-fade .carousel-inner > .item.prev,
.carousel-fade .carousel-inner > .item.active.left {
opacity: 0;
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
.carousel-fade .carousel-inner > .item.next.left,
.carousel-fade .carousel-inner > .item.prev.right,
.carousel-fade .carousel-inner > .item.active {
opacity: 1;
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
}

.item {
display: none;
position: relative;
.transition(5s ease-in-out left);
}

.affix {
top: 0;
width: 100%;
margin:0!important;
left:0!important;
background-color:rgba(144,195,212,1)!important;
z-index: 9999!important;
animation: affixFadeIn 3s ease-in;
-webkit-animation: affixFadeIn 3s;
height: 50px;
}
.affix .item h3{
margin-top:10px;
font-size: 1vw!important;
}

.affix .item p{
margin-top: 0px !important;
font-size: 0.75vw!important;
}


@keyframes affixFadeIn
{
from {opacity: 0;}
to {opacity: 1;}
}

@-webkit-keyframes affixFadeIn
{
from {opacity: 0;}
to {opacity: 1;}
}


.affix + .container-fluid {
padding-top: 70px;
}

.divPublicidad{
width: 300px;
background-color: green;
position: absolute;
right: 0px;
margin-right: 1% !important;
height: 100%;
}

<!DOCTYPE html>
<html>
<head>
<title>Noticias Creativas de gente que se entero tres días después</title>
<meta name="description" content="Página web de noticias que es gestionada por personas que no sabían muy bien de que iba esto del periodismo y mantener a las personas informadas.">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--Boostrap-->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<!--my css-->
<link rel='stylesheet' media='screen and (min-width: 961px)' href='css/desc.css'>
<link rel='stylesheet' media='screen and (max-width: 960px)' href='css/desc.css'>
</head>
<body>

<div id="divHead" class="jumbotron text-center"><h1>NoticiasNET</h1>
<br>
<div id="myCarousel" class="carousel slide carousel-fade" data-ride="carousel" data-spy="affix" data-offset-top="330">
<!-- Carousel de noticias hemos de implementar leer del JSON tmb -->
<div class="carousel-inner">
<div class="item active">
<h3>Los Angeles</h3>
<p>LA is always so much fun!</p>
</div>
<div class="item">
<h3>Chicago</h3>
<p>Thank you, Chicago!</p>
</div>
<div class="item">
<h3>New York</h3>
<p>We love the Big Apple!</p>
</div>
</div>
</div>
</div>
<div class="divPublicidad"></div>
<div class="divNoticias">
<h3>Noticia Sobre cosas raras</h3>
<p>pequeña descripcion de la noiticia que mola mucho aunque no lo creas</p>
<p> fecha y hora</p>
</div>
<div class="divNoticias">
<img>
<h3>Noticia Sobre cosas raras</h3>
<p>pequeña descripcion de la noiticia que mola mucho aunque no lo creas</p>
<p> fecha y hora</p>
</div>
<div class="divNoticias">
<img>
<h3>Noticia Sobre cosas raras</h3>
<p>pequeña descripcion de la noiticia que mola mucho aunque no lo creas</p>
<p> fecha y hora</p>
</div>

<div class="divNoticias">
<h3>Noticia Sobre cosas raras</h3>
<p>pequeña descripcion de la noiticia que mola mucho aunque no lo creas</p>
<p> fecha y hora</p>
</div>
<div class="divNoticias">
<img>
<h3>Noticia Sobre cosas raras</h3>
<p>pequeña descripcion de la noiticia que mola mucho aunque no lo creas</p>
<p> fecha y hora</p>
</div>
<div class="divNoticias">
<img>
<h3>Noticia Sobre cosas raras</h3>
<p>pequeña descripcion de la noiticia que mola mucho aunque no lo creas</p>
<p> fecha y hora</p>
</div>

<div id="divPub>licidadMovil"><p>publicidad</p></div>
</body>
</html>




Answer Source

You have CSS that's overwriting the font size.

.affix .item h3{
margin-top:10px;
font-size: 1vw!important;
}

Change the value for font-size on this to change the font size.

Update: You can change the H3 and P tags to be display inline block.

Below example is the H3 tag:

.affix .item h3 {
margin-top: 10px;
font-size: 1vw !important;
display:inline-block;
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download