I'm having issues setting up a container div keeping text within the container div - html

For some reason the body tag settings spill into the container div and text in the p tag goes out of the container div boundaries. I don't know why. Adding another div and applying the settings there fixed the issue, but I wanted the settings to apply to the container div.
I was expecting a centered green div with the placeholder text in it aligned like the rest of the elements, and a grey background using the body tag. How can I solve this problem?
body {
width: 100%;
color: #A4A7A5;
}
div #container {
color: #63EC91;
width: 80%;
margin: 0 auto;
padding: 10px;
}
ul {
list-style: none;
background-color: black;
margin: 20px;
text-align: center;
list-style-type: none;
padding: 20px;
}
li {
text-align: center;
font-size: 1.5em;
font-family: Roboto;
display: inline;
color: white;
padding: 20px;
}
li a {
text-decoration: none;
color: lightgrey;
padding: 20px;
}
li a:hover {
background-color: lightgreen;
}
#container .FCR {
width: 20%;
text-align: center;
color: lightgrey;
font-size: 1.5em;
font-family: Roboto, Arial;
}
p {
text-align: center;
color: lightgrey;
font-size: 0.8em;
font-family: Roboto, Arial;
}
h1 {
margin: 20px;
padding: 0;
text-align: center;
color: lightgrey;
font-size: 1.5em;
font-family: Roboto, Arial;
}
<div id="container">
<ul>
<li>Pocetna</li>
<li>O nama</li>
<li>Kontakti</li>
<li>Galerija</li>
</ul>
<h1>Meni stranica</h1>
<hr>
<br>
<p class="FCR"> FCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCR</p>
</div>

I think ur problem is about
FCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCRCR
text that u put inside of p tag.
default browser split the word and put their into new line when there is any space (" ") between words BTW I guess u can use word-wrap: break-word to change this behavior.
Also u can use overflow property to prevent this but it's not a good solution.

Related

How do I make a h1 and h3 only as wide as the text [duplicate]

This question already has answers here:
How can I make a div not larger than its contents?
(43 answers)
Closed 2 years ago.
.main-heading {
display: block;
font-family: "Josefin-Sans", sans-serif;
font-size: 70.6px;
font-weight: bold;
text-align: center;
color: #ba9a45;
}
.subheading {
font-family: "Cardo", sans-serif;
font-size: 23.5px;
text-align: center;
color: #fff;
padding-top: 30px;
}
<!-- Headings -->
<div>
<h1 class="main-heading">ATLANTIC</h1>
<h1 class="main-heading">CASINO</h1>
<h3 class="subheading">FEED YOUR DESIRES</h3>
</div>
I seem to not be able to make my h1 and h3 background only as wide as the text and not span the whole width of the line.
How can I reduce the background of the h1 and h3 so it only spans to the end of the text?
--
I've managed to resolve my issue by taking into consideration all the advice given by users below.
Have a look at my revised code which works:
<div class="title-headings">
<h1 class="main-heading">ATLANTIC</h1>
<h1 class="main-heading">CASINO</h1>
<h3 class="subheading">FEED YOUR DESIRES</h3>
</div>
.main-heading{
display: block;
margin-left: auto;
margin-right: auto;
width: max-content;
font-family: "Josefin-Sans", sans-serif;
font-size: 70.6px;
font-weight: bold;
color: #ba9a45;
}
.subheading{
display: block;
margin-left: auto;
margin-right: auto;
width: max-content;
font-family: "Cardo", sans-serif;
font-size: 23.5px;
color: #fff;
padding-top: 30px;
}
Headings (<h1>, <h2>, ...) are block-level elements (display: block); if you want these to only take up as much space as the text is, you should set these to display: inline.
You can easily do it by:
.element{
display: inline-block
}
It will now take up only the width it is supposed to take!
Whilst the comments and other answers are correct in that - display : inline-block is the correct answer if the text was to be on one line, they do not address the fundamental semantic flaw in the code - you should have only one h1 element and for that to be followed by a h2.
It is important to maintain the correct hierarchy or headings in your page structure.
The way that I would do this is to have the h1 to be display: inline-block and within that to have spans for each word - and to have these spanss a display: block so that they are on separate lines.
Note that I added a red border to demonstrate the layout. And also added a text-align: center to the wrapping div to allow al lthe text to be centered.
div {
text-align: center;
}
.main-heading {
display: inline-block;
font-family: "Josefin-Sans", sans-serif;
font-size: 70.6px;
font-weight: bold;
color: #ba9a45;
border: solid 1px red
}
.main-heading span {
display: block;
}
.subheading {
font-family: "Cardo", sans-serif;
font-size: 23.5px;
text-align: center;
}
<!-- Headings -->
<div>
<h1 class="main-heading">
<span>ATLANTIC</span>
<span>CASINO</span>
</h1>
<h2 class="subheading">FEED YOUR DESIRES</h2>
</div>
To make a block HTML element not span the full width of its container, change its style.display property to inline-block.
You can do it with CSS like this:
display: inline-block
If you wanted to do it in the element itself, the equivalent would be:
style="display: inline-block;"
On .main-heading change display:block; to display:inline-block;
.main-heading {
display: inline-block;
font-family: "Josefin-Sans", sans-serif;
font-size: 70.6px;
font-weight: bold;
text-align: center;
color: #ba9a45;
}
.subheading {
font-family: "Cardo", sans-serif;
font-size: 23.5px;
text-align: center;
color: #fff;
padding-top: 30px;
}
<div>
<h1 class="main-heading">ATLANTIC</h1>
<h1 class="main-heading">CASINO</h1>
<h3 class="subheading">FEED YOUR DESIRES</h3>
</div>

