How to change width and height of <h1> text dynamically? - html

I am trying to change <h1> and <p> text's width and height dynamically. I want to get parents height and width, then use percentage for changing child's. But all my attempts are failed.
Here is my css example code:
#main-holder #category1 {
height: 80px;
width: 15%;
float: left;
padding-top: 0px;
padding-right: 0px;
padding-bottom: 0px;
padding-left: 0px;
border: thin solid #999;
margin-top: 5%;
margin-right: 2%;
margin-bottom: 0px;
margin-left: 6%;
text-align: center;
vertical-align: top;
}
#main-holder #category1 h1 {
font-weight: bold;
color: #FFF;
text-align: center;
vertical-align: middle;
line-height: 20%;
text-decoration: none;
}
#main-holder #category1 h1 a {
color: #FFF;
text-decoration: none;
}
#main-holder #category1 h1 a:hover {
color: #999;
text-decoration: none;
}
#main-holder #category1 p {
color: #CCC;
}
in html I am using like this:
<div id="category1">
<h1>MOVIES</h1>
<p>FOR ALL AGES</p>
</div>
I added width and height like below, but it didn't help:
#main-holder #category1 h1 {
height: 50%;
width: 50%;
}

In your code, you dont have #mainholder, but used all the css with that.so none of the styles applied. So I removed that from css and used line-height as 100% along with height. As the parent div have height as 80px, hope this is working fine and this is what you expected.
Updated Demo
Added font-size:2.9vw; for h1
#category1 {
height: 80px;
width: 15%;
float: left;
padding-top: 0px;
padding-right: 0px;
padding-bottom: 0px;
padding-left: 0px;
border: thin solid #999;
margin-top: 5%;
margin-right: 2%;
margin-bottom: 0px;
margin-left: 6%;
text-align: center;
vertical-align: top;
background-color:#666;
}
#category1 h1 {
font-weight: bold;
color: #FFF;
text-align: center;
vertical-align: middle;
line-height: 100%;
height: 100%;
text-decoration: none;
font-size:2.9vw;
}
#category1 h1 a {
color: #FFF;
text-decoration: none;
}
#category1 h1 a:hover {
color: #999;
text-decoration: none;
}
#category1 p {
color: #CCC;
}
You can use viewport value instead of ems, pxs or pts.
1vw = 1% of viewport width
1vh = 1% of viewport height
Update: Demo
For <p> Height alignment problem, Use background and border for <h1> along with height and line-height like this:
CSS:
#category1 {
height: 80px;
width: 15%;
float: left;
padding-top: 0px;
padding-right: 0px;
padding-bottom: 0px;
padding-left: 0px;
margin-top: 5%;
margin-right: 2%;
margin-bottom: 0px;
margin-left: 6%;
text-align: center;
vertical-align: top;
}
#category1 h1 {
font-weight: bold;
color: #FFF;
text-align: center;
vertical-align: middle;
line-height: 80px;
height: auto;
text-decoration: none;
font-size:2.9vw;
background-color:#666;
border: thin solid #999;
}

Why dont you use vw for font-size ?
font-size: 5vw;
Documentation

To change the text size you should use font-size:72px; or font-size:3em;.

One of the options it to use CSSStyleSheet JS object.
Check this tutorial: http://davidwalsh.name/add-rules-stylesheets
This answer provides another approach: modify a css rule object with javascript
You can get stylesheet object and manually modify properties:
var sheet = document.styleSheets[0];
var rules = sheet.cssRules || sheet.rules;
rules[0].style.height = '80px';

Related

Footer is not going doing with content (Vuejs)

Basically I created one component which has just a title and a color for background that should cover the whole page (but it's not, apparently there's a top margin and I don't know how to remove it) and also I created a componenent to be the footer. This component should stay at the botom of the page and it should go down with the addition of content, but it doesn't, the content overlaps it and even crosses it. How can I fix it?
Background CSS:
<style scoped>
*{
margin: 0%;
padding: 0%;
}
.background{
position: relative;
height: 88vh;
background-color: #3B3B3B;
}
.title{
border: 1px solid #707070;
border-left: none;
border-right: none;
}
.title h2{
text-align: left;
color: #B16DFF;
padding-top: 0.8em;
font-size: 2em;
padding-bottom: 0.5em;
margin-left: 1.5em;
font-weight: 600;
}
Footer CSS:
<style scoped>
.container{
width: 100%;
margin: 0%;
position: absolute;
bottom: 0%;
background-color: #232323;
}
.container h2{
font-weight: bold;
color: #B16DFF;
font-size: 1.5rem;
padding-top: 1.1em;
}
.container #text{
position: relative;
float: left;
padding-left: 5em;
text-align: justify;
padding-bottom: 2em;
}
.container p{
font-weight: 600;
font-size: 0.8rem;
color: white;
}
.container #title{
padding-bottom: 0.4em;
}
.container #description{
padding-bottom: 1.3rem;
}
.container #images{
position: relative;
padding-top: 3em;
float: left;
padding-left: 5em;
}
.container ul li{
display: inline-block;
padding-left: 2em;
}
On your background css, you have a scoped style so it doesn't apply to everything.
Also when you use 0 as value for a css property, you don't need to specify units.

