Centering left-aligned text - html

I want to center left-aligned text in the yellow box (txtbox).
It looks like that now:
and it want it to be looking like this:
HTML:
<div class="content container small">
<div class="txtbox">
<header style="text-align:left;">
<h2>I AIN'T</h2>
<h2>AN ARTIST.<h2>
<h2>I'M A</h2>
<h2>BEAST!</h2>
</header>
</div>
<footer>
More
</footer>
</div>
CSS:
.container.small {
/* width: (containers) * 0.75; */
width: 900px;
}
.txtbox{
width:800px;
margin:0 auto;
background-color:yellow;
text-align:center;
}

.txtbox header h2{
padding-left: 50px;
}

.txtbox header {
display: grid;
grid-template-columns: 1fr;
width: fit-content;
margin: auto;
background-color: yellow;
text-align: left;
align-items: center;
}
This will put your text in a box. Align the text to the left of the box and fitting the box for the text you have.
Then it will center the box.
This also works when you don't know the width or height.
And remove
style="text-align:left;"
out of the header.

Get rid of the inline style in your
<header style="text-align:left;">
it overrides the stylesheet; leave just
<header>

It took me a little bit to figure out what "centered left-aligned" text mean.
If I understand you correctly, You want the text to be left-aligned on a vertical axis, but centered on the page.
If that is what you want than you can do that by centering your inner header tag like so: width: 132px; margin: 0 auto;
Here's a fiddle to demonstrate:
http://jsfiddle.net/u4sj7/

header h2 { position: relative; left : 30% /* percentage of yellow box */; }

<div class="txtbox">
<div class="centerblock">
<header style="text-align:left;">
<h2>I AIN'T</h2>
<h2>AN ARTIST.<h2>
<h2>I'M A</h2>
<h2>BEAST!</h2>
</header>
</div>
</div>
CSS:
.centerblock {
display:inline-block;
margin:auto;
}

HTML:
<div class="content container small">
<div class="txtbox">
<header>
<h2>I AIN'T</h2>
<h2>AN ARTIST.</h2>
<h2>I'M A</h2>
<h2>BEAST!</h2>
</header>
</div>
<footer> More
</footer>
</div>
Add this to CSS:
.txtbox header {
display: block;
margin: 0 auto;
}

Related

How to remove the margin from div

I'm making a model of a website in HTML and Css and I do not know how to remove this little space on my div element
I've tried to put padding and margin to 0 but nothing happens
Here's my CSS code
body{
padding-left:269px;
padding-right:269px;
background-color:black;
margin: 0;
}
.blanco{
background-color: #fff;
height:780px;
width: 1366px;
padding:0;
margin:0;
}
The div element is named "blanco"
The arrows are a CSS too
Here's the HTML:
<div class="setaEsquerda">
<img src="images/Path Copy.svg" alt="">
</div>
<div class="setaDireita">
<img src="images/Path.svg" alt="">
</div>
and here's the css
.setaEsquerda{
position: absolute;
top: 42.1%;
border-radius: 5px;
margin-left: 36px;
}
.setaDireita{
position: absolute;
top: 42.1%;
border-radius: 5px;
margin-left: 1290px;
}
You are specifing the size of your div.blanco .. Any bigger screen than that will also show the <body> behind it, if .blanco ends there.
I am just assuming and i think the issue you have may be because of these arrows. They are pushing the other content down.
You may want to divide the body into 3 section, then apply the style you want and it should be affective
<body>
<div class="main">
<div class="left-col">arrow left</div>
<div class="content">
<h1>Some text</h1>
<button>Hey</button>
</div>
<div class="right-col">arrow right</div>
</div>
</body>
<style>
.main {
display: grid;
grid-template-columns: auto 1fr auto;
}
</style>
</html>
try not to give a size for your Blanco Class in your CSS code.
.blanco{
background-color: #fff;
padding:0;
margin:0;
}

footer collapsing above div containing transparent background image in body element

I want to make a background image transparent and found a good answer here. But my footer is collapsing to the top of my page underneath my header. I can see the transparent image in the body, but my main article continues below the footer with the html background color applied. What is causing the footer to collapse? The section which is the parent container for the div's has a defined width. Any help would be appreciated.
html {background: #95A3C2;}
body {
background: white;
background-image: url(_images/pg_p_lewis_bckgrnd.jpg);
width: 960px;
margin: 0 auto 0;
font-family: "minion-pro";
}
section {
width: 960px;
display: block;
position: relative;
}
#trns {
height: auto;
opacity: 0.2; filter: alpha(opacity=20);
position: absolute;
}
#trnsb {
height: auto;
}
#heading {
width: 960px;
}
<body>
<header>
<div id="colA">
</div>
</header>
<section>
<div id="trns">
<div id="trnsb">
<div id="heading">
<div id="colD">empty</div>
</div>
<div id="main">
<div class="text">
<p>text</p>
<p>text</p>
</div>
<div class="image">
<p>Image Gallery</p>
<p><span class="caption">Center image vertically on page and hover to enlarge.</span></p>
<p><img class="img-zoom" src="_images/RL_LEWIS_Alex_KCC_1197_Sur_1.jpg" class="img-thumbnail" alt="lewis land grant" width="259" height="387"></p>
</div>
</div>
</div>
</div>
</section>
<footer>
<div id=copyright>copyright 2016 by Barton Lewis</div>
<div id=hosting>hosting by simply hosting</div>
</footer>
</body>
</html>
You have given #trns a position of absolute. Doing this removes the element from the normal flow of the document. So there is nothing 'pushing' the footer down. From your code I couldn't see a reason for giving #trns an abolute position. You should be able to just remove this declaration from your css.

Vertical center on middle element with flex