A button is inside the navigation bar, but the btn doesnt belong in the div class of the nav bar

So I made a post similar to this one, since I didn't get a precise answer and didn't understand the instructions. So I am once again asking for your support.
There are a couple of issues regarding my nav bar that I am unable to fix. One of them is a button sticking inside of the nav bar, but it doesn't even belong in the div class.
Navigation Bar
The second issue is that I can't line the logo/text [SINUS] and the links together in one line.
Any help would be appreciated!
/*====================
The CSS File
Section 1:
Buttons
=====================*/
button {
background-color: #358cf0;
border: none;
border-radius: 18px;
text-align: center;
text-decoration: none;
opacity: 0.8;
font-size: 14px;
color: rgb(255, 255, 255);
padding: 12px 48px;
transition: 0.3s;
outline: none;
}
button:hover {
opacity: 1;
}
ul li {
display: inline-block;
padding: 10px;
font-size: 20px;
font-family: raleway;
}
ul li:hover {
color: orange;
}
/*====================
The CSS File
Section 2:
Alerts
=====================*/
.container {
position: fixed;
top: 74%;
right: 0;
left: 77%;
bottom: 0;
display: flex;
align-items: center;
justify-content: center;
font-family: basic;
}
.modal {
width: 40%;
min-width: 20rem;
background-color: #ffffff;
border-radius: 12px;
}
.modal-header {
display: flex;
align-items: center;
border-top-left-radius: 12px;
border-top-right-radius: 12px;
background-color: #358cf0;
padding: 8px 10px;
color: #fff;
font-size: 110%;
font-weight: 600;
font-family: basic;
}
.modal-content {
padding: 1rem;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}
.modal-footer {
text-align: center;
}
/*====================
The CSS File
Section 3:
Body etc.
=====================*/
body {
background-color: #252036;
}
#navigation-container {
width: 1200px;
margin: 0 auto;
height: 70%;
}
.navigation-bar {
background-color: #1c172c;
position: fixed;
width: 100%;
left: 0;
top: 0;
text-align: right;
}
.navigation-bar ul {
padding: 0px;
margin: 0px;
text-align: right;
display: inline-block;
vertical-align: top;
}
.navigation-bar li {
list-style-type: none;
padding: 0px;
display: inline;
text-align: right;
}
.navigation-bar li a {
color: black;
font-size: 16px;
font-family: basic;
text-decoration: none;
line-height: 70px;
padding: 5px 15px;
opacity: 0.7;
}
#menu {
float: right;
}
/*====================
The CSS File
Section 4:
Text
=====================*/
#font-face {
font-family: basic;
src: url(Helmet-Regular.ttf);
}
h1 {
font-family: basic;
color: white;
font-size: 390%;
text-align: left;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="sccp.css">
<title>Sinus - 【Home】</title>
<link rel="icon" href="titl.ico">
<link rel="apple-touch-icon" href="titl.ico" />
</head>
<body>
<div class="navigation-bar">
<div id="navigation-container">
<h1>SINUS</h1>
<ul>
<li>Home</li>
</ul>
</div>
</div>
<button>Download</button>
<div class="container" role="alert">
<div class="modal">
<div class="modal-header">
UPDATE! Sinus 1.0v
</div>
<div class="modal-content">
Here new stuff go gogogo
<br>Read more...
</div>
<div class="modal-footer">
</div>
</div>
</div>
</body>
</html>
To align the logo and links, use flex on the #navigation-container:
#navigation-container {
display: flex;
justify-content: space-between;
align-items: center;
}
justify-content: space-between will put the maximum space between the contents - in this case your logo and ul that contain the links. align-items:center lines them up vertically.
https://codepen.io/doughballs/pen/RwPrYoX
Not sure what your issue with the button is but because your nav has position:fixed, it is being taken out of the flow of the page, so the button doesn't 'know' it is there. If you wanted it to sit under the nav, you need to add a container with margin-top to push it down. But I'm not sure what your issue is with it, clarify and I'll amend the codepen.

