In my project, I implement bootstrap and I use it's grid system. I create a row, and then I add a span inside the row which acts as a column (col-12).
This span I use is underlined, and I add <br> elements within the span to separate line. The first line auto-indents to the right more than the other two lines. I attempt to use the tag, however this doesn't work as my text is underlined and it creates an unwanted underline before the text.
Does anybody know the issue? Thank you.
Here is my code:
.mainBodyTxt {
color: white;
position: relative;
font-family: 'Roboto', sans-serif;
font-size: 54px;
z-index: 2;
left: 200px;
}
.container-fluid {
background:lightgrey;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="" crossorigin="anonymous">
<div class="container-fluid">
<div class="row">
<!-- <div class="col-md-4 col-lg-6">-->
<u style="color: white;"><span class="col-12 mainBodyTxt">I really like <br>
Blue <br>Sandwiches</span> </u>
</div>
</div>
Your layout is giving you a right indentation probably because you're using a <u> outside the <span class='col-12'>
col-x elements should be direct descendants of row elements!
To solve this, you could:
Put the <u> tag inside the span (example 1)
Remove the <u> tag and give span the CSS attribute text-decoration:underline (example 2)
Remove the <span> tag and give u the classes col-12 mainBodyTxt (example 3)
.mainBodyTxt {
color: white;
position: relative;
font-family: 'Roboto', sans-serif;
font-size: 54px;
z-index: 2;
left: 200px;
}
.container-fluid {
background:lightgrey;
}
.mainBodyTxtUnderlined{
color: white;
text-decoration:underline;
position: relative;
font-family: 'Roboto', sans-serif;
font-size: 54px;
z-index: 2;
left: 200px;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="" crossorigin="anonymous">
<!-- example 1 -->
<div class="container-fluid">
<div class="row">
<span class="col-12 mainBodyTxt"><u style="color: white;">I really like <br>
Blue <br>Sandwiches</u></span>
</div>
</div>
<br>
<!-- example 2 -->
<div class="container-fluid">
<div class="row">
<span class="col-12 mainBodyTxtUnderlined">I really like <br>
Blue <br>Sandwiches</span>
</div>
</div>
<br>
<!-- example 3 -->
<div class="container-fluid">
<div class="row">
<u class="col-12 mainBodyTxt">I really like <br>
Blue <br>Sandwiches</u>
</div>
</div>
Related
I know there are tons of questions similar to mine but the complexities of flexbox are just overwhelming me. What I need seems very simple. I want the body to be equal to the height and width of the viewport. I then want everything inside to scale relative to its parents. However this is not what is happening. I have a <div class=flex-grow-1> and then I have a child <div h-100> nested inside. I would expect the height of the child to match the height of the parent. But... no. Not what is happening at all.
How do I get this image to resize to fit within the pink area? How do I get the height of this row to match the height of the pink area?
body {
height: 100%;
width: 100%;
position: absolute;
}
#pink-banner {
width: 100%;
height: 90%;
background-color: #FFCFC8;
}
.title {
font-family: 'Pacifico', cursive;
font-size: 70px !important;
color: #48555E;
}
.thick-border {
border: solid blue 5px;
}
.header {
display: flex;
justify-content: center;
}
.main-text {
font-family: 'Source Code Pro', monospace;
font-size: 45px;
color: #ffffff;
text-shadow: 2px 2px 5px #4a4a4a;
}
.text-shadow{
text-shadow: 2px 2px 10px #b3b3b3;
}
<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css"
integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<!-- JS, Popper.js, and jQuery -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"
integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.0/dist/umd/popper.min.js"
integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"
integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI"
crossorigin="anonymous"></script>
<title></title>
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght#600&family=Pacifico&display=swap"
rel="stylesheet">
</head>
<body>
<div id="pink-banner" class="d-flex flex-column">
<div class="shadow mb-0 pb-4 bg-light rounded-bottom header">
<h1 class="text-center mb-0 title">Test</h1>
</div>
<div class="row flex-grow-1 thick-border">
<div class="col-sm float-sm-right my-auto justify-content-center text-center">
<h2 class="w-75 float-right main-text">
Words words
</h2>
</div>
<div class="col-sm float-left-sm h-100 thick-border">
<img src="https://upload.wikimedia.org/wikipedia/commons/8/89/Portrait_Placeholder.png" alt="">
</div>
</div>
</div>
</body>
Here is the JSFiddle.
Thank you for any help!
Problem is the image not getting adjusted to space you have for the parent. Give the bootstrap class - img-fluid to the img tag , and it should work fine.
<img src="https://upload.wikimedia.org/wikipedia/commons/8/89/Portrait_Placeholder.png" class="img-fluid" alt="">
See if giving it solves the problem
I created a simple page with Bootstrap and would like to have my blockquotes (including the left quotation mark added with a CSS pseudoselector) centered on while being mobile responsive.
Additionally, I tried setting the blockquote to have a width of 500px in CSS, and it made it look right on my laptop, but caused the quote text to go off the page on mobile rather than scaling down. So I removed the width declaration.
Here's my current CSS for the blockquote and corresponding quotation mark:
blockquote {
font-family: Georgia, serif;
font-style: italic;
margin: 3em auto;
padding: 0.35em 40px;
line-height: 1.45;
position: relative;
color: #383838;
}
blockquote p {
font-size: 1em !important;
}
blockquote:before {
display: block;
padding-left: 10px;
content: "\201C";
font-size: 3em;
/* Element with abolute positioning is positioned relative to nearest positioned ancestor */
position: absolute;
/* Offsets from edges of element's containing block, ancestor to which element is relatively positioned */
left: -3px; /* Negative moves it left */
top: -13px; /* Negative moves it toward top */
color: #7a7a7a;
}
blockquote cite {
color: #999;
font-size: 14px;
margin-top: 5px;
}
add display: inline-block;text-align: left; to blockquote and also text-align: center; to .jumbotron in css:
body {
margin-top: 3em;
font-family: Helvetica;
}
h1 {
text-transform: uppercase;
}
img {
width: 90%;
}
.panel img {
height: 400px;
width: auto;
}
.panel h4 {
font-size: 10px;
}
.jumbotron {
text-align: center;
}
.jumbotron blockquote {
font-family: Georgia, serif;
font-style: italic;
margin: 3em auto;
padding: 0.35em 40px;
line-height: 1.45;
position: relative;
color: #383838;
display: inline-block;
text-align: left;
}
blockquote p {
font-size: 1em !important;
}
blockquote:before {
display: block;
padding-left: 10px;
content: "\201C";
font-size: 3em;
/* Element with abolute positioning is positioned relative to nearest positioned ancestor */
position: absolute;
/* Offsets from edges of element's containing block, ancestor to which element is relatively positioned */
left: -3px; /* Negative moves it left */
top: -13px; /* Negative moves it toward top */
color: #7a7a7a;
}
blockquote cite {
color: #999;
font-size: 14px;
margin-top: 5px;
}
ul {
list-style: none;
text-align: left;
/* Bottom set to 3em to match margin above ul created by blockquote */
margin: 0 auto 3em auto;
}
<html lang="en">
<head>
<meta charset="UTF-8">
<title>David Hume</title>
<!-- Ensures proper rendering and touch zooming -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="styles.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="script.js"></script>
</head>
<body>
<!-- Provides a responsive, fixed-width container. Needed as outermost wrapper in order for Bootstrap grid system to work correctly -->
<div class="container">
<!-- Big grey box for calling extra attention to content -->
<div class="jumbotron">
<div class="row">
<div class="col-xs-12">
<div class="text-center">
<h1>David Hume</h1>
<h4>Scottish Enlightenment Philosopher, Historian, Economist, Essayist</h4>
<div class="thumbnail">
<img src="https://cdn.theatlantic.com/assets/media/img/2015/09/03/BOB_Essay_Opener_WEBCrop/1920.jpg?1441298243" alt="Portrait of David Hume">
<div class="caption">"Portrait of David Hume," 1754, by Allan Ramsay</div>
</div>
</div> <!-- End of text-center div -->
<blockquote>
<p>A wise man proportions his belief to the evidence.</p>
<footer class="blockquote-footer"><cite>David Hume</cite></footer>
</blockquote>
</div> <!-- End of col-xs-12 div -->
</div> <!-- End of row div -->
<div class="row">
<div class="col-xs-12 col-sm-10 col-sm-offset-1 col-md-8 col-md-offset-2">
<h4 class="text-center">A brief timeline in events of David Hume's life:</h4>
<ul>
<li><strong>1711</strong> – Born as David Home in Edinburgh, Scotland</li>
<li><strong>1713</strong> – Father dies</li>
<li><strong>1723</strong> – Enrolls at University of Edinburgh at the age of 12 (14 was typical)</li>
<li><strong>1734</strong> – Changes surname to Hume</li>
<li><strong>1739</strong> – Publishes Books 1 and 2 of <em>A Treatise on Human Nature</em></li>
<li><strong>1748</strong> – Publishes <em>An Enquiry Concerning Human Understanding</em></li>
<li><strong>1751</strong> – Publishes <em>An Enquiry Concerning the Principles of Morals</em></li>
<li><strong>1776</strong> – Dies at the age of 65</li>
</ul>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="text-center">Works</h3>
</div>
<div class="panel-body">
<div class="row text-center">
<div class="col-md-6">
<h5>An Enquiry Concerning Human Understanding</h5>
<img src="https://images-na.ssl-images-amazon.com/images/I/51RE8VsWyGL.jpg" alt="An Enquiry Concerning Human Understanding">
<br><br>
<h5>An Enquiry Concerning Human Understanding</h5>
<img src="https://images-na.ssl-images-amazon.com/images/I/51RE8VsWyGL.jpg" alt="An Enquiry Concerning Human Understanding">
</div>
<div class="col-md-6">
<h5>Dialogues Concerning Natural Religion</h5>
<img src="https://images-na.ssl-images-amazon.com/images/I/51RE8VsWyGL.jpg" alt="Dialogues Concerning Natural Religion">
<br><br>
<h5>An Enquiry Concerning Human Understanding</h5>
<img src="https://images-na.ssl-images-amazon.com/images/I/51RE8VsWyGL.jpg" alt="An Enquiry Concerning Human Understanding">
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<blockquote>
<p>Were it not for his infidel writings, every body would love him.</p>
<footer class="blockquote-footer"><cite>James Boswell</cite></footer>
</blockquote>
<h4 class="text-center">Learn more on Wikipedia.</h4>
</div>
</div>
</div>
</div>
<footer class="text-center">
<hr>
<p>Written and coded by Natalie Cardot</p>
</footer>
</div>
</body>
</html>
I'm doing a site and I'm starting with the mobile stylesheet first.
But the container-fluid's width isn't the same as the window's width.
What I tried to do to fix this was:
.container-fluid{
width: 105%
}
The problem now is that when I make the window a little smaller, it's still not enough, but when I make the window a little bit bigger, it's TOO MUCH, when I do that a scroll bar appears at the bottom.
100% doesn't work since I already said that it's not the full width of the window.
Here's the entire body from the HTML file:
<body>
<!-- Introduction -->
<div id="introduction" class="container-fluid">
<div class="row">
<header>
<h1> Mosescu Bogdan Gabriel </h1>
<img id="profilepic" src="profilepic.png" />
<h2> Web Designer | Motion Graphics Artist </h2>
</header>
</div>
</div>
<!-- //Introduction// -->
<div id="about" class="container-fluid">
<div class="row">
<h1 id="about-title"> Who I am </h1>
</div>
</div>
</body>
and this is the CSS file:
/*Introduction CSS */
#introduction{
background-color: #542437;
color: white;
margin-top: -21px;
}
#introduction header{
text-align: center;
}
#introduction header h1{
font-family: montserrat;
font-weight: bold;
}
#introduction header h2{
font-family: montserrat;
font-weight: normal;
font-size: 1em;
}
#profilepic{
border-radius: 100%;
width: 150px;
height: 150px;
}
/* //Introduction CSS// */
/* About CSS */
#about{
background-color: #f2f2f2;
color: #1a1a1a;
text-align: center;
margin-top: -24px;
}
#about-title{
font-family: montserrat;
font-weight: bold;
font-size: 2.25em;
border-bottom: solid 1px black;
}
Bootstrap containers are padded.
.container-fluid {
padding-right:15px;
padding-left:15px;
margin-right:auto;
margin-left:auto
}
You need to remove the padding.
.container-fluid {
padding-right:0;
padding-left:0;
margin-right:auto;
margin-left:auto
}
Edit: This is a bare bones example. If you copy this and paste into a new .html document you'll see no padding on the container. If you then remove the container-fluid override you'll see padding.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<!-- put your override styles here - AFTER you include Bootstrap -->
<link href="style-mobile.css" rel="stylesheet">
</head>
<style>
/* override Bootstrap's container */
.container-fluid {
padding-right:0;
padding-left:0;
margin-right:auto;
margin-left:auto
}
</style>
<body>
<div class="container-fluid">
This text hits the left side of the viewport.
</div>
</body>
</html>
Edited HTML example to include new css link
Edit: Bootstrap 4
#Dagrooms commented: "The best way to do this in Bootstrap 4 is to add px-0 to your container-fluid div."
This will remove the padding from the left and right of the container, so that it will touch the sides of the browser viewport.
<div class="container-fluid px-0">
This text hits the left side of the viewport.
</div>
Try this, wrap all the content inside container-fluid with a bootstrap row class. It should work, thanks.
<div id="introduction" class="container-fluid">
<div class="row">
<header>
<h1> Mosescu Bogdan Gabriel </h1>
<img id="profilepic" src="profilepic.png" />
<h2> Web Designer | Motion Graphics Artist </h2>
</header>
</div>
</div>
<div id="about" class="container-fluid">
<div class="row">
<h1 id="about-title"> Who I am </h1>
</div>
</div>
If you just change .container-fluid that won't work because the row and col inside the container all get their own corrections. Try adding full-width to your container-fluid and then adding this:
.full-width { padding-left: 0; padding-right: 0; }
.full-width .row { margin-right: 0; margin-left: 0; }
.full-width .col-md-12 { padding-left: 0; padding-right: 0; }
With Bootstrap 4:
<div class="container-fluid p-0">
<div class="row m-auto">
your content here
</div>
</div>
After a long time of searching and trying out what did it for me in the end was a "w-100" in the "col-xs-12" div tag.
<div class="container-fluid">
<div class="row">
<div class="col-xs-12 w-100">
My content that did not span 100% now with w-100 it does
</div>
</div>
</div>
<div className="container-fluid p-0 m-0 row justify-content-center" >
If you use bootstrap, you can use p-0 and m-0 and they will set the 15px padding from .container-fluid and -15px margin from .row to 0.
I guess there are many ways to do this. in Bootstrap 4, all you have to do is wrap the Container in a Div with Class=Row
<div class="Row">
<header class="container-fluid">
<nav class="navbar navbar-dark bg-secondary">
<h1 class="navbar-brand">Try this out</h1>
</nav>
<header>
</div>
This is the only thing I could get to work, after trying most of these answers.
css:
#mydiv {
margin: 0 -9999rem;
padding: 0.25rem 9999rem;
background-color:#2A2A52
}
html:
<div class="container-fluid px-0">
<div id="mydiv">
<div class="row">
<div class="col-md-12">
<p>YOUR CONTENT HERE</p>
</div>
</div>
</div>
</div>
note: I needed to specify px-0 on the container and wrap the row in a separate div in order for the text to line up horizontally with additional text on the page that was part of a typical container-fluid div.
If none of this works try:
*{margin:0;padding:0}
to remove the padding/margin that might be overlapping on your code. It worked for me, since adding a row wrapping the container-fluid created a horizontal scroll on my page.
I have an image that takes up the fold, below a fixed nav. I Want to vertical align: middle the #fold-text and chevron over the image.
html markup:
<div class="row">
<img class="background-image" src="images/1400px_splash.jpeg">
<div id="fold-container">
<div id="fold-text">
Sign up to learn about upcoming changes!
</div>
<div class="fa fa-chevron-down"></div>
</div>
</img>
</div>
This CSS below usually works when I want to center one div within another, but not luck on this (maybe because the img height is set to "auto" ? ) . Can anyone tell me how to correct this?
.background-image {
height: auto;
width: 100%;
display: table;
}
#fold-container {
display: table-cell;
vertical-align: middle;
}
#fold-text {
font-size: 1.6em;
font-weight: bold;
background-color: rgba(black, 0.3);
color: white;
display: table-cell;
}
.fa.fa-chevron-down {
z-index: 500;
color:white;
text-align: center;
font-size: 2em;
font-weight: normal;
display: table-cell;
}
Your desired markup:
<div class="row">
<img class="background-image" src="images/1400px_splash.jpeg">
<div id="fold-container">
<div id="fold-text">
Sign up to learn about upcoming changes!
</div>
<div class="fa fa-chevron-down"></div>
</div>
</img>
</div>
... is not valid HTML. <img> tags don't contain any other markup, so what the browser sees is more like this:
<div class="row">
<!-- note the self closing img tag -->
<img class="background-image" src="images/1400px_splash.jpeg"/>
<div id="fold-container">
<div id="fold-text">
Sign up to learn about upcoming changes!
</div>
<div class="fa fa-chevron-down"></div>
</div>
<!-- </img> don't know what to do with this, because img tags close themselves -->
</div>
What you need to do is more like this:
<div class="row">
<div id="fold-container">
<div id="fold-text">
Sign up to learn about upcoming changes!
</div>
<div class="fa fa-chevron-down"></div>
<img class="background-image" src="images/1400px_splash.jpeg"/>
</div>
</div>
... and just make sure the appropriate stylings are added to your elements to position them appropriately.
I am using skeleton css framework, I want to vertically align my fontawesome icon to the right of a textarea, but it seems the common "vertical-align:middle; display: table-cell;" doesn't work. I also want when the textarea resizes, the icon still aligns in the middle, without hard code a height inside the style, is it possible?
<link href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.css" rel="stylesheet"/>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<style type="text/css">
.icon {
margin-left: 1em;
vertical-align: middle;
display: table-cell;
}
</style>
<div class="row">
<div class="six columns">
<label for="inputA">labelA</label>
<textarea class="u-full-width" id="inputA" type="text"></textarea>
</div>
<div class="one colum">
<span class="icon"> <i class="fa fa-check-circle"></i> </span>
</div>
</div>
You may need to fake it, due to the way skeleton styles its columns.
As such, you can use absolute positioning to offset the icon as necessary:
.six.columns {
position: relative; /* <-- ensure the icon positions relative to the parent column */
}
#inputA {
margin-bottom: 0; /* <-- remove the textarea margin, making the icon look like its not centered */
}
.icon {
position: absolute; /* <-- position the icon */
/* transform:translateY(-50%); OPTIONAL, use for true vertical alignment */
top: 50%;
right: -20px;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.css" rel="stylesheet" />
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<div class="row">
<div class="six columns">
<label for="inputA">labelA</label>
<textarea class="u-full-width" id="inputA" type="text"></textarea>
<span class="icon"> <i class="fa fa-check-circle"></i> </span>
</div>
<div class="one column">
</div>
</div>
You can try creating a javascript function wich reubicates the icon. Anyways, it could be a little bit of trouble if you're handling with many dinamic icons/textareas.
css:
.icon {
margin-left: 1em;
vertical-align: middle;
display: table-cell;
position:absolute; <--- additions
padding-top:52px; <--- additions
padding-left:269px; <--- additions
}
HTML (Notice the onClick="resiz()" instruction)
<textarea onClick="resiz()" class="u-full-width" id="inputA" type="text"></textarea>
<span id="ico" class="icon"> <i class="fa fa-check-circle"></i> </span>
JavaScript
document.resiz=function(){
var he = document.getElementById("inputA").offsetHeight;
var wi = document.getElementById("inputA").offsetWidth;
document.getElementById("ico").style.paddingTop=(he/2+20)+'px';
document.getElementById("ico").style.paddingLeft=wi+'px';
}
Here's the code: https://jsfiddle.net/ko2dzcfc/
You can also make the resiz() instruction to execute when the page loads, so it will automatically place the icon correctly at start, and avoid editing the css.
Update: I tested it in Firefox, and it worked well. In chromium it does not work so well. Maybe you'll have to edit the code for differents browsers