Elements overflowing on right side for some time?

Im working on a gadget site.So i have to display 10 items on page.
My problem is whenever my page loads,item 2 floats on the right side of item 1 for some time then it appears correctly on left side.It happens for the rest of the items.I want all items to left at once.
See demo so you will get idea what im saying.
Demo here.
Also attached my CSS.
What are some corrections i should make?
.article-number{
border: 1px solid;
float: left;
width: 35px;
height: 40px;
padding-left: 15px;
padding-top: 5px;
font-size: 24px;
font-weight: 700;
background: #000000;
color: #ffffff;
overflow: hidden;
}
.article-item-title{
border: 1px solid;
width: auto;
height: 40px;
overflow: hidden;
background: #000000;
color: #ffffff;
text-align: left;
padding-left: 25px;
padding-top: 5px;
font-size: 24px;
font-weight: 700;
}
.article_media{
float: left;
margin-top: 25px;
}
.article-container{
border: 1px dotted #ccc;
height: 170px;
width: 270px;
float: right;
margin-top: 25px;
margin-bottom: 30px;
margin-left: 10px;
}
.specification{
margin-top: 7px;
margin-left: 30px;
border-radius: 40px;
border: none;
width: 220px;
text-align: center;
background: #ff3800;
color: #ffffff;
height: 35px;
padding-top: 7px;
font-weight: 700;
font-family: 'Ubuntu', sans-serif;
font-size: 17px;
}
.specification a{
color: #ffffff;
}
#article-flipkart-icon{
margin-left: 40px;
margin-top: 10px;
float: left;
}
.affiliate-link{
width: 145px;
float: left;
margin-top: 10px;
height: 35px;
padding-left: 15px;
padding-top: 5px;
border-top-right-radius: 40px;
border-bottom-right-radius: 40px;
background: #289dcc;
font-weight: 700;
}
.affiliate-link a{
color: #ffffff;
}
#article-amazon-icon{
float: left;
margin-left: 40px;
margin-top: 10px;
}
.article-wrapper{
margin-top: 50px;
}
.article-item-one,.article-item-two,.article-item-three,.article-item-four,.article-item-five,.article-item-six,.article-item-seven,.article-item-eight,.article-item-nine,.article-item-ten{
float: left;
margin-bottom: 35px;
}
.featured-image{
border: 1px dotted;
pointer-events: none;
}
This is happening because all images are rendering after some time. There can be multiple solutions to this problem.
1. You can set image width in pixels (300px in your case). - By this, right content will be at proper position until images appears.
2. You can use a very low-quality image for all item list as a placeholder and later replace image src with proper image URL. - By this, placeholder image will render quickly and it will occupy the required space until proper image appears.

How To Line Things Up