CSS - aligning H1 with a span symbol

I'm styling the section headings for a website and I can't quite get a span symbol and a H1 heading to align properly. This is how it looks on the site -
Annoyingly, when I've come to include the code in this snippet the two elements seem to align. When I check the console the span element seems to have a buffer around the symbol which prompts it slightly out of line as you can see in the image. I'm using bootstrap for the site, could this be a hidden rule that I'm missing?
.secthead span {
font-weight: bolder;
font-size: 80px;
font-family: 'Gotham-Medium', sans-serif;
}
.secthead h1 {
font-size: 50px;
font-family: 'Gotham-Medium', sans-serif;
color: #000;
text-align: left;
padding: 0 0 20px 20px;
}
.secthead h1, span {
display: inline-block;
}
<div class="secthead"><span style="color: rgb(255,128,55);">+</span><h1>Who We Are</h1></div>
Just use vertical-align: middle; in both tag & remove padding from bottom in h1 tag. check updated snippet below..
.secthead span {
font-weight: bolder;
font-size: 80px;
font-family: 'Gotham-Medium', sans-serif;
}
.secthead h1 {
font-size: 50px;
font-family: 'Gotham-Medium', sans-serif;
color: #000;
text-align: left;
padding: 0 0 0px 20px;
}
.secthead h1, span {
display: inline-block;
vertical-align: middle;
}
<div class="secthead"><span style="color: rgb(255,128,55);">+</span><h1>Who We Are</h1></div>
You could use a height and line-height.
.secthead span {
font-weight: bolder;
font-size: 80px;
font-family: 'Gotham-Medium', sans-serif;
}
.secthead h1 {
margin: 0;
font-size: 50px;
font-family: 'Gotham-Medium', sans-serif;
color: #000;
text-align: left;
padding: 0 0 20px 20px;
line-height: 92px;
}
.secthead h1, .secthead span {
height: 92px;
display: inline-block;
vertical-align:top;
height: 92px;
}
<div class="secthead">
<span style="color: rgb(255,128,55);">+</span>
<h1>Who We Are</h1>
</div>

CSS - Make sans-serif font imitate monospace font

