1

How do i exactly use the parent's element width in css? I know this is a basic question but i'm using width: 50% on css expecting that the width would be 50% of the parent but instead it uses less than 50%.

In this example, i colored the parent as green so i could see the width and i was expecting each tab to be distributed along the green block.

Link to the example: https://jsfiddle.net/zfw81ojq/6/

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>BPO Services</title>
    <link rel="stylesheet" href="css/style.css">
</head>
<body>

    <div class="content" id="main-content" onclick="appendEl()">
        <div class="tab-selector">
            <div class="tablinks" onclick="openForm()"><h2>1st Tab</h2></div>
            <div class="tablinks" onclick="openForm()"><h2>2nd Tab</h2></div>
        </div>
    </div>

</body>
</html>
.content {
    position: absolute;
    width: 60%;
    padding: 120px auto 120px;
    top: 30%;
    margin-left: 20%;
}

.content .tab-selector {
    height: 25px;
    background-color: green;
}

.content .tab-selector .tablinks {
    display: inline;
    padding: 20px;
    width: 50%;
    text-align: center;
}

.content .tab-selector .tablinks h2 {
    font-size: 20px;
    display: inline;
}
Ricardo Vilaça
  • 846
  • 1
  • 7
  • 18

0 Answers0