I have very specific request for centering elements so I decided to try flexbox.
The request is following. I have 3 elements stacked vertically.
Header, content and footer.
A special condition is there to have middle element "content" centered on page (vertically and horizontaly) and header with footer stick on it from top and down. It should works with window resize.
There is hard-coded solution for better demonstration.
http://codepen.io/anon/pen/oXjVmE
I tried to solve that with flex box, but only what I get is that all 3 elements are centered together.
I am looking how to tell flex-box "First and last element should be same and max possible height"
http://codepen.io/anon/pen/GJpeYY
html
<div class="wrapper">
<div class="header">
<h1>Header</h1>
<h2>Subheader</h2>
<p>Text</p>
</div>
<div class="centered">
Centered Text
</div>
<div class="footer">
Some tiny footer
</div>
</div>
css
.wrapper {
height:500px;
background-color:lightgreen;
.display(flex);
.flex-direction(column);
.align-items(center);
.justify-content(center);
text-align: center;
}
.header {
background-color:gold;
}
.centered {
height: 50px;
line-height: 50px;
background-color:deepskyblue;
}
.footer {
background-color:tomato;
}
You can achieve that result by simply using flex: inline-flex, and adding an outer container, like in the following
running demo
I've made the centered text content editable, so edit it and see that header and footer stretches themselves along with it.
.container {
text-align: center;
background-color: lightgreen;
}
.wrapper {
height: 500px;
display: inline-flex;
flex-direction: column;
justify-content: center;
}
.header {
background-color: gold;
}
.centered {
height: 50px;
line-height: 50px;
background-color: deepskyblue;
}
.footer {
background-color: tomato;
}
<div class="container">
<div class="wrapper">
<div class="header">
<h1>Header</h1>
<h2>Subheader</h2>
<p>Text</p>
</div>
<div class="centered" contentEditable="true">
Centered Text - I'm editable, so... EDIT ME !!!!
</div>
<div class="footer">
Some tiny footer
</div>
</div>
</div>
Also FlexyBoxes tool is worthy a try for this kind of things.
remove wraper height:500px; and add height:100vh;
it is viewport height and i hope you will get what you want.

A better way to float text on top of an image with varying container widths

I'm redesigning a site and the different sections (header, banner image, main, etc.) have a background that stretches all the way across, however the content is contained to a certain width and that box is centered.
However, in the design the "banner image" (which is a image below the header but above the main content) will extend beyond the width of the rest of the content. At first this was easy until a need arose to have text on top of the banner image, and that text would need to line up with the rest of the text.
I cannot use CSS background image because on some pages the banner image area will be a slider, which requires tags.
I have a working solution, but it seems clunky and I was hoping to find a better method: http://jsfiddle.net/PkStg/10/
HTML:
<div class="header">
<div class="content-wrapper">
header text
</div>
</div>
<div class="banner">
<div class="content-wrapper">
<div class="banner-text-outer">
<div class="banner-text-inner">
<h2>banner text header</h2>
<p>banner text paragraph</p>
</div>
</div>
</div>
<div class="banner-image-wrapper">
<img src="http://www.brokenbowlakeguide.com/rainbow-trout-1.jpg" />
</div>
</div>
<div class="main-content">
<div class="content-wrapper">
main content text
</div>
</div>
CSS:
.header, .banner, .main-content { width: 100%; }
.header { background: red;}
.banner { background: green; }
.main-content { background: yellow; }
.content-wrapper {
margin: 0 auto;
max-width: 300px;
}
.banner-text-outer {
position: relative;
}
.banner-text-inner {
position: absolute;
top: 10px;
}
.banner-image-wrapper {
margin: 0 auto;
max-width: 400px;
min-width: 300px;
font-size: 0;
}
.banner-image-wrapper img {
width: 100%;
}
I know that you wanted to not use background-image, but here is a solution which uses that for anyone else who sees the page.
Perhaps your slider could make use of the background-image?
This should do it:
jsFiddle
HTML
<body>
<div class="header">
<div class="content-wrapper">
header text
</div>
</div>
<div class="banner">
<div class="content-wrapper">
<div class="banner-text-outer">
<div class="banner-text-inner">
<h2>banner text header</h2>
<p>banner text paragraph</p>
</div>
</div>
</div>
</div>
<div class="main-content">
<div class="content-wrapper">
main content text
</div>
</div>
</body>
CSS
.header, .banner, .main-content { width: 100%; }
.header { background: red;}
.banner { background: green; }
.main-content { background: yellow; }
.content-wrapper {
margin: 0 auto;
max-width: 300px;
}
.banner {
background: green url("http://www.brokenbowlakeguide.com/rainbow-trout-1.jpg") no-repeat;
background-size: contain;
background-position: center;
min-height: 150px;
}

How do I get 2 divs within another div centred and floated to the right?

I have 2 divs on my page that I want to appear with one centred relative to the page (the page title) and the other floated to the right (a navigation bar). I can't get the title centred relative to the page. The best I can do is have it centred relative to the space remaining to the left of the navigation bar.
This demonstrates the problem I'm having.
<style>
.page {
width: 400px;
margin: 0 auto;
background: red;
}
.navbar {
float: right;
}
.title {
text-align: center;
}
</style>
<div class='page'>
<div class='navbar'>
navbar
</div>
<div class='title'>
<h1>TITLE GOES HERE</h1>
</div>
</div>
Is there a simple solution to this?
How is this?
<style>
.page {
width: 400px;
margin: 0 auto;
background: red;
position:relative;
}
.navbar {
position:absolute;
right:2px;
}
.title {
text-align: center;
}
</style>
<div class='page'>
<div class='navbar'>
navbar
</div>
<div class='title'>
<h1>TITLE GOES HERE</h1>
</div>
</div>