I have a logo/home button for my webpage which is the abbreviation of my project (the temp letters I use are ABCDEF). I am using Arial for the font (although may change it later). As you can see from the photo of the logo, the letters do not completely align under each other.
I've tried font-kerning: none; which helps but does not completely make it do what I want it to do.
I've made a jsfiddle for this example and here's the link: https://jsfiddle.net/7dfetxto/
Otherwise, here's my code (same as in the jsfiddle):
HTML
<div id="logo">
<a href="#">
<h1>ABC</br>DEF</h1>
</a>
</div>
CSS
#logo{
font-family: "arial", "times", "sans-serif";
width: 128px;
height: 100%;
background-color: #336699;
float: left;
}
#logo a{
width: 100%;
height: 100%;
display: block;
text-decoration: none;
}
#logo h1{
margin: 0px;
padding: 26px 30px;
text-align: center;
text-transform: uppercase;
font-kerning: none;
display: block;
color: white;
}
My goal is to get the letters on the second line to fall directly under their respective letter on the first line.
Thank you.
letter-spacing
Use CSS letter-spacing property.
JSfiddle.
#logo {
font-family: "arial", "times", "sans-serif";
width: 128px;
height: 100%;
background-color: #336699;
float: left;
}
#logo a {
width: 100%;
height: 100%;
display: block;
text-decoration: none;
}
#logo h1 {
margin: 0px;
padding: 26px 30px;
text-align: center;
text-transform: uppercase;
font-kerning: none;
display: block;
color: white;
}
.h1b {
letter-spacing: 3.25px;
}
<div id="logo">
<a href="#">
<h1>ABC<br><span class="h1b">DEF</span></h1>
</a>
</div>
You might find this interesting: kerningjs
There are more possible ways. One is
font-size
By making the font-size of the second line (in this case) bigger, it will grow and reach the two sides of the first line: JSFiddle.

Background Color Size fit with Text?

See my codepen. I look to make the blue background color scale to fit with the text, "My Pet". I tried display: inline and padding, but I couldn't figure out how to set the background to fit with the text responsively, rather than being full width. Also, how can I set the opacity of the background color but not the text?
After googling, I still struggle to find a solution.
HTML:
<div class="myDiv">
<div class="bgImage">
<h1>My Pet</h1>
</div>
</div>
CSS:
.myDiv h1 {
font-family: 'Gabriela', serif;
color: #FFF;
margin: auto;
text-align: center;
font-size: 3.5em;
border-radius: 20px;
background-color: #2ba6cb;
/* padding: 0.5em 0.2em 0.8em 0.5em;*/
}
Is this what you're trying to achieve?
.myDiv {
text-align: center;
}
.myDiv h1 {
display: inline-block;
font-family: 'Gabriela', serif;
color: #FFF;
font-size: 3.5em;
border-radius: 20px;
background: rgba(43, 166, 203, 0.5 /* alpha value for background */);
padding: 0.5em 0.2em 0.8em 0.5em;
}
<div class="myDiv">
<h1>My Pet</h1>
</div>
even shorter
width: max-content;
.myDiv h1 {
font-family: 'Gabriela', serif;
color: #FFF;
margin: auto;
text-align: center;
font-size: 3.5em;
border-radius: 20px;
background-color: #2ba6cb;
width:max-content;
padding:2px 20px;
}
<div class="myDiv">
<div class="bgImage">
<h1>My Pet</h1>
</div>
</div>
Is that what you were trying to get? This way you can set opacity of bgImage
.myDiv h1 {
font-family: 'Gabriela', serif;
color: #FFF;
margin: auto;
text-align: center;
font-size: 3.5em;
}
.myDiv {
text-align:center;
}
.myDiv .bgImage{
display:inline-block;
background-color: #2ba6cb;
border-radius: 20px;
padding: 0.5em 0.2em 0.8em 0.5em;
}
<div class="myDiv">
<div class="bgImage">
<h1>My Pet</h1>
</div>
</div>
You can just display your h1 as a table-cell and add the required padding around the text.
Note the last two rules to selector below....
.myDiv h1 {
font-family: 'Gabriela', serif;
color: #FFF;
margin: auto;
text-align: center;
font-size: 3.5em;
border-radius: 20px;
background-color: #2ba6cb;
display: table-cell;
padding: 0 0.5em ;
}