I am trying to get two things to line up for HTML. Instead, I get them on top of each other. What I really want is to have them next to each other like websites do (where at the top you can choose between like 6 things and they take you to different parts of the website).
#home {
background: #5F9EA0;
border-radius: 25px;
margin: auto;
width: 100px;
line-height: 50px;
text-align: center;
font-size: 20px;
}
#home:hover {
background: #6495ED;
border-radius: 50px;
margin: auto;
width: 105px;
line-height: 55px;
text-align: center;
font-size: 22.5px;
cursor: pointer;
}
#Alt {
background: #5F9EA0;
border-radius: 25px;
margin: auto;
width: 100px;
line-height: 50px;
text-align: center;
font-size: 20px;
}
#Alt:hover {
background: #6495ED;
border-radius: 50px;
margin: auto;
width: 105px;
line-height: 55px;
text-align: center;
font-size: 22.5px;
cursor: pointer;
}
<div id="home">Home</div><div id="Alt">test</div>
As another stated, you can use display: inline-block to get horizontal alignment of block elements.
I also added vertical-align: center to maintain a centered position when hovered, since the size changes. You can change center to top or another value if needed.
I also removed redundant CSS rules, shrinking your CSS down to around half its original size.
#home, #Alt {
background: #5F9EA0;
border-radius: 25px;
margin: auto;
width: 100px;
line-height: 50px;
text-align: center;
font-size: 20px;
display: inline-block;
vertical-align: center;
}
#home:hover, #Alt:hover {
background: #6495ED;
border-radius: 50px;
width: 105px;
line-height: 55px;
font-size: 22.5px;
cursor: pointer;
}
<div id="home">Home</div><div id="Alt">test</div>
<div>s naturally stack over one-another as they carry a block display by default.
In order to line them up, you may consider setting an inline-block display for both the #home and #Alt:
#home, #Alt {
display: inline-block;
vertical-align: middle;
}
You may also add a vertical-align: middle for a better appearance on hover (as suggested by another answer).
#home {
background: #5F9EA0;
border-radius: 25px;
margin: auto;
width: 100px;
line-height: 50px;
text-align: center;
font-size: 20px;
}
#home:hover {
background: #6495ED;
border-radius: 50px;
margin: auto;
width: 105px;
line-height: 55px;
text-align: center;
font-size: 22.5px;
cursor: pointer;
}
#Alt {
background: #5F9EA0;
border-radius: 25px;
margin: auto;
width: 100px;
line-height: 50px;
text-align: center;
font-size: 20px;
}
#Alt:hover {
background: #6495ED;
border-radius: 50px;
margin: auto;
width: 105px;
line-height: 55px;
text-align: center;
font-size: 22.5px;
cursor: pointer;
}
#home, #Alt {
display: inline-block;
vertical-align: middle;
}
<div id="home">Home</div>
<div id="Alt">test</div>

Align buttons in html/css

I'm trying to get my buttons aligned in my display. If I try to use float: right; nothing happends. Below you can find a screenshot:
So I'm trying to get these buttons all in a row below each other.
I also tried using a table, but that one screws up my design of my hrefs
Here you can find my html:
<div class="LineField">
<p>Axo 800</p>
Planning
Data analyse
</div>
<div class="LineField">
<p>JC-FSX</p>
Planning
Data analyse
</div>
etc. etc.
css:
.LineField
{
width: 50%;
height: 8%;
margin-bottom: 15px;
padding-top: 5px;
margin-left: auto;
margin-right: auto;
background: #191748;
border: 0.1em #191748;
border-radius: 1em;
color: white;
/* vertical alignment */
display: flex;
align-items:center;
}
.LineField p
{
margin-left: 25px;
margin-right: 25px;
Font-size: 200%;
}
.LineButton
{
border-radius: 0.5em;
width: 30%;
height: 50%;
background: linear-gradient(#ffffff, #c4c4ff);
margin-left: 3%;
margin-right: 3%;
padding-top: 5px;
color: #191748;
font-size: 150%;
font-weight: 500;
text-decoration: none;
}
You can set the width for the p element like below
.LineField p
{
margin-left: 25px;
margin-right: 25px;
Font-size: 200%;
width: 130px;
}
Updated Code Here
Just use the CSS below:
.LineField p {
margin-left: 25px;
margin-right: 25px;
Font-size: 200%;
float: left;
width: 16%;
}
You can set the width of LineButton class like below
.LineButton
{
border-radius: 0.5em;
width:50%;
height: 50%;
background: linear-gradient(#ffffff, #c4c4ff);
margin-left: 1%;
margin-right: 1%;
padding-top: 5px;
padding-left: 5%;
color: #191748;
font-size: 150%;
font-weight: 500;
text-decoration: none;
}
Please see the updated code below
Sample Code

How to centering span

How to centering that download button? I tested many times but it's wrong codes.
.col {
width: 100%;
height: auto;
float: left;
}
.download {
width: auto;
font-weight: 600;
font-size: 14px;
color: #000;
border: 2px solid #000;
padding: 17px 37px;
margin-top: 30px;
float: left;
}
<div class="col">
<span class="download">Download</span>
</div>
Just add text-align: center; to .col and replace float:left with display:inline-block; in the button element. jsfiddle
Remove float:left; from .download (because it forces the element to be floated to the left).
Give display:inline-block; (It acts like inline element, it means you can center it by giving text-align:center; to its parent.)
JSFiddle
.col {
width: 100%;
height: auto;
float: left;
text-align: center;
}
.download {
font-weight: 600;
font-size: 14px;
color: #000;
border: 2px solid #000;
padding: 17px 37px;
margin-top: 30px;
display: inline-block;
}